[Paper Review] An Explanation of In-context Learning as Implicit Bayesian Inference
This paper explains in-context learning in large language models as implicit Bayesian inference, where models infer a shared latent concept across few-shot examples during prompting. It proves that in-context learning emerges when pretraining data has long-range coherence via a mixture of HMMs, and demonstrates this using a synthetic dataset (GINC), showing that both Transformers and LSTMs achieve in-context learning despite distribution shift, with performance improving with example length and number of examples.
Large language models (LMs) such as GPT-3 have the surprising ability to do in-context learning, where the model learns to do a downstream task simply by conditioning on a prompt consisting of input-output examples. The LM learns from these examples without being explicitly pretrained to learn. Thus, it is unclear what enables in-context learning. In this paper, we study how in-context learning can emerge when pretraining documents have long-range coherence. Here, the LM must infer a latent document-level concept to generate coherent next tokens during pretraining. At test time, in-context learning occurs when the LM also infers a shared latent concept between examples in a prompt. We prove when this occurs despite a distribution mismatch between prompts and pretraining data in a setting where the pretraining distribution is a mixture of HMMs. In contrast to messy large-scale datasets used to train LMs capable of in-context learning, we generate a small-scale synthetic dataset (GINC) where Transformers and LSTMs both exhibit in-context learning. Beyond the theory, experiments on GINC exhibit large-scale real-world phenomena including improved in-context performance with model scaling (despite the same pretraining loss), sensitivity to example order, and instances where zero-shot is better than few-shot in-context learning.
Motivation & Objective
- To explain the mechanism behind in-context learning in large language models, which occurs without explicit fine-tuning.
- To investigate how in-context learning can emerge from long-range coherence in pretraining data, even when prompts differ from pretraining distributions.
- To demonstrate that in-context learning is a form of implicit Bayesian inference by modeling the latent concept shared across examples.
- To validate theoretical claims using a controlled synthetic dataset (GINC) where both Transformers and LSTMs exhibit in-context learning.
Proposed method
- Model pretraining data as a mixture of Hidden Markov Models (HMMs), where each document is generated from a shared latent concept θ that governs token transitions.
- Formulate in-context learning as Bayesian posterior predictive inference: p(output|prompt) = ∫ p(output|concept, prompt) p(concept|prompt) d(concept), where the model infers the shared concept across examples.
- Prove that under distribution mismatch between pretraining and prompt data, in-context learning error is asymptotically optimal when signal per example exceeds error from distribution shift.
- Construct a synthetic dataset, GINC, with controlled HMM-based documents to isolate the role of latent concept structure in enabling in-context learning.
- Train both Transformers and LSTMs on GINC to empirically verify theoretical predictions about model scaling, example order, and example length effects.
- Conduct ablation studies on GINC to show that the latent concept structure is essential for in-context learning to emerge.
Experimental results
Research questions
- RQ1Can in-context learning emerge from long-range coherence in pretraining data without explicit example-based fine-tuning?
- RQ2Is in-context learning equivalent to implicit Bayesian inference over a shared latent concept across examples?
- RQ3How does distribution mismatch between pretraining data and prompts affect in-context learning performance?
- RQ4Does increasing example length or number of examples improve in-context learning, even when task-relevant input-output mapping remains unchanged?
- RQ5Can both Transformers and LSTMs exhibit in-context learning in a controlled synthetic setting where the latent concept is explicitly defined?
Key findings
- In-context learning accuracy improves with the number of examples and example length, even when task-relevant input-output mapping is unchanged, supporting the role of contextual information in concept inference.
- The 12-layer Transformer on GINC achieves 71.4% in-context learning accuracy with 10 short independent examples, outperforming 5 duplicated examples (69.6%) and 5 short examples (69.8%), indicating that more diverse examples improve performance.
- Using longer examples (500–600 characters) in GPT-3’s in-context learning on LAMBADA improves accuracy by nearly 1% compared to shorter examples (200–300 characters), despite distribution mismatch, validating the theory that longer context aids concept inference.
- The model’s in-context learning performance improves with vocabulary size (50, 100, 150), as larger vocabularies make HMM state inference easier, confirming that richer observables enhance concept detection.
- Ablation studies on GINC show that removing the latent concept structure eliminates in-context learning, proving that the concept structure is necessary for the phenomenon to emerge.
- Despite identical pretraining loss, larger models show improved in-context learning performance, demonstrating that scaling improves implicit Bayesian inference even without further pretraining.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.