Part XIX — Alignment, Mechanistic Interpretability, Safety & Red-Teaming · Chapter 7

Circuit tracing & induction heads

Hook

A transformer that has never seen "Ohm's Law" before can still complete "Ohm's Law states that V = I" correctly the second time the phrase appears in the same context — purely from having seen it once already. No weight update, no training example: just one forward pass finding the pattern's earlier occurrence and copying whatever followed it.

Intuition
A
B
C
A
B
?

Switch sequences. Whenever the last token has appeared earlier, attention concentrates almost entirely on the position right after that earlier occurrence — and the predicted token is whatever sat there. When nothing in the sequence matches, there's no earlier occurrence to point to, and attention spreads out with no real preference.

Formalize

An induction head is two attention heads working in sequence. A previous-token head first writes, into every position ii, a report about whatever token sat at i1i-1. The induction head then reads the current (last) token as a query and compares it against every position's previous-token report, used as a key:

scorei=qki,ki=embed(xi1),q=embed(xT),αi=scoreijscorej\text{score}_i = q \cdot k_i, \qquad k_i = \text{embed}(x_{i-1}), \qquad q = \text{embed}(x_T), \qquad \alpha_i = \frac{\text{score}_i}{\sum_j \text{score}_j}
  • xTx_T — the current (last) token in the sequence, the one we're predicting a continuation for.
  • kik_i — position ii's previous-token report: the embedding of whatever token came right before it.
  • qq — the query: the embedding of the current token.
  • αi\alpha_i — the resulting attention weight on position ii, normalized to sum to 1 across all earlier positions.
  1. Match found
    If some earlier position's previous token equals the current token, scorei=1\text{score}_i = 1 there and 0 everywhere else — attention locks onto that position.
  2. No match anywhere
    Every score is 0; normalizing 0/0 is undefined, so the head falls back to spreading weight uniformly instead.
  3. Prediction
    The output copies the token actually sitting at argmaxiαi\arg\max_i \alpha_i — not i1i-1, but ii itself, since that's what followed the matching earlier occurrence.
Play

"A B C A B" and "C A B C A" both lock onto a single earlier position with weight 1.00 — a genuine repeated token gives an unambiguous match. "A B C" has no repeated token anywhere, so the best it can do is 0.50, split between two equally uninformed guesses.

Worked example

Predicting the continuation of "A B C A B":

  1. Embed the tokens
    One-hot in a 3-symbol vocabulary: A = [1,0,0], B = [0,1,0], C = [0,0,1].
  2. Build each position's previous-token report
    • k1=embed(x0)=Ak_1=\text{embed}(x_0)=A
    • k2=embed(x1)=Bk_2=\text{embed}(x_1)=B
    • k3=embed(x2)=Ck_3=\text{embed}(x_2)=C
    • k4=embed(x3)=Ak_4=\text{embed}(x_3)=A
  3. Score against the query

    q=embed(x4)=Bq = \text{embed}(x_4) = B:

    • score1=BA=[0,1,0][1,0,0]=0\text{score}_1 = B\cdot A = [0,1,0]\cdot[1,0,0] = 0
    • score2=BB=[0,1,0][0,1,0]=1\text{score}_2 = B\cdot B = [0,1,0]\cdot[0,1,0] = 1
    • score3=BC=[0,1,0][0,0,1]=0\text{score}_3 = B\cdot C = [0,1,0]\cdot[0,0,1] = 0
    • score4=BA=[0,1,0][1,0,0]=0\text{score}_4 = B\cdot A = [0,1,0]\cdot[1,0,0] = 0
  4. Normalize and predict
    α=[0,1,0,0]\alpha = [0,1,0,0] — all the weight lands on position 2. The token actually at position 2 is C, so the prediction is C.
Checkpoint

Find the sequence, among the four, where the induction head is least confident in its prediction.

Pick a sequence to try it
Summary
αi=embed(xT)embed(xi1)jembed(xT)embed(xj1)\alpha_i = \frac{\text{embed}(x_T) \cdot \text{embed}(x_{i-1})}{\sum_j \text{embed}(x_T) \cdot \text{embed}(x_{j-1})}

Two heads, chained: one reports "what came right before me," the other matches that report against the current token and copies whatever followed the match. Real induction heads (identified in small transformers by Olsson, Elhage, and collaborators at Anthropic) run on continuous embeddings and noisy matches instead of clean one-hot vectors, but the mechanism — match on the past, copy what followed — is the same circuit this chapter traced exactly.