Draft

Skip-trigram bugs and induction heads: what Q, K, and V actually do

Queries, keys, and values are often explained as “queries ask questions, keys match, and values provide answers.” But that analogy can hide a crucial distinction: a query changes how much it reads from a source; it does not customize the value vector that source sends. Query–key matching determines the attention weights, while values supply the information being mixed.

Skip-trigram bugs and induction heads make this separation concrete. The first exposes a limitation of sending one fixed message to different receivers. The second shows why a source’s key and value can usefully describe different aspects of its representation.

Suppose an attention head helps complete both of these phrases:

  • keep this in → mind
  • keep this at → bay

In both cases, the current token could attend back to keep. But then a problem appears: the value vector at keep is the same in both prefixes. How does it know whether to send information supporting mind or bay?

If this head’s message from keep supports both continuations, increasing its attention weight strengthens both contributions. Matching alone cannot select only the mind part for one receiver and only the bay part for the other. This exposes a skip-trigram bug: useful associations can accidentally support unwanted combinations. The example comes from the analysis of small attention-only models in A Mathematical Framework for Transformer Circuits.

The induction example asks how to complete A B … A → B using the earlier pair in the current input. The final A needs to find the earlier B, where the continuation is available to copy. An earlier head can make the key at B describe “preceded by A,” while its value carries B’s identity. The later head then finds B using information about A and reads information about B. That is why matching and delivered content need separate projections.

The attention-head article develops the weighted-mixture calculation. Here we’ll use it to build the bug with two numbers, construct the induction circuit, and change its matching and value paths independently. The diagrams and widgets are hand-designed examples, not measurements from a trained language model. We treat each displayed word or letter as one token.

A trigram has three tokens; a skip-trigram allows a gap

An ordinary trigram is a consecutive sequence such as keep in mind. A trigram language model uses the last two tokens to help predict the third. A skip-trigram in this discussion has the form:

A  …  B  →  C.A\;\ldots\;B\;\to\;C.

A is an earlier source token, B is the current destination token, and C is the next token we want to predict. The gap may contain other tokens: keep this in → mind still has the relevant relationship keep … in → mind.

At prediction time, C is not yet in the input. The head reads from earlier positions to modify the next-token scores computed at B. This use of “skip-trigram” describes an attention behavior; it does not mean the transformer stores a literal three-word lookup table.

Follow one source through Q, K, V, and O

Let rir_i be the representation at the receiving position and rjr_j the representation at a source. Using row vectors, a head computes:

qi=riWQ,kj=rjWK,vj=rjWV.q_i=r_iW_Q,\qquad k_j=r_jW_K,\qquad v_j=r_jW_V.

The query and key produce a score. Softmax compares that score with those of all causally available sources:

aij=exp⁡(qikj⊤/dk)∑ℓ≤iexp⁡(qikℓ⊤/dk).a_{ij}=\frac{\exp(q_i k_j^\top/\sqrt{d_k})} {\sum_{\ell\leq i}\exp(q_i k_\ell^\top/\sqrt{d_k})}.

Then the head returns a weighted mixture and projects it into the residual stream:

oi=∑j≤iaijvjWO.o_i=\sum_{j\leq i}a_{ij}v_jW_O.

Focus on the contribution from just one source:

contribution from j=aij (rjWVWO).\boxed{\text{contribution from }j=a_{ij}\,(r_jW_VW_O).}

The query affects the scalar aija_{ij}. For a fixed source representation and head, it does not change the vector rjWVWOr_jW_VW_O. Two destinations can receive different amounts of the same message. The head’s complete output can still differ in direction because the destinations can mix different sources.

This is why circuit explanations often group the matrices into two paths:

PathWhat it determines
QK: query and keyHow strongly a destination weights each source
OV: value and output projectionThe vector a source contributes when it is read

