Language models Working model Advanced 3D dissection 56 components 20 Oct 2026

Anatomy of Induction Heads

In-context Learning and Induction Heads, dissected: a two-layer attention-only Transformer in 3D, every matrix a real one from a model trained in the repository, with seven pre-registered hypotheses tested on 14 training runs.

A complete, granular dissection of Olsson et al. (2022), In-context Learning and Induction Heads. The paper's small attention-only Transformer is rebuilt at miniature size (two layers, four heads of width 16, 45,376 parameters, positions on queries and keys only) and trained for 3,000 steps on a synthetic language that mixes a Markov chain with repeated random spans. Every tensor of its forward pass on the text you type is drawn on a 3D stage as a block of cells: the embedding table, LayerNorm, queries, keys and values, every head's scores, softmax and output, the residual stream climbing from layer 1 to layer 2, the orange route by which layer 2's keys read what layer 1 wrote, and the unembedding. Thirty steps walk the camera through the computation, then replay training from eighteen snapshots, then through the paper's six arguments, its inconsistencies, and later work, each with the paper's numbers hover-linked to the sentence they come from. A research desk, with hypotheses and numeric verdict rules written before the runs, tests whether the induction head forms in one window with in-context learning and a loss bump (five seeds), whether smeared keys move the phase change, and whether ablations support the mechanism, and reports every seed.

The machine

A staircase on a table. Layer 1 is the lower-left tower, layer 2 the upper-right one, and the residual stream climbs between them. Each tower holds, from the bottom, the residual stream, its LayerNorm, the query/key input with positions added, the three weight matrices with their query, key and value blocks above them, four pods of scores, softmax weights and head outputs, the concatenation, W_O, the attention output and the new residual stream. The embedding and position tables sit at the lower left, the unembedding, logits and probabilities at the top right, and an orange line carries layer 1's output into layer 2's keys. Cell colour and height are the values.

What is real. Everything on the stage is computed in the page from trained weights: a 45,376-parameter attention-only Transformer trained in PyTorch for 3,000 steps on a CPU. Its JavaScript forward pass matches PyTorch to within 4e-5 on three inputs, an earlier training snapshot, a randomly initialised smeared-key network, and pattern-preserving and full head ablations (test.mjs), and the same tests recompute every derived number in the text: parameter counts, the paper's non-embedding column, the in-context learning score from the stored curves, and the behaviours the text claims on the default input. Paper figures are quoted from the arXiv v1 PDF's text layer and from the follow-up papers' sources, and listed in the fact ledger. The research desk is reproducible from research/: 14 runs across four arms, pre-registered in research/README.md.

What to take away

  • An induction head is a pair: a layer 1 head writes each token's predecessor into the residual stream, and a layer 2 head matches the current token against those writes and copies what followed.
  • Because the residual stream carries no position, a single layer cannot find what came before a token, which is why one-layer models form no induction head and smeared keys let one layer do it.
  • In this miniature the induction head, the loss drop and repeat accuracy rise together, but the in-context learning score has a long tail, so the paper's single-window picture holds more loosely than a tight pre-registered rule asked for.
  • Ablating a single head costs little; the work is shared across heads, and which layer 1 head is a single point of failure depends on the seed.
  • Smeared keys moved the onset of induction from about step 1,460 to within the first 300 steps, and the heads that did the work were in layer 1.
  • Fully ablating the previous-token heads destroys in-context learning while ablating them with their attention patterns preserved costs nothing, which is what K-composition predicts.

Sources

More machines

Other working models

Anatomy of the Transformer: a still of the machine Working model · 3D AI & ML · Language models

Anatomy of the Transformer

Attention Is All You Need, dissected: the whole encoder-decoder in 3D, every matrix a real one from a trained model running in your browser, every number from the paper traced to its sentence.

The 2017 Transformer, built in 3D from its own numbers: a trained miniature of the paper's exact encoder-decoder translates your English number into German while the camera walks through 29 steps, fr…

172 components · Intermediate 15 Oct 2026
Anatomy of Adam: a still of the machine Working model · 3D AI & ML · Training & alignment

Anatomy of Adam

Kingma and Ba's optimiser, dissected: every line of Algorithm 1 drawn as real blocks on a 151-parameter network, checked against PyTorch, with a research desk that reruns Reddi et al.'s counterexample, finds how rare a large gradient must be to defeat it, and tests the paper's claims about bias correction, the size of the step and ε.

Adam in 3D: its gradient, two moving averages, bias corrections and step drawn as real blocks for any step of a live training run, tested against PyTorch, then a pre-registered research desk on the c…

61 components · Intermediate 18 Oct 2026

The whole gallery →