LLM·

A Circuit for In-Context Learning — gated associative lookup — What does it mean?

The news. On November 3, 2026, Andrew Gao and William Gao (Stanford) posted A Circuit for In-Context Learning (arXiv:2611.05344), a 38-page paper with 22 figures. It traces few-shot sentence classification with arbitrary labels through three base models, Qwen3-4B, SmolLM3-3B and Llama-3.2-3B. Read the paper →

Picture the prompt as a coat-check room. Each demonstration, such as The soup was cold and the waiter rude -> bar, ends in a label token, and that token is a hook on the rack. Its residual stream already says which label it is. As the model reads the sentence before the hook, about twenty middle-layer attention heads clip a tag onto it: the class of that sentence. The hook is now a slot in a key–value memory. The key is the class of the preceding sentence, and the value is the identity of the label.

At the query, I would not go back to that place ->, the model first works out the class of the new sentence. Then about ninety upper-layer heads, the attendants, compare that class with the tag on every hook and copy out the label whose tag matches. This is ordinary attention, the query-against-keys scoring you may know, with one twist: the query is a class, and the keys sit on label tokens. That is why the authors describe the readers as induction heads keyed on a class.

Two details stop this from being a plain lookup. First, the lookup is gated. Early-layer duplicate-token heads register whether any label has appeared twice, and that is pooled into one direction in the residual stream at the query. The direction lowers the logit the readers give to the attention sink at position zero. With no repeated label the sink wins the softmax and the readers return nothing in particular. The paper calls this the null action. Nobody had to add it: softmax weights add up to one, so attention has to go somewhere.

Second, a population of about two dozen brake heads writes against whichever label the model saw most recently. Removing them nearly triples the margin but leaves the model biased toward the most recent label, so the brakes are what keep recency from deciding the answer.

How do the authors know it is causal and not just correlated? They build prompt pairs that are identical token for token except in one span, then move activations from one prompt to the other, head by head and group by group. They ablate heads and compare against random heads from the same layers, and they steer the residual stream along directions at the strength the model itself uses, compared with random directions of the same norm. Cutting the connections shows that sixty percent of a class flip passes through the readers, and that a few amplified readers cannot replace the rest. A softmax model of the readout with two constants per head, fit on one prompt distribution, also predicts another.

Here is the gate in numbers. This is a toy calculation (illustrative), not a figure from the paper. Take 12 demonstration slots, of which 6 match the query's class and get a logit of +2, while the other 6 sit at 0. Give the attention sink a logit of 6 with the gate shut and 0 with the gate open. Gate shut: the weights are e6 ≈ 403 for the sink, 6 × e2 ≈ 44 for the matches and 6 for the rest, so the total is about 454 and the sink takes 88.9% while the matching slots get only 9.8%. Gate open: the sink weighs 1, the total is about 51, and the sink drops to 1.9%. The matching slots go from 9.8% to 86.4% of the attention, with nothing else changed. That is the whole job of the gate: it is a switch on a normal softmax, not a separate module.

PartWhereHow manyWhat it does
Writer headsMiddle layersAbout twenty (paper §1)Write the class of the preceding sentence onto the label token as its key
Reader headsUpper layersAbout ninety (paper §1)Match the query's class against the keys and copy out the matching label
Repeat gateEarly layersDuplicate-token heads pooled into one direction (paper §1)Signals that a label has repeated and lowers the sink's logit
Brake headsNot broken out hereAbout two dozen (paper §1)Write against the most recently seen label to cancel recency bias

The claim is narrow, and the paper is careful about it. It covers two-class label retrieval and function selection, with up to twelve demonstrations, in three base models of 3–4B parameters. Instructions, long-form tasks and binding among many classes are outside its scope. Which heads fill each role varies from model to model, but the computation is conserved. A transformer trained from scratch grows the same parts (the gate only when retrieval is penalised), the same parts appear from 0.6B to 8B in the Qwen3 family, and the base model's heads still carry retrieval after instruction tuning. With natural-word labels, the circuit carries only the part of the margin that follows the demonstrations. The part that follows word meaning lies outside it.

Goes deeper in: LLM Internals → Self-Attention → Multi-Head Attention

Related explainers

Frequently Asked Questions

Check what you knowMap your AI & GPU knowledge across every track — free, role-based