{"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/toward-understanding-in-context-vs-in-weight","title":"Toward Understanding In-context vs. In-weight Learning","arxiv_id":"2410.23042","date":"2024-10-30","proceeding":null,"authors":["Bryan Chan","Xinyi Chen","András György","Dale Schuurmans"],"abstract":"It has recently been demonstrated empirically that in-context learning emerges in transformers when certain distributional properties are present in the training data, but this ability can also diminish upon further training. We provide a new theoretical understanding of these phenomena by identifying simplified distributional properties that give rise to the emergence and eventual disappearance of in-context learning. We do so by first analyzing a simplified model that uses a gating mechanism to choose between an in-weight and an in-context predictor. Through a combination of a generalization error and regret analysis we identify conditions where in-context and in-weight learning emerge. These theoretical findings are then corroborated experimentally by comparing the behaviour of a full transformer on the simplified distributions to that of the stylized model, demonstrating aligned results. We then extend the study to a full large language model, showing how fine-tuning on various collections of natural language prompts can elicit similar in-context and in-weight learning behaviour.","url_abs":"https://arxiv.org/abs/2410.23042v2","url_pdf":"https://arxiv.org/pdf/2410.23042v2.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"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"large-language-model","task_name":"Large Language Model"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2410.23042","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2410.23042"}},"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/chanb/icl_vs_iwl","reach":{"status":"ok"}}],"summary":{"ran_honours":1,"unverified":11},"by_repo_kind":{"found_in_text":{"samples":12,"ran":1,"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":12,"samples":[{"code_sha256_prefix":"9910e2fc297f8665","entry":"identity","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/models.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/models.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9910e2fc297f8665"}},{"code_sha256_prefix":"3530bb7a687ad762","entry":"evaluate","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"experiments/utils.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/experiments/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3530bb7a687ad762"}},{"code_sha256_prefix":"2548c37cb3dcc6e6","entry":"get_param_mask_by_name","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/optimizer.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/optimizer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2548c37cb3dcc6e6"}},{"code_sha256_prefix":"e1259466c139acd0","entry":"get_preds_labels","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"experiments/utils.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/experiments/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e1259466c139acd0"}},{"code_sha256_prefix":"75fa073f0c5c3557","entry":"get_scheduler","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/optimizer.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/optimizer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"75fa073f0c5c3557"}},{"code_sha256_prefix":"e6ee54b3ae1accdc","entry":"l2_norm","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/learner.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/learner.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e6ee54b3ae1accdc"}},{"code_sha256_prefix":"b3094ed7367fd8a7","entry":"linear_warmup_sqrt_decay","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/optimizer.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/optimizer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b3094ed7367fd8a7"}},{"code_sha256_prefix":"c2941847c7ff001c","entry":"load_config","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/utils.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c2941847c7ff001c"}},{"code_sha256_prefix":"91a98277e57a16bc","entry":"make_h","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/models.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/models.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"91a98277e57a16bc"}},{"code_sha256_prefix":"4f481719630f7b96","entry":"parse_dict","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/utils.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4f481719630f7b96"}},{"code_sha256_prefix":"85b5f412d531bc19","entry":"prepare_seqs_for_icl","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"src/dataset.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/src/dataset.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"85b5f412d531bc19"}},{"code_sha256_prefix":"381775abc41222b4","entry":"print_performance_with_aux","repo":"chanb/icl_vs_iwl","repo_kind":"found_in_text","path":"experiments/utils.py","file_url":"https://github.com/chanb/icl_vs_iwl/blob/HEAD/experiments/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"381775abc41222b4"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}