“O” matters: the value starts in the head’s value coordinates, and the output projection maps it into the shared representation. An unembedding matrix, WUW_U, eventually maps the final representation to vocabulary logits. A logit is a score before the vocabulary softmax.

For the next calculation, use a simplified attention-only model with a linear vocabulary readout, omitting normalization and MLPs. Then the source’s logit contribution is exactly aijrjWVWOWUa_{ij}r_jW_VW_OW_U. In a deeper model, later computations can transform a head’s contribution before the final prediction.

The skip-trigram bug: one message, two incompatible requests

Keep the source representation at keep fixed. Suppose its OV path and vocabulary readout produce the following two-coordinate message:

mkeep=[22],coordinates: [mind, bay].m_{\text{keep}}= \begin{bmatrix}2&2\end{bmatrix}, \qquad\text{coordinates: [mind, bay].}

Both entries are positive because this head has learned to support both continuations. If in attends to keep with weight 0.80.8, while at attends with weight 0.60.6, the contributions are:

DestinationWeight on keepAdded to mind logitAdded to bay logit
in0.80.81.61.61.61.6
at0.60.61.21.21.21.2

The attention weights differ, but the message’s proportions do not. in receives unwanted support for bay; at receives unwanted support for mind.

Two different queries attend to keep, but both receive scaled copies of the same message supporting mind and bay.

The arrows carry one fixed vector with different scalar weights. Stronger matching cannot choose one coordinate of that vector and discard the other.

We can make the restriction exact. For one fixed source and head, stack two destinations’ logit contributions into a matrix:

[Δℓin,mindΔℓin,bayΔℓat,mindΔℓat,bay]=[ain,keepaat,keep][mkeep,mindmkeep,bay].\begin{bmatrix} \Delta\ell_{\text{in,mind}}&\Delta\ell_{\text{in,bay}}\\ \Delta\ell_{\text{at,mind}}&\Delta\ell_{\text{at,bay}} \end{bmatrix} = \begin{bmatrix}a_{\text{in,keep}}\\a_{\text{at,keep}}\end{bmatrix} \begin{bmatrix}m_{\text{keep,mind}}&m_{\text{keep,bay}}\end{bmatrix}.

This is an outer product: its rows are proportional and its rank is at most one. It cannot equal the independent requests [2,0][2,0] and [0,2][0,2], which form a rank-two matrix. Increasing query/key width does not remove this particular restriction: a head still assigns one scalar weight to each source’s entire value vector.

That is the bug in this example. It is a limitation of putting these associations into the same source contribution, not a software exception. It also does not force the full model to generate in bay: other sources, heads, the direct residual path, and later nonlinear computations can change the final ranking. Even a positive logit contribution does not by itself guarantee a higher final probability, which depends on all logits.

Try changing the match without changing the message

Start with One shared head, key strength 44, and message weight for mind equal to 22. The two prefixes differ only in their destination token; their source message is identical. The widget calculates softmax over three source positions, so its attention weights need not equal the illustrative 0.80.8 and 0.60.6 above.

Before changing a control, predict whether increasing Key strength can make mind beat bay for in while making bay beat mind for at. Compare the two rows, then change only Message weight for mind. Record which contributions changed in each case.

Hand-designed circuit · no training

Can a different query change the message?

One source message: keep sends [2, 2] to both destinations. Query q = 1 for in; q = 0.75 for at. The other two source positions send zero vectors and have zero keys.

Head contributions to two output logits; these are not probabilities
PrefixAttention to keepΔ mindΔ bay
keep this in
96.5%
1.9291.929
keep this at
90.9%
1.8191.819

Both rows have the same mind:bay ratio (2:2). Changing the query changes the amount delivered.

Inspect the arithmetic
Destination: in

Head 1: scores = [4.000, 0.000, 0.000]; softmax = [0.965, 0.018, 0.018]; contribution = 0.965 × [2, 2].

Destination: at

