{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/a-theoretical-understanding-of-self","title":"A Theoretical Understanding of Self-Correction through In-context Alignment","arxiv_id":"2405.18634","date":"2024-05-28","proceeding":null,"authors":["Yifei Wang","Yuyang Wu","Zeming Wei","Stefanie Jegelka","Yisen Wang"],"abstract":"Going beyond mimicking limited human experiences, recent studies show initial evidence that, like humans, large language models (LLMs) are capable of improving their abilities purely by self-correction, i.e., correcting previous responses through self-examination, in certain circumstances. Nevertheless, little is known about how such capabilities arise. In this work, based on a simplified setup akin to an alignment task, we theoretically analyze self-correction from an in-context learning perspective, showing that when LLMs give relatively accurate self-examinations as rewards, they are capable of refining responses in an in-context way. Notably, going beyond previous theories on over-simplified linear transformers, our theoretical construction underpins the roles of several key designs of realistic transformers for self-correction: softmax attention, multi-head attention, and the MLP block. We validate these findings extensively on synthetic datasets. Inspired by these findings, we also illustrate novel applications of self-correction, such as defending against LLM jailbreaks, where a simple self-correction step does make a large difference. We believe that these findings will inspire further research on understanding, exploiting, and enhancing self-correction for building better foundation models.","url_abs":"https://arxiv.org/abs/2405.18634v2","url_pdf":"https://arxiv.org/pdf/2405.18634v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"}],"methods":[{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2405.18634","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2405.18634"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/yifeiwang77/Self-Correction","reach":null}],"summary":{"ran":4},"by_repo_kind":{"found_in_text":{"samples":4,"ran":4,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":4,"samples":[{"code_sha256_prefix":"2999a429a2fe84dc","entry":"NoSoftmaxAttention","repo":"yifeiwang77/Self-Correction","repo_kind":"found_in_text","path":"synthetic_experiment/models.py","file_url":"https://github.com/yifeiwang77/Self-Correction/blob/HEAD/synthetic_experiment/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2999a429a2fe84dc"}},{"code_sha256_prefix":"32a9bceb8f44f3d7","entry":"NoSoftmaxGPT2Model","repo":"yifeiwang77/Self-Correction","repo_kind":"found_in_text","path":"synthetic_experiment/models.py","file_url":"https://github.com/yifeiwang77/Self-Correction/blob/HEAD/synthetic_experiment/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"32a9bceb8f44f3d7"}},{"code_sha256_prefix":"b3faaba0a0c6e611","entry":"NoSoftmaxTFBlock","repo":"yifeiwang77/Self-Correction","repo_kind":"found_in_text","path":"synthetic_experiment/models.py","file_url":"https://github.com/yifeiwang77/Self-Correction/blob/HEAD/synthetic_experiment/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b3faaba0a0c6e611"}},{"code_sha256_prefix":"6cdc3c683451db64","entry":"NoSoftmaxTransformerModel","repo":"yifeiwang77/Self-Correction","repo_kind":"found_in_text","path":"synthetic_experiment/models.py","file_url":"https://github.com/yifeiwang77/Self-Correction/blob/HEAD/synthetic_experiment/models.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6cdc3c683451db64"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}