{"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/dual-operating-modes-of-in-context-learning","title":"Dual Operating Modes of In-Context Learning","arxiv_id":"2402.18819","date":"2024-02-29","proceeding":null,"authors":["Ziqian Lin","Kangwook Lee"],"abstract":"In-context learning (ICL) exhibits dual operating modes: task learning, i.e., acquiring a new skill from in-context samples, and task retrieval, i.e., locating and activating a relevant pretrained skill. Recent theoretical work investigates various mathematical models to analyze ICL, but existing models explain only one operating mode at a time. We introduce a probabilistic model, with which one can explain the dual operating modes of ICL simultaneously. Focusing on in-context learning of linear functions, we extend existing models for pretraining data by introducing multiple task groups and task-dependent input distributions. We then analyze the behavior of the optimally pretrained model under the squared loss, i.e., the MMSE estimator of the label given in-context examples. Regarding pretraining task distribution as prior and in-context examples as the observation, we derive the closed-form expression of the task posterior distribution. With the closed-form expression, we obtain a quantitative understanding of the two operating modes of ICL. Furthermore, we shed light on an unexplained phenomenon observed in practice: under certain settings, the ICL risk initially increases and then decreases with more in-context examples. Our model offers a plausible explanation for this \"early ascent\" phenomenon: a limited number of in-context samples may lead to the retrieval of an incorrect skill, thereby increasing the risk, which will eventually diminish as task learning takes effect with more in-context samples. We also theoretically analyze ICL with biased labels, e.g., zero-shot ICL, where in-context examples are assigned random labels. Lastly, we validate our findings and predictions via experiments involving Transformers and large language models.","url_abs":"https://arxiv.org/abs/2402.18819v2","url_pdf":"https://arxiv.org/pdf/2402.18819v2.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":[{"paper_slug":"dual-operating-modes-of-in-context-learning","repo_url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"dual-operating-modes-of-in-context-learning","repo_url":"https://github.com/uw-madison-lee-lab/icl-hcg","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"},{"task_slug":"retrieval","task_name":"Retrieval"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2402.18819","atlas_url":"https://app.syntology.ai/?focus=2402.18819","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.18819"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/uw-madison-lee-lab/icl-hcg","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl","reach":{"status":"ok"}}],"summary":{"ran":4},"by_repo_kind":{"official":{"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":"e151f81560f7cdf1","entry":"decimal_to_numpy","repo":"uw-madison-lee-lab/dual_operating_modes_of_icl","repo_kind":"official","path":"TransformerExperiment/setting.py","file_url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl/blob/HEAD/TransformerExperiment/setting.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":"e151f81560f7cdf1"}},{"code_sha256_prefix":"c1ff72ef583fa84d","entry":"numpy_to_decimal","repo":"uw-madison-lee-lab/dual_operating_modes_of_icl","repo_kind":"official","path":"TransformerExperiment/setting.py","file_url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl/blob/HEAD/TransformerExperiment/setting.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":"c1ff72ef583fa84d"}},{"code_sha256_prefix":"38f20eea99d3afda","entry":"sorted_eigenvalues","repo":"uw-madison-lee-lab/dual_operating_modes_of_icl","repo_kind":"official","path":"TransformerExperiment/setting.py","file_url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl/blob/HEAD/TransformerExperiment/setting.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":"38f20eea99d3afda"}},{"code_sha256_prefix":"7a0b41d5cd881c72","entry":"train_model","repo":"uw-madison-lee-lab/dual_operating_modes_of_icl","repo_kind":"official","path":"TransformerExperiment/TS_D_d.py","file_url":"https://github.com/uw-madison-lee-lab/dual_operating_modes_of_icl/blob/HEAD/TransformerExperiment/TS_D_d.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":"7a0b41d5cd881c72"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}