A Circuit for In-Context Learning
Not on the map. Why?
Abstract (arXiv)
In-context learning (ICL) lets a pretrained language model perform a task specified by demonstrations in its prompt, with no parameter updates. With arbitrary labels the model must acquire a mapping it cannot have memorized, so the learning happens within a single forward pass. Prior work found candidate parts but not how they compose. We give the composition for few-shot sentence classification with arbitrary labels in three 3-4B-parameter transformers. The model implements a key-value memory over label-token positions: each label token's residual stream encodes the label's identity, and middle-layer attention heads write into it the class of the preceding demonstration as its key. At the query, upper-layer heads match the query's class against the stored keys and copy out the matching labels. An early-layer signal encoding whether any label has repeated gates this readout; in its absence the readers attend to the start of the prompt and no label is favored. A separate set of heads suppresses the most recently seen label. Each step is established causally by activation patching, head ablations against random-head baselines, and steering with the model's own signals. A softmax model of the readout with two constants per head, fit on one prompt distribution, predicts another. The computation is conserved across the three models, the named heads alone reproduce the behaviour, and a transformer trained from scratch grows the same parts. The circuit transfers to semantic concepts and to labels with meaning, and the same parts, with a causal gate, appear from 0.6B to 8B in one family and survive instruction tuning. ICL in this setting is a gated associative lookup built from a few identifiable component types, traced causally from demonstrations to prediction.
Key facts. No citing papers in the map yet (data through 26 Nov 2026). Builds on 23 of its 25 references that are in the map. Submitted 3 Nov 2026.
Builds on
23 of 25 references.
References · 23
- 2020Language Models are Few-Shot Learnerscited by 33,113
- 2022Locating and Editing Factual Associations in GPTcited by 2,951
- 2023Efficient Streaming Language Models with Attention Sinkscited by 2,444
- 2022Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 smallcited by 1,270
- 2022In-context Learning and Induction Headscited by 1,085
- 2023Progress measures for grokking via mechanistic interpretabilitycited by 919
- 2022Transformers learn in-context by gradient descentcited by 763
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 754
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 729
- 2023Larger language models do in-context learning differentlycited by 436
- 2023Function Vectors in Large Language Modelscited by 353
- 2023In-Context Learning Creates Task Vectorscited by 337
11 more
- 2023How does GPT-2 compute greater-than?: Interpreting mathematical abilities in a pre-trained language modelcited by 217
- 2020Causal Mediation Analysis for Interpreting Neural NLP: The Case of Gender Biascited by 205
- 2023Copy Suppression: Comprehensively Understanding an Attention Headcited by 88
- 2024Revisiting In-context Learning Inference Circuit in Large Language Modelscited by 21
- 2024How do Large Language Models Learn In-Context? Query and Key Matrices of In-Context Heads are Two Towers for Metric Learningcited by 19
- 2025Understanding In-context Learning of Addition via Activation Subspacescited by 11
- 2024Label Words as Local Task Vectors in In-Context Learningcited by 5
- 2025Task Schema and Binding: A Double Dissociation Study of In-Context Learningcited by 4
- 2026Understanding the Dynamics of Demonstration Conflict in In-Context Learningcited by 4
- 2024Skill Path: Unveiling Language Skills from Circuit Graphscited by 2
- 2026Necessary, Decodable and Reversible, Yet Not Transferable: A Stress Test for Attention-Head Role Claimscited by 2
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2024Does In-Context Learning Really Learn? Rethinking How Large Language Models Respond and Solve Tasks via In-Context Learning
- 2025On the Relationship Between the Choice of Representation and In-Context Learning
- 2023Is attention required for ICL? Exploring the Relationship Between Model Architecture and In-Context Learning Ability
- 2025From Compression to Expression: A Layerwise Analysis of In-Context Learning
- 2022Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?
- 2025Mechanistic Fine-tuning for In-context Learning
- 2024In-Context Language Learning: Architectures and Algorithms
- 2023Hint-enhanced In-Context Learning wakes Large Language Models up for knowledge-intensive tasks