Bigram
[A] → [B]The direct embedding-to-unembedding path stores local statistics.
CONTEXT JAMMING / MECHANISTIC INTERPRETABILITY / 22 DEC 2021
How two layers of attention invent in-context learning
Attention is not merely a blur of token-to-token links. Expand the residual stream into end-to-end paths and a small transformer becomes legible: QK circuits choose where to look; OV circuits decide what to write. In two layers, those parts compose into a reusable copying algorithm.
A head does two different jobs. Its QK circuit decides which source positions receive attention. Its OV circuit decides how information from an attended source changes the destination and, ultimately, the next-token logits.
Once “where” and “what” are separated, the sudden advantage of a second layer becomes a tractable anomaly rather than a vague scaling story.
[A] → [B]The direct embedding-to-unembedding path stores local statistics.
[B] … [A] → [B]A head can copy a plausible earlier token, conditioned on learned token statistics.
[A][B] … [A] → [B]One head shifts a key; another matches the prefix and copies its continuation.
To see the difference in the weights, we first need the paper’s decisive coordinate change: replace a stack of layers with a sum of paths.
Residual connections make each layer an identity path plus a collection of attention-head writes. Multiplying layers out produces a sum: one term for every end-to-end route from input token to output logit.
The embedding-to-unembedding route; a readable bigram table.
Each head contributes an end-to-end token-to-logit map; together these behave like skip-trigram tables.
V-composed virtual heads are elegant, but have little marginal effect in the studied two-layer model.
The nats are the paper's aggregate ablation values, not a token-specific decomposition for “ Dursley.” The token selector changes the conceptual route being inspected. Higher-order virtual-head terms are small in this model.
At order zero and one, the abstract paths collapse into something almost embarrassingly concrete: tables of token relationships.
The zero-layer matrix maps the present token directly to next-token logits: a bigram table. Add one layer and each head contributes a factored skip-trigram table. QK selects a source given the destination; OV changes output logits given that source.
The paper publishes enormous expanded matrices (roughly 2.5 billion entries at a 50k vocabulary) and curated large-entry tables. This compact viewer preserves published example families and sign logic; its normalized cell intensities are not a model checkpoint dump.
A second layer adds more than another pile of cards. It lets later heads read what earlier heads wrote.
A later head can read an earlier head’s write through its query, key, or value projection. Q- and K-composition alter the attention pattern. V-composition alters what is moved and creates an implicit virtual head.
Bar lengths are schematic, not Frobenius-norm measurements. The original paper figure contained a library bug; the correction preserves the previous-token K-composition result while revealing additional composition for two induction heads.
With the operators separated, the induction algorithm can be stated as a three-step program rather than a mysterious diagonal in an attention map.
A previous-token head writes information about token j − 1 at position j.
02K-composition lets the induction head compare the current query with that shifted key.
03A copying OV circuit raises the logit for the token found immediately after the earlier match.
The current token matches an earlier token; the shifted key lands attention on the token that followed it.
The attention rule is a deterministic reconstruction of the paper's mechanism, not a running transformer. Positive QK and OV eigenvalues are a working formalization of matching and copying, not a complete definition.
Natural language can hide a lookup-table trick inside familiar statistics. Random repeated tokens remove that escape hatch.
Uniformly sampled vocabulary tokens do not form plausible phrases. Yet when a random sequence repeats, the induction pattern continues: find the earlier copy of the current token and attend to what followed it.
The tokens have no linguistic relation. Repetition alone creates the address structure an induction head needs.
A clean mechanism still needs an importance test: elegant terms can exist algebraically without doing much useful work.
Order 2 contributes only 0.3 nats in aggregate—about 0.002 nats per virtual-head term.
This ablation isolates V-composition by freezing ground-truth attention patterns. It does not imply that Q- or K-composition is unimportant; K-composition is essential to the induction circuit.
Order-2 V-composed paths contribute only −0.3 nats in aggregate in the studied model, versus −5.2 nats for individual heads.
The paper deliberately removes MLP blocks. It offers little traction on the feature superposition and nonlinear computation they add.
The authors use it as a working summary for matching and copying matrices, while explicitly declining to call it a complete definition.
This paper does not causally establish induction heads as the primary driver of in-context learning in large, modern transformers.
Those limits make the structural analogy useful only if it is fenced, testable, and kept separate from the paper’s findings.
An induction head converts token content plus a one-step shift into an address: “find this earlier symbol, advance, retrieve.” That resembles pointer arithmetic in a memory system. It is a structural rhyme, not a claim that today’s agents store or retrieve memory through this exact circuit.
Treat the current symbol as an address: find its earlier occurrence, advance one position, and retrieve what came next.
The right ending is therefore not “transformers are databases,” but a ledger that records which statements belong to evidence, interpretation, and extension.
With the claims sorted, the vocabulary can become compact rather than slippery.
The shared vector channel that components read from and add their outputs to.
Algebraically expanding layer products into a sum of end-to-end routes through the model.
The query-key computation that sets attention scores: where a head reads.
The output-value computation that maps an attended token to a change in logits: what a head writes.
A next-token relationship involving the present token and the token predicted after it.
A factored relationship of the form source … destination → output.
A later attention head reading information written by an earlier attention head.
Composition in which the later head's key reads the earlier head's output.
A head whose attention pattern mainly selects the token one position back.
A head that finds an earlier occurrence of the current token and copies the token that followed it.
An implicit end-to-end term created when two heads V-compose.
The paper's imperfect summary statistic for whether a matrix behaves like matching or copying.
The framework’s payoff is not a new metaphor for attention. It is a practical method for turning parameters into candidate programs.
Path expansion makes the small model readable because it changes the unit of analysis: not a layer, neuron, or attention map, but an end-to-end route from tokens to logits. In one layer, those routes encode skip-trigrams. In two, an earlier head can shift information so a later head retrieves by relation rather than memorized plausibility. That is the induction circuit—and the paper’s first clean example of a transformer implementing a general algorithm in context.
The citation map below pins each claim to the primary source and records the paper’s post-publication correction.
Elhage, Nelson, Neel Nanda, Catherine Olsson, et al. “A Mathematical Framework for Transformer Circuits.” Transformer Circuits Thread, Anthropic, 22 Dec. 2021.
Read the original Transformer Circuits paper ↗