Notes on In-Context Learning and Induction Heads
Transformer Circuits Thread Notes · 2 of 7
- 1. Notes on A Mathematical Framework for Transformer Circuits
- 2. Notes on In-Context Learning and Induction Heads
- 3. Notes on Toy Models of Superposition
- 4. Notes on Towards Monosemanticity and Scaling Monosemanticity
- 5. Notes on Sparse Crosscoders
- 6. Notes on Circuit Tracing and the Biology of a Large Language Model
- 7. Notes on Tracing Attention Computation Through Feature Interactions
Notes on In-Context Learning and Induction Heads (Olsson & others, 2022), the second paper in Anthropic’s Transformer Circuits thread.
The paper asks whether induction heads, first understood in two-layer attention-only transformers, also explain the more general in-context learning seen in larger language models. Its answer has two parts. In small models, the proposed mechanism can be inspected and ablated directly. In large models, the evidence is circumstantial: several measurements continue smoothly with scale, but the underlying circuit is not recovered in the same detail.
Prefix matching and copying
An induction head completes patterns of the form
On seeing the second [A], it attends to the [B] that followed the earlier [A] and raises the logit for [B]. This is a useful primitive for repeated text, but it does not depend on the text having any meaning. The paper tests heads on repeated random token sequences specifically to separate the mechanism from memorized language statistics.
The operational test has two parts. Prefix matching asks whether the head attends to a token that followed an earlier occurrence of the current prefix. Copying asks whether its OV circuit increases the logit of the attended token. A head that passes both tests counts as an induction head, even when its internal implementation has not been fully traced.
The examples in the next figure (Fig. 1) separate those two measurements. The red path is the attention move from the later occurrence back to the earlier continuation; the purple path is the resulting logit effect. The Pot/ters and D/urs/ley examples have different tokenization but the same pattern.
The two-head circuit
The awkward part of [A][B] … [A] → [B] is finding the earlier [B]. At the second [A], the induction head’s query contains information about [A]. But a key built only from [B] does not say that [B] came after an [A]. The model first has to move information between positions.
In the simplest circuit, two heads do this:
- A previous-token head in the first layer attends one position back. At position
[B], it writes a representation of the preceding[A]into the residual stream. - An induction head in the second layer reads that representation into its keys. Its query at the later
[A]matches the key at[B]because both encode[A]. It attends to[B], and its OV circuit raises the logit for[B].
The two panels below follow those steps in order. The first shows the previous-token head attaching prev = A to [B]; the second shows the later [A] matching that tag and using [B] as the token to copy.
Using the notation from the mathematical framework, this is K-composition. The induction head reads the earlier head’s output through its key input, giving the virtual QK circuit
If this matrix has a strong positive diagonal, a query associated with token [A] scores positions where the previous-token head wrote [A]. The induction head then uses its own OV circuit to copy the token at the selected position.
The framework paper also gives a Q-composition construction called pointer arithmetic, in which the later head attends one position beyond the location selected by an earlier head. The two constructions differ internally but produce the same visible pattern.
A one-layer model cannot form either two-head circuit. Its queries and keys are computed before any attention head has moved contextual information between positions. On a random sequence, an attention score can depend on the two token identities and their positions, but the key at [B] cannot encode the fact that the previous token was [A]. This architectural constraint becomes useful evidence when the authors examine training.
The phase change during training
The paper measures in-context learning as the difference between loss early and late in a 512-token sequence. A more negative score means that the model predicts better after seeing more of the current context.
For models with at least two layers, that score improves sharply during a narrow window early in training. Induction heads appear during the same window. Per-head ablations attribute most of the improvement to those heads. One-layer models show neither the abrupt improvement nor an induction-head circuit, while architectural changes that make induction easier or harder shift the phase change in the expected direction. The plot (Fig. 2) aligns these observations vertically: the shaded training window in the upper row contains the loss improvement, and the lower row shows the induction-head ablation curves separating during the same interval.
This does not by itself establish that induction heads implement every kind of in-context learning. It establishes a tighter claim in the models studied: the emergence of a particular circuit coincides with, and causally contributes to, a sudden improvement in learning from earlier tokens in the sequence.
The six-part case
The paper builds its broader claim from six arguments:
| # | Argument | Contribution |
|---|---|---|
| 1 | Macroscopic co-occurrence (opens in a new tab) | Induction heads appear during the same narrow training window in which in-context learning improves. |
| 2 | Macroscopic co-perturbation (opens in a new tab) | Architectural changes move the formation of induction heads and the improvement in in-context learning together. |
| 3 | Direct ablation (opens in a new tab) | Ablating induction heads in small models removes much of their in-context learning ability. |
| 4 | Examples of generality (opens in a new tab) | Some heads identified by the copying test also perform less literal, more abstract forms of pattern completion. |
| 5 | Mechanistic plausibility (opens in a new tab) | The small-model circuit is understood well enough to see how variants of it could support broader behaviors. |
| 6 | Continuity from small to large (opens in a new tab) | Observable properties of induction heads and in-context learning change smoothly across model sizes. |
The first five arguments are most direct in small attention-only models. The sixth is the bridge to larger models, and therefore the least mechanistically secure part of the case.
Small models and large models
It helps to separate an induction head’s operational definition from the specific circuit above. Prefix matching and copying can be measured from a head’s attention pattern and output. Verifying K-composition requires showing how that behavior is assembled from earlier heads and residual-stream subspaces.
The paper does both in small attention-only models. It identifies the two-head circuit, checks its weights, and measures the effect of ablating it. For larger models, it mainly identifies heads by their behavior and observes continuity in aggregate measurements. Calling one of these heads an “induction head” does not show that it uses the same two-head implementation, nor does it establish that the head is the main cause of general few-shot learning.
The phase-change result is narrower and stronger than the large-model extrapolation. In the models where the circuit can be inspected, induction heads form suddenly and cause much of the corresponding improvement in prediction from context. The proposal that this mechanism remains the principal source of in-context learning at scale was a hypothesis for later causal work.
How the hypothesis changed
Todd et al. (2024) (opens in a new tab) identified function vector heads, whose outputs carry information about the task demonstrated in the prompt. Their causal interventions transfer that task information between prompts, which is different from copying the token that followed a matching prefix.
Yin and Steinhardt (2025) (opens in a new tab) compared the two mechanisms with head ablations. They found that few-shot performance depends primarily on function vector heads, especially in larger models. Many of those heads begin training with induction-like behavior and later shift toward carrying task-level information.
There are also broader versions of induction. Feucht et al. (2025) (opens in a new tab) distinguish token-level copying from concept-level induction, where a model retrieves a semantically related answer rather than repeating a literal token. Taken together, this work leaves induction heads as a clear mechanism for early and literal pattern completion, but not a complete account of sophisticated in-context learning.
Further material
- ARENA’s induction heads exercises (opens in a new tab) — locate and verify induction heads in a real 2-layer model with TransformerLens.
- Function vectors project page (opens in a new tab) — code and data for the function-vector line of work.
References
These are notes on the work marked ★ — cite the original rather than this page.
- Olsson, C., & others. (2022). In-Context Learning and Induction Heads. Transformer Circuits Thread. https://transformer-circuits.pub/2022/in-context-learning-and-induction-heads/index.html ★