What a Reader Head Learns From Twelve Labeled Examples
A fit predicted attention to matching labels in twelve-example prompts. At eighteen examples it overestimated that attention for 92–94% of the heads tested.
Correction, November 25, 2026. Equation 1 fits three constants for each attention head, of which two quantities can be identified separately. It predicts how much of that head’s attention falls on matching label positions. Our earlier account incorrectly extended the result to the model’s output probabilities. Section 4, Equation 1
Imagine a prompt that labels requests about deliveries with oak and requests about refunds with ash. When a new delivery question arrives, the model can use the earlier examples to infer what oak means in this prompt. Andrew Gao and William Gao study a version of that problem in A Circuit for In-Context Learning. They trace sentence classification in three base models, Qwen3-4B, SmolLM3-3B and Llama-3.2-3B. Paper and experimental setup
A label position carries two pieces of information. The label itself provides a value. Middle-layer heads write information about the preceding sentence’s class at that position, supplying a key. Later heads can match the new sentence to those keys. The authors also identify an early signal for repeated labels and a separate group of heads that counteracts the pull of the most recent label. Their repository includes the paired prompts and scripts used to trace those steps. Authors’ code and walkthrough
Reading Equation 1
Choose one head at the query and add up its attention weights on all the example labels whose class matches the query. That sum is the quantity m in the equation. For example, weights of 0.11, 0.08 and 0.06 on three matching positions give a matching mass of 0.25. This illustrative sum says nothing by itself about the probability assigned to oak at the output.
The fit groups positions into matching labels, other labels, the first token (the attention sink), and the rest of the prompt. The fitted quantities are the matching logit L, the sink logit Lsink and the remaining unnormalized mass nrest. The last two appear only as the sum exp(L_sink) + n_rest. Matching-mass measurements can distinguish the matching logit and that combined contribution. They cannot recover the two contributions to the sum individually. Equation 1 and identifiability
What happened when the prompt grew
| Authors’ test | Qwen result | Llama result |
|---|---|---|
| Fit on 12 demonstrations spread across 2, 3, 4 or 6 classes | 127 of 140 eligible heads fit within 0.10 attention mass | 124 of 125 fit within 0.10 |
| Keep those constants and predict 18 demonstrations, with 3–9 matching slots | Median error 0.15 | Median error 0.13 |
The twelve-example comparison includes heads that assigned at least 0.03 of their attention to label slots. For the eighteen-example test the authors set a median-error target below 0.07. Both models missed it, and the fit overestimated matching mass for 92–94% of heads. Figure 9 shows the direction of the error. Extra matching examples can share a head’s existing attention budget. Figure 9 and results
If you are deciding how many labeled examples to send to a classifier, measure its answers on the same held-out queries at each candidate prompt length. Count the predicted labels that match your answer key. That gives you a task accuracy you can use to compare prompt lengths. Figure 9 answers a narrower question about attention inside the models, and the twelve-example fit did not extrapolate reliably to eighteen.
The four parts of the circuit
The paper’s central claim is that a prompt becomes a key–value memory, and that the memory has four functional parts. Each part is a population of attention heads, or a direction in the residual stream, with a job the authors name and then isolate by intervention. Paper abstract and introduction
Writers are about twenty middle-layer heads. A writer reads the sentence that precedes a label token and writes the sentence’s class into the label token’s residual stream. The label token already carries its own identity — foo or bar, oak or ash — from its embedding. That identity is the slot’s value. The class the writer deposits is the slot’s key. The split matters because the two fields are read through different attention matrices later: the key through the readers’ key matrix, the value through their value matrix. A single label token therefore stores both “which label this is” and “what kind of sentence it followed”, and the two pieces of information can be moved independently in an intervention. Introduction: writers and slots
Readers are about ninety upper-layer heads. At the query — the arrow after the final sentence — the model computes a code for the query sentence’s class and writes it at the query position. The readers then run an ordinary softmax over prompt positions, comparing that query code with the keys stored at each label token, and copy out the values from the matching slots. In effect they are induction heads keyed on a semantic class rather than on a literal repeated token: where a classic induction head copies the token that followed an earlier copy of the current token, these heads copy the label that followed an earlier sentence of the current class. The paper reports that the named heads alone reproduce the behaviour, and that cutting the connections shows about sixty percent of a class flip passes through the readers. Abstract: readers and key–value memory
The gate is an early-layer signal, not a head population. Duplicate-token heads register whether any label has appeared twice, and that information is pooled into a single direction in the residual stream at the query. That direction lowers the logit the readers assign to the attention sink at position zero. When no label repeats, the sink wins the softmax and the readers return nothing in particular — the null action. The null action follows from the softmax itself: attention has to go somewhere, and the sink is where these heads put the attention they do not spend on the slots. The gate is therefore a switch with a clear trigger (a repeated label) and a clear default (attend to the start of the prompt, favour no label). Introduction: the gate and the null action
Brakes are about two dozen heads that write against whichever label the model saw most recently. They are negative heads in the sense of earlier interpretability work: they suppress, rather than promote, a candidate. Removing them nearly triples the margin and leaves the model biased toward the most recent label. In the paper’s ablation numbers, knocking out the ninety reader heads together lowers the margin by 0.74 nats, while disabling the twenty-four brake heads raises it by 1.39 nats (plus or minus 0.22). A single reader head, by contrast, changes the margin by only a few hundredths of a nat. The brakes are doing real work: without them, recency — the pull of the last demonstration — would dominate the answer. Introduction and ablation results
One more quantitative detail explains why so many heads are involved. No single head contributes more than 0.2 nats of logit directly, so a 1.3-nat answer is a sum over at least seven heads, and a 1.3-nat change between two prompts needs at least four, since a head’s contribution can change sign. A single reader already separates the two classes in its attention pattern, so the model is not spreading the work because individual heads lack the signal. Individual heads lack output gain. The circuit is a population effect by construction, and any account that names one “classification head” would miss how the answer is actually assembled. The authors also account for the answer exactly: on each prompt, the contributions of all heads and MLPs to the answer logit add up to the model’s own logit to within 0.05 nats. Introduction: populations and logit accounting
How the causal evidence works
The paper’s method is worth spelling out, because it is what separates this account from a plausible story told over attention heatmaps. The authors build pairs of prompts that are identical token for token except in one span — a twin — and move activations from one member of the pair into the other, head by head, group by group, or position by position. Five kinds of twin recur: a class-flipped twin replaces one demonstration’s sentence with a sentence of the other class; a same-class twin replaces it with a different sentence of the same class and the same length, as a control whose answer should not change; a label exchange swaps foo and bar everywhere; an other-class query replaces the query sentence; and a unique-label rewrite replaces each repeated label with a fresh one. Because twins line up token for token, an activation taken from one prompt can be placed into the other at the same position, and the change in the answer shows how much of the difference between the twins that one activation carries. The authors call this a handoff. Setup: twin prompts and handoffs
Alongside handoffs they use three other operations. To knock out a head they mean-ablate it, replacing its output by its mean over the battery, which removes what the head writes without setting it to zero. To steer, they add a direction to the residual stream at the query arrow at the dose the model itself uses, and compare against a random direction of the same norm. To hold a component, they fix it at its intact value while a handoff runs upstream of it, which shows whether the upstream effect passes through that component. Every named head set is compared with random sets of the same size drawn from the same layers, every steering direction with a random direction of the same norm, and every set selected on one draw of prompts is confirmed on a fresh draw with a different seed. The numbers the paper leads with come from the fresh draw. Setup: interventions and controls
The prompt sets themselves are four batteries. The concept battery has six demonstrations, three per class, on sentence axes such as topic (animals against food), sentiment, language (English against Spanish) and question against statement, with invented-word labels (foo/bar, quil/zorp) and natural ones. The concept12 battery is the same with twelve demonstrations, six per class. The slotgate battery has four demonstrations and comes in token-identical pairs: in one member every label appears twice, in the other every label appears once, so the two differ only in whether labels repeat — the cleanest possible test of the gate. The manyclass battery has two to six classes with one or more demonstrations each and arbitrary single-token labels. Scoring uses the margin: the log-probability of the correct label minus that of the other label, each scored over its full token sequence. A margin of 2 nats means the model prefers the right answer by a factor of about seven. Setup: batteries and the margin
The models are Qwen3-4B-Base (36 layers, 32 query heads, 8 key–value groups, QK-norm), SmolLM3-3B-Base (36 layers, 16 heads, 4 groups) and Llama-3.2-3B (28 layers, 24 heads, 8 groups), with intermediate checkpoints of OLMo-2 1B and 7B used to study how the circuit emerges during training. All interventions are forward hooks on the HuggingFace implementations, run in bfloat16 on one H100. The computation is conserved across the three main models, the authors report, while which heads fill each role varies — the same algorithm, different staffing. Setup: models
A worked example: twelve delivery and refund requests
Take the oak/ash prompt from the opening of this article and make it concrete, using only the paper’s own numbers and the arithmetic of Equation 1. Suppose the prompt has twelve demonstrations, six delivery requests labelled oak and six refund requests labelled ash, followed by a new delivery question and an arrow. The writers have stored a delivery key at each oak slot and a refund key at each ash slot. At the query, the model computes a delivery code. One reader head, call it head R, distributes its attention across the prompt. Suppose its weights on the six matching oak slots are 0.11, 0.08, 0.06, 0.05, 0.04 and 0.03. Their sum — the matching mass m for this head — is 0.37. Suppose it also puts 0.20 on the first token (the sink), 0.05 on the six ash slots combined, and the remaining 0.38 on the rest of the prompt (the sentences themselves, the arrows, the query). Those four groups are exactly the groups Equation 1 fits: matching labels, other labels, the sink, and the rest.
Now add six more delivery examples, taking the prompt to eighteen demonstrations with twelve matching slots. If the head’s total attention to matching slots were free to grow, m might rise toward 0.6 or higher. The paper’s finding is that it does not: each head’s attention to the sink, and its total attention to the matching slots, are roughly fixed properties of the head, so adding matching slots divides a fixed budget among them. The twelve matching weights might become roughly 0.05, 0.04, 0.03, 0.03, 0.02, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01 and 0.01 — still summing to about 0.37, but spread thinner, with each individual slot mattering less. That is the mechanism behind the extrapolation failure in the table above: the twelve-example fit assumes the matching mass can keep growing with the number of matching slots, and at eighteen examples it overestimates for 92–94% of heads, with a median error of 0.13–0.15 attention mass. The arithmetic above is illustrative — it uses invented per-slot weights that sum to a plausible matching mass — but the fixed-budget claim and the error figures are the paper’s. Introduction: the fixed-budget surprise
The gate changes the picture in a different way. Suppose instead the twelve demonstrations use twelve distinct labels, one per sentence, so no label ever repeats. The duplicate detectors find nothing to register, the gate direction stays closed, and the readers’ attention goes to the sink. The matching mass m collapses toward zero — not because the writers failed to store keys, but because the read was never switched on. Conversely, a prompt with only two distinct labels repeated six times each opens the gate wide, and the readers can use the stored keys. That is a practical consequence a prompt designer can act on without any new experiment: repetition of labels is not just a convenience for the reader of the prompt, it is the trigger for the model’s own retrieval switch. And the brakes add a second practical consequence: if the last demonstration is a refund labelled ash and the query is a delivery, the brakes are actively writing against ash at the query, which helps the model resist answering with the most recent label. Ordering still matters — the brakes suppress recency bias, they do not erase it — but the mechanism gives a reason to put a representative example last rather than an outlier.
What transfers, and what does not
The paper tests the circuit beyond the three main models and the invented-label setup, and the transfer results are the most interesting part for anyone deciding how much to generalise from a 3–4B base model. A transformer trained from scratch grows the same parts, the authors report — and it grows the gate only when training penalises blind retrieval, which suggests the gate is a learned response to a training pressure, not an architectural inevitability. The same parts, with a causal gate, appear from 0.6B to 8B in one model family; across that range the brakes’ hold on word meaning rises with the flipped-label margin, the behaviour Wei et al. (2023) found only in large models. And the base model’s heads still carry retrieval after instruction tuning, so the circuit survives the step from base model to instruction-tuned model rather than being overwritten by it. Abstract: transfer and scaling
The circuit also transfers to semantic concepts. With the concept’s own words as labels, the same reader and brake types carry the part of the margin that follows the demonstrations, while the part that follows word meaning lies outside the circuit. That split is important: when labels have meanings of their own — positive and negative, say, rather than foo and bar — the model has two routes to the answer, the demonstrated mapping and the words’ prior meaning, and only the first runs through this circuit. A prompt designer who uses meaningful labels is therefore leaning on both routes at once, and a failure could come from either. The paper’s invented-label batteries isolate the demonstrated route by removing the meaning route entirely, which is why the results are clean — and why they should not be read as a complete account of few-shot learning with natural labels. Abstract: transfer to semantic concepts
The limits are stated in the paper itself. The account covers two-class label retrieval and function selection, on invented-word and natural labels, with up to twelve demonstrations, in three base models of three to four billion parameters. Instructions, long-form tasks and binding among many classes are outside its scope. The manyclass battery extends the setup to two to six classes, but the core quantitative results — the Equation 1 fit, the 127-of-140 and 124-of-125 head counts, the eighteen-example extrapolation failure — are for the few-shot sentence-classification setting the paper defines. A reader applying the fixed-budget lesson to a forty-example prompt, a chain-of-thought task, or a 70B model is extrapolating beyond the evidence, in the same way the twelve-example fit extrapolated beyond its own evidence. Introduction: scope
For a practitioner, the actionable summary is narrow and concrete. First, measure answers, not attention: the paper’s own advice, repeated in the table above, is to count predicted labels against an answer key at each candidate prompt length, because attention mass is not accuracy. Second, repeat labels deliberately: a repeated label is what opens the gate, so a prompt with all-unique labels is asking the model to retrieve from a memory it has not switched on. Third, do not assume more examples help monotonically: the fixed-budget finding gives a mechanism for diminishing — and eventually misleading — returns from adding matching demonstrations, and the 0.13–0.15 median error at eighteen examples is a measured warning, not a guess. Fourth, put the recency bias in its place: the brakes exist because the last demonstration pulls the answer toward itself, so the final example deserves the same care as the first. None of that requires running the paper’s interventions; it requires taking the paper’s numbers seriously and checking the answers on held-out queries, which is the one measurement any team can do with the model it already uses.