Head 1: scores = [3.000, 0.000, 0.000]; softmax = [0.909, 0.045, 0.045]; contribution = 0.909 × [2, 2].

Changing key strength alters how much of the message arrives. Changing the mind coordinate alters the message delivered to both destinations. Neither lets one source in this one head deliver two independently chosen vectors.

Now restore the reference settings and choose Two specialized heads. One head writes [2,0][2,0] and favors the in query; the other writes [0,2][0,2] and favors at. Their independent weights allow different sums at the destinations. At finite score strength, the nonpreferred head still has a small positive softmax weight.

This is one possible construction, not a claim that trained models allocate one neat rule to each head. Follow-up skip-trigram experiments found a different two-head strategy using addition and cancellation. Its lesson for interpreting a real model is that contributions from several heads can jointly implement a condition.

For your own variation, choose unequal message coordinates and predict both rows before moving the slider. The check is whether the one-head rows remain proportional. Then switch to two heads without changing those coordinates and explain why that constraint no longer applies to their sum.

A different problem: recover a continuation from this context

The phrase examples involve associations stored in weights. Now consider an arbitrary sequence:

position:  0  1  2  3  4  5  6
input:     A  B  X  C  D  X  A  → ?

Earlier in this input, A was followed by B. At the final A, a pattern-completion mechanism could support B again. If we replace that earlier B with D, the useful continuation changes without changing any weights.

The pattern [A][B]…[A]→[B][A][B]\ldots[A]\to[B] is the basic induction behavior studied in In-context Learning and Induction Heads. The crucial attention target is the earlier B position: that is where the continuation is available to copy. Attending only to the earlier A would retrieve A’s value instead.

So the later A needs to find a source whose key effectively says “the preceding token was A”, while its value says “the token here is B.” A single position can support both descriptions because its key and value are different projections of its representation.

Induction does not magically make a value depend on its receiver. It arranges for the useful continuation to be stored at a source that the query can identify.

First write the previous token; then match it

We can build that arrangement in two sequential stages. Call them layer 0 and layer 1 to match a zero-based implementation.

At layer 0, a previous-token head reads from position j−1j-1 and writes information about that token into position jj. Its QK path uses positional information to favor the preceding position; its OV path carries that position’s token identity. The receiving position’s own identity remains available through the residual stream. Our toy representation reserves separate coordinates for the two identities:

rj=[etj⏟self  ∣  etj−1⏟previous].r_j=\bigl[\underbrace{e_{t_j}}_{\text{self}}\;\big|\; \underbrace{e_{t_{j-1}}}_{\text{previous}}\bigr].

Here eAe_A, eBe_B, and so on are one-hot identity vectors. Position 0 has no predecessor, so its previous-token coordinates are zero. These literal slots are a teaching construction; a trained network can represent information in overlapping directions.

After this write, the relevant positions contain:

PositionSelf identityPrevious identity
0A—
1BA
3CX
4DC
6AX

At layer 1, choose the projections so that the query reads self, the key reads previous, and the value reads self:

WQ=[I0],WK=[0I],WV=[I0].W_Q=\begin{bmatrix}I\\0\end{bmatrix},\qquad W_K=\begin{bmatrix}0\\I\end{bmatrix},\qquad W_V=\begin{bmatrix}I\\0\end{bmatrix}.

With row vectors, these matrices turn [self∣previous][\text{self}\mid\text{previous}] into qi=etiq_i=e_{t_i}, kj=etj−1k_j=e_{t_{j-1}}, and vj=etjv_j=e_{t_j}.

At the final A, the query is eAe_A. The key at position 1 is also eAe_A, because B follows A. That match selects position 1, whose value is eBe_B. The output can therefore support B.

A previous-token head writes A into the previous-token coordinates at B. A later query A matches that key and reads B's value to support B as the next token.

The first arrow moves information from the earlier A to the earlier B position. The second moves B’s continuation information to the current A position. Both information transfers travel forward through the sequence; the attention lookups point backward.

