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 → mindkeep 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 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 be the representation at the receiving position and the representation at a source. Using row vectors, a head computes:
The query and key produce a score. Softmax compares that score with those of all causally available sources:
Then the head returns a weighted mixture and projects it into the residual stream:
Focus on the contribution from just one source:
The query affects the scalar . For a fixed source representation and head, it does not change the vector . 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:
| Path | What it determines |
|---|---|
| QK: query and key | How strongly a destination weights each source |
| OV: value and output projection | The 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, , 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 . 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:
Both entries are positive because this head has learned to support both continuations. If in attends to keep with weight , while at attends with weight , the contributions are:
| Destination | Weight on keep | Added to mind logit | Added to bay logit |
|---|---|---|---|
in | |||
at |
The attention weights differ, but the message’s proportions do not. in receives unwanted support for bay; at receives unwanted support for mind.
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:
This is an outer product: its rows are proportional and its rank is at most one. It cannot equal the independent requests and , 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 , key strength , and message weight for mind equal to . 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 and above.
Before changing a control, predict whether increasing can make mind beat bay for in while making bay beat mind for at. Compare the two rows, then change only . Record which contributions changed in each case.
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.
| Prefix | Attention to keep | Δ mind | Δ bay |
|---|---|---|---|
keep this in | 96.5% | 1.929 | 1.929 |
keep this at | 90.9% | 1.819 | 1.819 |
Both rows have the same mind:bay ratio (2:2). Changing the query changes the amount delivered.
Inspect the arithmetic
Head 1: scores = [4.000, 0.000, 0.000]; softmax = [0.965, 0.018, 0.018]; contribution = 0.965 × [2, 2].
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 . One head writes and favors the in query; the other writes 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 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 and writes information about that token into position . 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:
Here , , 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:
| Position | Self identity | Previous identity |
|---|---|---|
| 0 | A | — |
| 1 | B | A |
| 3 | C | X |
| 4 | D | C |
| 6 | A | X |
At layer 1, choose the projections so that the query reads self, the key reads previous, and the value reads self:
With row vectors, these matrices turn into , , and .
At the final A, the query is . The key at position 1 is also , because B follows A. That match selects position 1, whose value is . The output can therefore support B.
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 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 , with the usual head-dimension scale absorbed into the factor .
For the default sequence, one of seven keys matches the final A. Its weight is:
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:
- Change from
AtoC. Which earlier source should receive the largest weight? - Restore
A, then change fromBtoD. Should the strongest source position change, or only what it sends? - Restore
Band choose . What remains in the keys when that earlier write is replaced by zero? - Restore , then choose . Should the attention pattern survive this intervention?
Find the continuation that followed this token
Stage 1/4: Token identities
| Position | Self |
|---|---|
| 0 | A |
| 1 | B |
| 2 | X |
| 3 | C |
| 4 | D |
| 5 | X |
| 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 . 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.