---
generator: contextjamming-llm-context
title: "Transformer Circuits & Induction Heads"
description: "Path expansion turns small attention-only transformers into readable QK and OV circuits, revealing induction heads—created through K-composition—as a general in-context learning algorithm. An interactive guide to the Anthropic paper published 22 Dec 2021."
url: https://www.contextjamming.com/transformer-circuits-induction
markdown_url: https://www.contextjamming.com/transformer-circuits-induction.md
section: "Research Builds & Explainers"
content_type: "Research Build"
author: "Bret Kerr"
publisher: "Context Jamming (ACRA Insight LLC)"
date_published: 2021-12-22
language: en-US
word_count: 2616
---

> **Transformer Circuits & Induction Heads** — Research Builds & Explainers, Context Jamming. This is a plain-Markdown copy of https://www.contextjamming.com/transformer-circuits-induction, prepared for LLM context windows, agents and retrieval.
>
> Cite as: Bret Kerr, "Transformer Circuits & Induction Heads," *Context Jamming*, December 22, 2021, https://www.contextjamming.com/transformer-circuits-induction

CONTEXT JAMMING / MECHANISTIC INTERPRETABILITY / 22 DEC 2021

# TRANSFORMER CIRCUITS *& INDUCTION HEADS*

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.

EXPAND THE MODEL[READ THE ORIGINAL TRANSFORMER CIRCUITS PAPER ↗](https://transformer-circuits.pub/2021/framework/index.html)

PAPER-DERIVED ARCHITECTURE · CONCEPTUAL RECONSTRUCTION

ZERO-LAYER**bigram table**ONE-LAYER**skip-trigram ensemble**TWO-LAYER**induction via K-composition**

PRIMARY SOURCE · ANTHROPIC · THEORETICAL + REVERSE ENGINEERING

**A Mathematical Framework for Transformer Circuits**

Nelson Elhage, Neel Nanda, Catherine Olsson, Tom Henighan, Nicholas Joseph, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, Tom Conerly, Nova DasSarma, Dawn Drain, Deep Ganguli, Zac Hatfield-Dodds, Danny Hernandez, Andy Jones, Jackson Kernion, Liane Lovitt, Kamal Ndousse, Dario Amodei, Tom Brown, Jack Clark, Jared Kaplan, Sam McCandlish, Chris Olah

**Scope**

Attention-only transformers with at most two layers. Published 22 December 2021.

01 · The old mental modelCONCEPTUAL JOB · separate visible attention from a causal explanationPAPER ANCHOR · Transformer Overview; Attention Heads as Information Movement

## “Attention moves information” is true—and radically incomplete.

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.

ONE ATTENTION HEAD`Aʰ ⊗ WOVʰ`

The attention pattern A moves information across positions; WOV transforms the moved information.

**DO NOT CONFUSE**

An attention pattern says where a head reads. It does not, by itself, say what the head writes or how that write affects the logits.

Once “where” and “what” are separated, the sudden advantage of a second layer becomes a tractable anomaly rather than a vague scaling story.

02 · The anomalyCONCEPTUAL JOB · show why an extra layer changes the available algorithmPAPER ANCHOR · Summary of Results; One- and Two-Layer Attention-Only Transformers

## One layer can copy. Two layers can discover a rule.

0L

### Bigram

`[A] → [B]`

The direct embedding-to-unembedding path stores local statistics.

1L

### Skip-trigram

`[B] … [A] → [B]`

A head can copy a plausible earlier token, conditioned on learned token statistics.

2L

### Induction

`[A][B] … [A] → [B]`

One head shifts a key; another matches the prefix and copies its continuation.

ESTABLISHED RESULTThe paper reverse-engineers these algorithms in small attention-only models.AUTHOR INTERPRETATIONThis constitutes a transition to a more general form of in-context learning.CONTEXT JAMMING EXTENSIONLater, we compare the circuit’s shifted lookup to pointer arithmetic without claiming identity.

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.

03 · The coordinate changeCONCEPTUAL JOB · turn layer products into additive end-to-end circuitsPAPER ANCHOR · The Path Expansion Trick; Path Expansion of Logits

## Expand the product. Read the 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.

ONE-LAYER LOGIT MAP`T = Id ⊗ WUWE + Σₕ Aʰ ⊗ (WUWOVʰWE)`

The direct bigram path plus one additive term for every attention head.

PAPER-DERIVED VALUES · TERM-IMPORTANCE TABLE · TWO-LAYER MODEL

Freeze attention patternsSOURCE TOKEN

RESIDUAL STREAM / Dursley**LINEAR MAP**

With attention patterns held fixed, selected end-to-end paths add linearly from tokens to logits.

-7.3 nats aggregate marginal reduction

ORDER 0**-1.8 nats**1 term · -1.8 nats/term

The embedding-to-unembedding route; a readable bigram table.

ORDER 1**-5.2 nats**24 terms · -0.2 nats/term

Each head contributes an end-to-end token-to-logit map; together these behave like skip-trigram tables.

ORDER 2**-0.3 nats**144 terms · -0.002 nats/term

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.

**DO NOT CONFUSE**

Freezing attention patterns does not approximate the OV computation. It holds the QK-derived routing fixed so the resulting token-to-logit function is exactly linear for that run.

At order zero and one, the abstract paths collapse into something almost embarrassingly concrete: tables of token relationships.

04 · Zero- and one-layer baselinesCONCEPTUAL JOB · read bigrams and skip-trigrams directly from expanded weightsPAPER ANCHOR · Zero-Layer Transformers; Interpretation as Skip-Trigrams

## A tiny transformer is a compressed room full of index cards.

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.

PAPER-DERIVED LARGE-ENTRY EXAMPLES · NORMALIZED CONCEPTUAL RECONSTRUCTION

HEAD VIEW

MAGNITUDE ≥ 0.15

keep and open def github Ralph

keep

and

open

def

github

Ralph

QK CIRCUIT**HOVER OR FOCUS A CELL**

QK asks: when the destination token queries, which source token should receive attention?

—

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.

**DO NOT CONFUSE**

“Readable from weights” does not mean “easy to summarize.” At a roughly 50,000-token vocabulary, one expanded matrix contains about 2.5 billion entries, and QK rows require normalization choices.

A second layer adds more than another pile of cards. It lets later heads read what earlier heads wrote.

05 · The three operatorsCONCEPTUAL JOB · separate the three ways attention heads can composePAPER ANCHOR · Three Kinds of Composition; corrected composition diagram

## Q changes the question. K changes the address. V chains the payload.

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.

PAPER-DERIVED QUALITATIVE RESULT · CORRECTED COMPOSITION DIAGRAM

SELECTED OPERATOR**K-composition**

A later head's key reads the previous-token head's output. This shifts key content forward one position and enables prefix matching.

Show corrected additional composition

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.

**DO NOT CONFUSE**

The paper’s studied model uses K-composition centrally for induction. That does not establish that Q- and V-composition are universally negligible. The corrected figure also reveals more composition than the original visualization suggested.

With the operators separated, the induction algorithm can be stated as a three-step program rather than a mysterious diagonal in an attention map.

06 · Induction heads appearCONCEPTUAL JOB · recompute the minimal previous-token + match + copy algorithmPAPER ANCHOR · Induction Heads; How Induction Heads Work

## Shift the key. Match the prefix. Copy what came next.

01

A previous-token head writes information about token *j − 1* at position *j*.

02

K-composition lets the induction head compare the current query with that shifted key.

03

A copying OV circuit raises the logit for the token found immediately after the earlier match.

PAPER-DERIVED MECHANISM · ILLUSTRATIVE DETERMINISTIC RECOMPUTATION

Previous-token headMATCHING STRENGTH 0.90

**01** SHIFT KEY**02** MATCH SAME TOKEN**03** COPY NEXT TOKEN

CURRENT RESULT**small → son**

The current token matches an earlier token; the shifted key lands attention on the token that followed it.

illustrative next-token logit effect +2.88

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.

**DO NOT CONFUSE**

The induction head’s visible attention pattern is informative, but it does not explain how the head decided where to attend. That decision depends on K-composition with an earlier head.

Natural language can hide a lookup-table trick inside familiar statistics. Random repeated tokens remove that escape hatch.

07 · The out-of-distribution testCONCEPTUAL JOB · remove every distributional cue except repetitionPAPER ANCHOR · Function of Induction Heads; random repeated-sequence experiment

## The algorithm survives when the language disappears.

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.

ILLUSTRATIVE MODEL · SYNTHETIC TOKENS · PAPER-OBSERVED BEHAVIOR

SEED<39811>SEED<7598>SEED<1764>SEED<8873>SEED<5186>SEED<40593>COPY 1<39811>*← predicts <7598>*COPY 1<7598>*← predicts <1764>*COPY 1<1764>*← predicts <8873>*COPY 1<8873>*← predicts <5186>*COPY 1<5186>*← predicts <40593>*COPY 1<40593>*← predicts <39811>*COPY 2<39811>*← predicts <7598>*COPY 2<7598>*← predicts <1764>*COPY 2<1764>*← predicts <8873>*COPY 2<8873>*← predicts <5186>*COPY 2<5186>*← predicts <40593>*COPY 2<40593>*← predicts <39811>*

SEED 1741**INDUCTION SIGNAL PRESENT**

The tokens have no linguistic relation. Repetition alone creates the address structure an induction head needs.

**DO NOT CONFUSE**

The synthetic tokens below are generated locally. The paper-derived claim is that the studied induction heads operated on repeated random sequences far outside the training distribution—not that this page is running the authors’ checkpoint.

A clean mechanism still needs an importance test: elegant terms can exist algebraically without doing much useful work.

08 · Ablations and boundariesCONCEPTUAL JOB · measure path-order importance and expose the framework’s limitsPAPER ANCHOR · Term Importance Analysis; Virtual Attention Heads; Where Does This Leave Us?

## Not every path earns its keep.

PAPER-DERIVED VALUES · TERM IMPORTANCE ANALYSIS

REMAINING MARGINAL LOSS REDUCTION**7.3 nats**

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.

SMALL HERE

### Virtual heads

Order-2 V-composed paths contribute only −0.3 nats in aggregate in the studied model, versus −5.2 nats for individual heads.

OPAQUE

### MLP layers

The paper deliberately removes MLP blocks. It offers little traction on the feature superposition and nonlinear computation they add.

IMPERFECT TEST

### Eigenvalue positivity

The authors use it as a working summary for matching and copying matrices, while explicitly declining to call it a complete definition.

SCOPE LIMIT

### Scale

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.

09 · Context Jamming extensionCONCEPTUAL JOB · map shifted lookup to addressable agent memory without asserting identityPAPER ANCHOR · Additional Intuition: pointer arithmetic; Context Jamming extension

## A circuit that behaves like pointer arithmetic.

CONTEXT JAMMING EXTENSION / STRUCTURAL ANALOGY, NOT IDENTITY

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.

CONTEXT JAMMING EXTENSION · STRUCTURAL ANALOGY, NOT IDENTITY

MEMORY TAPE

INDUCTION-STYLE RETRIEVAL**red → blue**

Treat the current symbol as an address: find its earlier occurrence, advance one position, and retrieve what came next.

PAPER OBJECTPrevious-token shift**+**PAPER OBJECTSame-token match**+**PAPER OBJECTCopying OV*↔*STRUCTURAL ANALOGYAddress + offset + retrieval

### Where the analogy breaks

1. The paper studies pure attention-only toy models; real agents contain MLPs, many more layers, tools, retrieval systems, and external state.
2. The paper discovers induction heads by weight inspection in two-layer models; an agent may implement similar behavior through entirely different circuits or software.
3. The paper provides no causal evidence that induction heads are the primary driver of in-context learning at scale; that question is explicitly deferred to later work.

### A falsifiable extension

MEASURABLE OBJECTInduction accuracy on repeated random sequences before and after targeted ablation.EXPERIMENTAblate a candidate previous-token head; then insert an artificial one-step shifter and measure recovery.WEAKENING RESULTInduction-like behavior remains unchanged and no shifted-key path can be identified.PRIMARY CONFOUNDRedundant heads or MLP-mediated substitutes preserve the behavior after a single-path intervention.

The right ending is therefore not “transformers are databases,” but a ledger that records which statements belong to evidence, interpretation, and extension.

10 · Epistemic ledgerCONCEPTUAL JOB · keep derivation, interpretation, and extension visibly separatePAPER ANCHOR · Summary of Results; Where Does This Leave Us?; CJ synthesis

## Three layers. No smuggling.

ESTABLISHED / PAPER-DERIVED

- Zero-layer models expose a bigram table in their weights.
- One-layer attention-only models factor into bigram and skip-trigram paths.
- The studied two-layer model contains induction heads reliant on K-composition with earlier heads.
- Repeated random tokens elicit the induction pattern in the paper’s experiment.
- Order-2 virtual-head paths have a small aggregate effect in the paper’s term-importance analysis.

AUTHOR PROPOSAL / INTERPRETATION

- Induction heads constitute a more powerful and general in-context learning algorithm than one-layer copying.
- Virtual attention heads may matter more in larger, deeper models despite being weak here.
- Path-based circuit analysis may scale at least partially beyond these toy systems.
- Positive eigenvalues are a useful but incomplete signature of matching and copying.

CONTEXT JAMMING EXTENSION

- Induction’s shift-match-copy structure resembles pointer arithmetic over addressable context.
- That motif may be useful when designing experiments on agent memory and retrieval.
- No identity between the toy circuit and modern agent memory is claimed.

With the claims sorted, the vocabulary can become compact rather than slippery.

11 · GlossaryCONCEPTUAL JOB · make the circuit vocabulary reusablePAPER ANCHOR · Notation; Transformer Overview; Two-Layer sections

## A field guide to the residual stream

Residual stream

The shared vector channel that components read from and add their outputs to.

Path expansion

Algebraically expanding layer products into a sum of end-to-end routes through the model.

QK circuit

The query-key computation that sets attention scores: where a head reads.

OV circuit

The output-value computation that maps an attended token to a change in logits: what a head writes.

Bigram

A next-token relationship involving the present token and the token predicted after it.

Skip-trigram

A factored relationship of the form source … destination → output.

Composition

A later attention head reading information written by an earlier attention head.

K-composition

Composition in which the later head's key reads the earlier head's output.

Previous-token head

A head whose attention pattern mainly selects the token one position back.

Induction head

A head that finds an earlier occurrence of the current token and copies the token that followed it.

Virtual attention head

An implicit end-to-end term created when two heads V-compose.

Eigenvalue positivity

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.

12 · ConclusionCONCEPTUAL JOB · state the mechanism in one durable sentencePAPER ANCHOR · Summary of Results

## Two layers are enough to turn a table into a program.

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.

[READ THE PAPER ↗](https://transformer-circuits.pub/2021/framework/index.html)[CONTINUE TO THE 2022 FOLLOW-UP](https://www.contextjamming.com/induction-heads-in-context-learning)

The citation map below pins each claim to the primary source and records the paper’s post-publication correction.

13 · Source notesCONCEPTUAL JOB · make every major claim auditablePAPER ANCHOR · Primary source and correction

## The argument, pinned to the paper

1. **Zero-layer result:** “Zero-Layer Transformers.”
2. **One-layer path expansion and QK/OV split:** “The Path Expansion Trick” and “Splitting Attention Head terms into Query-Key and Output-Value Circuits.”
3. **Skip-trigram interpretation and large entries:** “Interpretation as Skip-Trigrams” and the linked head-dump tables.
4. **Three compositions:** “Three Kinds of Composition” and “Path Expansion of Attention Scores QK Circuit.”
5. **Induction algorithm:** “Function of Induction Heads” and “How Induction Heads Work,” including the Id ⊗ Aᵖʳᵉᵛ ⊗ W term.
6. **Copying / matching detection:** “Checking the Mechanistic Theory” and the two-dimensional OV/QK eigenvalue-positivity comparison.
7. **Ablation values:** “Term Importance Analysis”: order 0 −1.8 nats; order 1 −5.2 nats across 24 terms; order 2 −0.3 nats across 144 terms.
8. **Limits:** “Where Does This Leave Us?” and “Additional Intuition and Observations: MLP Layers.”
9. **Correction:** “Correction: Attention Head Composition Diagram.” The bug affected one visualization; the importance of previous-token K-composition remained, with additional composition revealed.

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 ↗](https://transformer-circuits.pub/2021/framework/index.html)