This is K-composition: a later head’s key projection reads information written by an earlier head. The minimal construction uses heads in successive layers because heads within one layer compute from the same input and cannot read each other’s newly produced outputs. This two-stage account is a useful circuit model, not a universal statement that every implementation of pattern completion must use exactly these two heads.

The distinction from the skip-trigram bug is now precise. The one-head phrase example tried to send different answers from the same source message. The induction circuit changes the source description: position 1 is identifiable as “after A,” while position 4 is identifiable as “after C.” Queries can select different sources with different values.

Trace the circuit, then break one path

Use Next stage to inspect the tokens, the previous-token write, the QK match, and the output. The first write is an idealized exact shift. The second head computes softmax from scores 8 qikj⊤8\,q_i k_j^\top, with the usual head-dimension scale absorbed into the factor 88.

For the default sequence, one of seven keys matches the final A. Its weight is:

a6,1=e8e8+6≈0.998.a_{6,1}=\frac{e^8}{e^8+6}\approx0.998.

The other weights are small, not zero. The bars show the head’s contributions through an identity output/readout map; they are logit contributions, not next-token probabilities.

Before each comparison, predict which table columns will change. Keep the other controls at their reference settings:

  1. Change Current query token from A to C. Which earlier source should receive the largest weight?
  2. Restore A, then change Earlier continuation after A from B to D. Should the strongest source position change, or only what it sends?
  3. Restore B and choose Remove previous-token write. What remains in the keys when that earlier write is replaced by zero?
  4. Restore Intact circuit, then choose Zero value vectors. Should the attention pattern survive this intervention?
Hand-designed circuit · ideal previous-token routing

Find the continuation that followed this token

position 0Aposition 1Bposition 2Xposition 3Cposition 4Dposition 5Xposition 6Anot in input?

Stage 1/4: Token identities

Separate self and previous-token coordinates; “—” means a zero vector
PositionSelf
0A
1B
2X
3C
4D
5X
6 (query)A

The first stage copies the previous identity exactly. The second uses real softmax weights: score = 8 × one-hot dot product. All shown positions are causally available. The predicted token is never an input.

The second comparison is particularly useful. The key at position 1 still describes A, so it remains the selected source. Its self identity changes from B to D, so its value changes. This is QK and OV doing different jobs in a calculation you can inspect.

Removing the previous-token write sets every key to zero. Equal scores produce uniform attention, so this toy loses its prefix-based selection and returns a mixture reflecting token frequencies. Zeroing values instead preserves the attention weights but removes every output contribution. The same attractive attention pattern can therefore coexist with no copying at all.

For an independent check, choose Read current token as key. Predict the winning positions before inspecting the table. Explain why matching token identity alone favors A itself, even though the desired continuation is B.

What would establish this in a trained model?

Our widgets demonstrate a possible mechanism because we supplied its matrices and the first stage’s routing. They do not show that a trained model learned those matrices.

To investigate a real head, use repeated sequences of otherwise unrelated tokens and check two properties separately: whether attention selects earlier continuation positions, and whether reading those positions supports the corresponding output tokens. Then intervene on the candidate previous-token write or copying path and measure what changes. ARENA’s induction-circuit exercises develop this workflow with activation inspection, matrix analysis, and ablations.

Repeated prefixes can have different continuations, and attention may distribute weight among several candidates. Other heads and later layers also contribute. An induction circuit explains a concrete form of context-dependent copying; it is not, by itself, an explanation of every kind of in-context learning.

The useful reading habit is to follow both sides of each attention edge: what makes this source match the query, and what vector does that source send after it matches? The skip-trigram bug exposes the limit of one fixed message. The induction construction shows how earlier computation can make a source’s key describe its context while its value carries the continuation we need.

Image viewer

Pinch or use + / − to zoom. Drag or use arrow keys to move. Esc to close.