Induction heads
Explain the two-head circuit that completes [A][B] … [A] → [B]. A previous-token head writes 'my predecessor was A' at B's position; an induction head at the later A searches for that marker and copies B. Relate it to the sudden drop during training in loss on tokens late in a context, which can be predicted from earlier parts of the same context.
Builds on: QK and OV circuits of a head, The residual stream as a shared channel, In-context learning
What the animation says
A pair seen once
Here's a made-up pair: Zxqv, then Plorb. Give the model this line, and at the second Zxqv it predicts Plorb. It almost surely never saw that pair in training. So it must read it from the context. But one attention head can't do this alone. At Plorb's position, the vector only says: I am Plorb. Nothing there says: I came after Zxqv. So how does the model find it?
Step 1: leave a marker
The trick takes two heads. First, in an earlier layer, a previous-token head. Every position attends to the one just before it. It copies that token's identity into its own stream, as a marker. Now Plorb's vector carries a second note: my predecessor was Zxqv. Later, at the second Zxqv, a new head goes searching. What does it look for?
Step 2: the induction head
It looks for the marker. This is the induction head, in a later layer. Its query says: current token is Zxqv. Each key offers that position's marker. Only Plorb's marker matches, so nearly all attention lands on Plorb. Then it copies Plorb's content into the prediction, and Plorb's score goes up. Matching is the query-key circuit. Copying is the value-output circuit. Its keys read the first head's output. That's called K-composition.
A toy induction head in numpy
Here it is in numpy. Tokens three, one, four, two, three: that's A, B, then A again. This line makes one-hot rows: all zeros, with a one at the token's id. P shifts those rows down by one. That's the previous-token head's marker. Now the last position's query: I am token three. This line scores every marker against it, times ten. Which position matches?
Why loss drops late, and suddenly
Why does this circuit matter in training? Here are some illustrative numbers. Without copying, the model gives the follower five percent. That's a loss of three nats. With the circuit, it copies at sixty percent. That's about half a nat. Only tokens with an earlier repeat gain, and those sit mostly late in the context. Neither head lowers loss alone, so each gets little gradient until the other partly exists. Once both start forming, they boost each other, and late-token loss drops sharply.
Two heads: leave a marker, then search it
The circuit in QK/OV terms
Why loss drops late in context, suddenly
Toy induction head in numpy
import numpy as np
x = np.array([3, 1, 4, 2, 3]) # A B . . A
V = 5
E = np.eye(V)[x] # token content, [T, V]
P = np.vstack([np.zeros(V), E[:-1]]) # prev-token head's marker
q = E[-1] # query: 'I am token 3'
s = 10 * P @ q # match marker 'prev = 3'
w = np.exp(s) / np.exp(s).sum() # attention weights
print(w.round(3)) # [0. 1. 0. 0. 0.]
print(x[np.argmax(w)]) # copies B = 1
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses