Vol. XXVIII · Interpretability Plate 4 of 9induction heads, in-context learning, circuits, composition, phase change, copyingLE

Induction Heads.

Find where this token appeared before, and predict what came after it.

Olsson and colleagues (2022) identified a two-step circuit behind much of in-context copying. A previous-token head in one layer writes, at each position, which token came just before. An induction head in a later layer then looks, from the current token A, for earlier positions whose previous token was A, and copies the token found there — B. Because the second head’s query depends on what the first head wrote, the circuit needs two attention layers composing; a single layer can only attend by position or by content directly. Induction heads form abruptly in training, at the same time as a bump in the loss curve and a jump in in-context learning.

The workshop trains a small model (d = 32, two heads per layer) in the page on sequences of 24 tokens from a vocabulary of 16: a run of 3 to 7 distinct random tokens repeated until the sequence is full. The period varies, so no fixed positional rule predicts the repeats; copying them needs induction. It measures the loss on the first run (unpredictable) and on the repeats, with one layer or two.

Below: loss on the unpredictable first run and on the repeats during training, for the chosen depth; chance is ln 16 ≈ 2.77 nats.

What you will learn
Workshop
A GPT with d = 32, 2 heads, MLP width 64, learned positions, trained from scratch for 1 500 steps (AdamW, learning rate 0.003, batches of 16) on fresh random sequences each step. Loss measured every 20 steps on 24 fixed held-out sequences: positions in the first run, and positions in the repeats.

Two layers to copy

With two layers the loss on the repeats falls from chance to 0.53 nats by step 1 500, crossing half of chance at step 900, while the loss on the unpredictable first run stays near chance at 2.99 — the model has learned to copy, not to guess. With one layer the repeats end at 1.39: it improves, using what a single layer can do with positions and content, but it does not solve the task. The difference is composition: the second layer’s attention depends on what the first layer wrote.

In large models induction heads appear early in pretraining, around the point where the loss curve shows a characteristic bump, and their formation coincides with models becoming able to use earlier context — the in-context learning that makes prompting work. Plate XXII.1’s repetitive greedy text is their side effect: once a phrase has repeated, induction heads predict that it will repeat again. They are the best-understood circuit in language models, and a template for how interpretability finds mechanisms: a behaviour, a hypothesis about components, and patching to confirm it.

The gradual curve here, rather than a sharp phase change, reflects a tiny model and a short run; the abruptness reported for large models depends on scale and data.

Terms

Induction head
An attention head that copies the token that followed an earlier occurrence of the current token.
Previous-token head
A head that writes the identity of the preceding token at each position.
Composition
One layer’s attention depending on what an earlier layer wrote.
In-context learning
Using examples in the prompt to improve predictions without changing weights.
Induction heads copy patterns by composing two attention layers; they form during training and underlie in-context learning.

Sources

  1. Olsson et al., “In-context Learning and Induction Heads”, Anthropic, 2022.
  2. Elhage et al., “A Mathematical Framework for Transformer Circuits”, Anthropic, 2021.
  3. Reddy, “The mechanistic basis of data dependence and abrupt learning in an in-context classification task”, ICLR 2024.