Dual Operating Modes of In-Context Learning
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.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
33 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Looped Transformers are Better at Learning Learning Algorithms cites An Explanation of In-context Learning as Implicit Bayesian Inference
- Looped Transformers are Better at Learning Learning Algorithms cites Language Models are Few-Shot Learners
- Looped Transformers are Better at Learning Learning Algorithms cites Transformers Learn In-Context by Gradient Descent
- Looped Transformers are Better at Learning Learning Algorithms cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Transformers on Markov data: Constant depth suffices cites Language Models are Few-Shot Learners
- An Explanation of In-context Learning as Implicit Bayesian Inference cites Language Models are Few-Shot Learners
- Transformers Learn In-Context by Gradient Descent cites Language Models are Few-Shot Learners
- Transformers Learn In-Context by Gradient Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites An Explanation of In-context Learning as Implicit Bayesian Inference
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks cites Language Models are Few-Shot Learners
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks cites Transformers Learn In-Context by Gradient Descent
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- True Zero-Shot Inference of Dynamical Systems Preserving Long-Term Statistics cites An Explanation of In-context Learning as Implicit Bayesian Inference
- True Zero-Shot Inference of Dynamical Systems Preserving Long-Term Statistics cites Language Models are Few-Shot Learners
- True Zero-Shot Inference of Dynamical Systems Preserving Long-Term Statistics cites Transformers Learn In-Context by Gradient Descent
- True Zero-Shot Inference of Dynamical Systems Preserving Long-Term Statistics cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Many-Shot In-Context Learning cites An Explanation of In-context Learning as Implicit Bayesian Inference
- Many-Shot In-Context Learning cites Language Models are Few-Shot Learners
- Many-Shot In-Context Learning cites Transformers Learn In-Context by Gradient Descent
- Many-Shot In-Context Learning cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
Cited by top-tier papers33
- Many-Shot In-Context LearningRishabh Agarwal, Avi Singh, Lei Zhang, Bernd Bohnet et al.NeurIPS 2024 · 271 citations
- Looped Transformers are Better at Learning Learning AlgorithmsLiu Yang, Kangwook Lee, Robert D. Nowak, Dimitris PapailiopoulosICLR 2024 · 82 citations
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasksTianyu He, Darshil Doshi, Aritra Das, Andrey GromovNeurIPS 2024 · 52 citations
- Transformers on Markov data: Constant depth sufficesNived Rajaraman, Marco Bondaschi, Ashok Vardhan Makkuva, Kannan Ramchandran et al.NeurIPS 2024 · 33 citations
- True Zero-Shot Inference of Dynamical Systems Preserving Long-Term StatisticsChristoph Jürgen Hemmer, Daniel DurstewitzNeurIPS 2025 · 25 citations
Builds on17
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 citations
- What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
- Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
- TweetEval: Unified Benchmark and Comparative Evaluation for Tweet ClassificationFrancesco Barbieri, José Camacho-Collados, Luis Espinosa Anke, Leonardo NevesEMNLP Findings 2020 · 720 citations
Related papers
- When can in-context learning generalize out of task distribution?Page C. Goddard, Lindsay M. Smith, Vudtiwat Ngampruetikorn, David J. SchwabICML 2025
- Prior Forgetting and In-Context OverfittingSungyoon LeeNeurIPS 2025 · 1 citation
- Can In-context Learning Really Generalize to Out-of-distribution Tasks?Qixun Wang, Yifei Wang, Xianghua Ying, Yisen WangICLR 2025
- In-Context Learning through the Bayesian PrismMadhur Panwar, Kabir Ahuja, Navin GoyalICLR 2024 · 79 citations
- What Do Language Models Learn in Context? The Structured Task HypothesisJiaoda Li, Yifan Hou, Mrinmaya Sachan, Ryan CotterellACL 2024 · 5 citations
