Abstract
We argue that in-context learning (ICL) predictably arises from standard self-supervised next-token pretraining, rather than being an exotic emergent property. This work establishes the foundational principles of this emergence by focusing on in-distribution ICL, demonstrating how models necessarily adapt to context when trained on token sequences, especially from non-ergodic sources. Our information-theoretic framework precisely predicts these in-distribution ICL dynamics (i.e., context-dependent loss reduction). We verify this with experiments using synthetic datasets of differing types of correlational structure, reproducing characteristic phenomena like phase transitions in training loss for induction head formation and power-law scaling of in-context loss. We further show that a model's in-context performance on any task is mathematically coupled to the ensemble of tasks seen in pretraining, offering a fundamental explanation, grounded in architecture- and modality-independent principles, for such inference-time learning.
Introduction
Since the introduction of GPT-2, In-Context Learning (ICL)—the ability of a model to adapt to a new task using only a few examples in a prompt—has been a central mystery of large language models. While some theories suggest ICL mimics Bayesian inference or internal gradient descent, a foundational, architecture-independent explanation has been missing.
This paper argues that ICL is not a "magical" emergent property but a mathematical inevitability of minimizing next-token prediction loss. By simply attempting to predict the next token, models are forced to "synchronize" with the hidden structure of their training data. This synchronization naturally leads to the adaptive behaviors we identify as ICL. The authors specifically focus on in-distribution ICL, where the tasks encountered at inference time reflect the diverse patterns seen during pretraining.
Theoretical Framework: ICL as Synchronization
The authors employ a framework rooted in computational mechanics to explain how models learn from context.
- Predictive States: These are defined as the minimal sufficient statistics of the past required to predict the future.
- Mixed-State Presentation (MSP): This tool tracks how a model’s internal "belief" about the data source evolves as it processes more context.
- Mathematical Coupling: The expected next-token loss (myopic cross-entropy) is lower-bounded by the "myopic entropy rate" of the data. As context length increases, this entropy generally decreases as the model "homes in" on the specific sub-process generating the current sequence.
In this view, ICL is a process of synchronization. At the start of a sequence, a model is uncertain which "task" or "topic" it is observing. As it processes more tokens, it narrows down the possibilities, reducing its uncertainty and, consequently, its prediction loss.
Experimental Verification
To verify this theory, the authors used synthetic datasets generated by Hidden Markov Models (HMMs), allowing for exact calculation of ground-truth entropy.
The experiments covered several types of processes, ranging from simple memoryless sources to complex hierarchical grammars:
- Ergodic processes: Such as biased coins and "Golden Mean" processes, where the statistical properties are constant over time.
- Non-ergodic processes: Such as a "bag of coins" with different biases, simulating a mixture of different "tasks" or "topics."
- Context-free grammars: Parentheses matching to test hierarchical structures.
Key Results and Insights
The study yielded several critical findings that bridge the gap between theory and the observed behavior of large models:
- Theoretical Matching: The empirical in-context loss of trained Transformers and RNNs (GRUs) almost perfectly matches the theoretical "myopic entropy" curves derived from the data's MSP. This confirms that the model's performance is limited by the statistical structure of the data itself.
- Architecture Independence: Both Transformers and RNNs converge to the same theoretical ICL performance. While Transformers use "induction heads" to look back at previous tokens, RNNs achieve similar results through hidden state updates. This proves that the objective (next-token prediction) drives the capability, not a specific architectural quirk.
- Power-Law Scaling: The authors mathematically derived that in a world with many "tasks" (ergodic components), the in-context loss should decay following a power law ($1/2 \ell^{-1}$). This provides a theoretical grounding for the scaling laws observed in massive LLMs.
- The Role of Non-Ergodicity: Real-world data is non-ergodic—a mixture of many styles and languages. ICL is essentially the model's mechanism for disambiguating which part of that massive mixture it is currently in.
Conclusion and Future Work
This work demonstrates that ICL is a predictable consequence of next-token pretraining on correlated, non-ergodic data. While it provides a robust explanation for in-distribution ICL, several questions remain. The paper does not fully account for Out-of-Distribution (OOD) ICL, where a model performs a task entirely unlike its training data. Future research will investigate "out-of-support" generalization and how different architectures might influence the model's ability to handle motifs never seen during training.
Summary updated