Sam Babichenko

Reading notes / Attention and concepts

Tracing attention through feature pairs

Kamath et al., 2025; Luger et al., 2026

Scores and features
WQ,W_Q, WKW_Ka head's query and key maps
WQKW_{QK}WQ⊤WKW_Q^\top W_K, the head's bilinear form
iiquery position, where the head attends from
jjkey position, j≤ij\le i, where the head may attend to
hih_iresidual stream entering the head's layer at position ii
dheadd_{\rm head}head dimension; WQKW_{QK} has rank at most dheadd_{\rm head}
f,f, gga query-side feature and a key-side feature
af(i)a_f(i)activation of feature ff at position ii
vfv_ffeature vector of ff
bbbias of the crosscoder's reconstruction
εi\varepsilon_ipart of hih_i the features miss
cfgc_{fg}vf⊤WQKvgv_f^\top W_{QK}v_g, the head's weight between ff and gg
const(i)\mathrm{const}(i)score terms equal at every key position jj
TfgT_{fg}term af(i) ag(j) cfga_f(i)\,a_g(j)\,c_{fg} of one score
μf,\mu_f, νg\nu_gfactors of a rank-one TT, Tfg=μfνgT_{fg}=\mu_f\nu_g
Singular directions (Franco and Crovella)
h~i\tilde h_ihih_i with a 1 appended
Ω\OmegaWQKW_{QK} with the head's biases appended
σm,\sigma_m, um,u_m, wmw_msingular values and vectors, Ω=∑mσmumwm⊤\Omega=\sum_m\sigma_mu_mw_m^\top
Paper symbols
xxKamath et al. and Franco and Crovella write xx for the residual stream hh
pq,p_q, pkp_kKamath et al. write pqp_q and pkp_k for the positions ii and jj
epqe_{p_q}Kamath et al. write epqe_{p_q} for the error εi\varepsilon_i
σk,\sigma_k, uk,u_k, vkv_kFranco and Crovella index singular directions by kk and write vkv_k for wmw_m

Context. An attention head decides where to look by scoring the current token's query against every earlier token's key. Both vectors are linear maps of their tokens' the vector carried at each token from layer to layer; every attention and MLP block reads it and adds its output to it. Nothing in that layout names a concept, yet heads often retrieve conceptual targets: the name belonging to this aunt, the right multiple-choice option, or the city that does not belong to a country. Anthropic's circuit-tracing method builds graphs whose nodes are sparse features at token positions and whose edges are the linear effect of one feature on another, computed with every attention pattern held at its value on the prompt from sparse features, freezing every attention pattern so each edge stays linear. That graph can show that the model copied a name from an earlier token, but not why the head looked there.

Kamath et al. (2025) fill that gap by expanding the attention score itself. The score is bilinear in the two residual-stream vectors. Writing each vector as a sum of sparse features splits the score exactly into one term per query-key feature pair, plus bias and error terms. In every prompt they trace in Claude 3.5 Haiku, the largest terms are a few interpretable feature pairs. To test each account, they steer a named feature only inside the query or key input of the relevant heads. That changes where those heads attend while leaving what they copy untouched, and the model's output shifts as predicted.

The strongest causal test comes from a November 2025 follow-up (Goel et al., 2025). They add a statement of harmful intent before each of 129 two-option questions, a setup they call harm pressure. Haiku's accuracy falls from 100% to 48.1%. A query-side "refuse and redirect" feature meets key-side "harm detection" features with a negative term, pulling the answer-fetching heads away from the correct option. Negative steering on that single feature restores accuracy to 93%. Steering it only on the query side of a subset of middle-layer heads produces the same result.

Setting. Fix one head with query and key maps WQW_Q and WKW_K, and write WQK=WQ⊤WKW_{QK}=W_Q^\top W_K. Let hih_i be the residual stream entering the head's layer at query position ii, and hjh_j at key position j≤ij\le i. Before the softmax over jj, the head scores jj from ii by hi⊤WQKhjh_i^\top W_{QK}h_j divided by the square root of the the width of a head's queries and keys, so that WQKW_{QK} has rank at most dheadd_{\rm head}. To trace that score back to concepts, the authors expand each residual-stream vector with a weakly causal crosscoder:hi=∑faf(i) vf+b+εi.h_i=\sum_f a_f(i)\,v_f+b+\varepsilon_i.Here af(i)≥0a_f(i)\ge0 is the activation of feature ff at position ii, vfv_f is its feature vector, bb is a reconstruction bias, and εi\varepsilon_i is the error the features miss. Each feature carries a text description of the contexts where it fires, which the papers use to name it.

Substituting this expansion on both sides of the score and multiplying out gives the feature-pair split. Write cfg=vf⊤WQKvgc_{fg}=v_f^\top W_{QK}v_g for the head's interaction weight between query feature ff and key feature gg; it is fixed by the head and crosscoder weights, independent of the prompt. Thenhi⊤WQKhj=∑f,gaf(i) ag(j) cfg+∑gag(j) b⊤WQKvg+error terms+const(i).\begin{aligned}&h_i^\top W_{QK}h_j\\&=\sum_{f,g}a_f(i)\,a_g(j)\,c_{fg}\\&\quad+\sum_g a_g(j)\,b^\top W_{QK}v_g\\&\quad+\text{error terms}+\mathrm{const}(i).\end{aligned}The first sum has one term for each pair of a feature active at ii and a feature active at jj. The second pairs the query-side bias with key features, capturing a standing preference of the head for keys carrying them. The error terms are those containing εj\varepsilon_j, or εi\varepsilon_i paired with a key feature. Every remaining term, including query features meeting the key-side bias, depends only on ii. Together they add the same shift const(i)\mathrm{const}(i) to every key position jj in the row and leave the softmax unchanged. Ranked by magnitude, the key-dependent terms form the the terms af(i) ag(j) cfga_f(i)\,a_g(j)\,c_{fg}, with the bias and error terms, that add up to one head's score of key position jj from query position ii, listed by size of the score.

Before computing QK attributions on an attribution-graph edge, one must identify which heads carry that edge. Splitting the attention-mediated part of the edge across heads gives one the part of an attribution-graph edge between two features at different positions that one head carries: the source feature passed through the head's value and output maps, read along the target feature, scaled by both activations and by the head's attention between the two positions per head. This requires attribution graphs that connect features only in adjacent layers, because paths through heads multiply with every layer an edge spans.

On a classic the completion [A][B] … [A] → [B]: a token A that was followed by B earlier in the context is followed by B again prompt, "I always loved visiting Aunt Sally. Whenever I was feeling sad, Aunt", Claude 3.5 Haiku completes with "Sally". The top-loading heads on the edge from the first "Sally" to the output look back using query features for "Aunt" or family titles at the second "Aunt". On "Sally", those queries meet two kinds of key feature. One is a general name feature (any name, or "Sally" itself); the other is "the name of an aunt or uncle", which fires on names following "Aunt" or "Uncle". The heads thus combine a search for any name with a search for a relative's name.

Steering confirms that this key feature drives where the heads look. The authors selected the top-loading heads on the edge, about 3% to 10% of all heads. Inside those heads' query-key computation alone, they added a multiple of a feature's vector to the activations at chosen positions, here only in the input to chosen heads' query or key map; a negative multiple turns the feature down the "name of an aunt or uncle" features at the first "Sally". Removing those features from the key side eliminates the induction completion completely, leaving generic aunt names. Freezing every other head's attention pattern cuts the number of steered heads needed for the same drop by more than half. The authors suggest this reflects the the finding that when one component of a language model is ablated, later components change their behavior and partly make up for it (McGrath et al., 2023).

A single score can also sum two independent feature pairs, which requires a bilinear form of rank at least 2. Take "I always loved visiting Aunt Mary Sue. Whenever I was feeling sad, Aunt Mary", which Haiku completes with "Sue". Two separate pairs contribute to the score from the second "Mary" to "Sue". Query "Mary" features meet key "token after Mary" features, while "name of an aunt or uncle" features meet each other across the two sides. The cross terms between "Mary" and "name of an aunt or uncle" are weak. Write Tfg=af(i) ag(j) cfgT_{fg}=a_f(i)\,a_g(j)\,c_{fg} for the matrix of QK attribution terms. If TT had rank one, its entries would factor as Tfg=μfνgT_{fg}=\mu_f\nu_g, forcingT12 T21=μ1ν2 μ2ν1=T11 T22.T_{12}\,T_{21}=\mu_1\nu_2\,\mu_2\nu_1=T_{11}\,T_{22}.Two strong matched pairs would then require at least one strong cross term. Because Tfg=af(i) vf⊤WQKvg ag(j)T_{fg}=a_f(i)\,v_f^\top W_{QK}v_g\,a_g(j) factors through WQKW_{QK}, the rank of TT is at most that of WQKW_{QK}. The head must therefore use at least two dimensions of its query-key form for this one score.

In multiple-choice questions, QK attribution isolates the heads that pick the right letter. Kamath et al. test a question about the year World War II ended, answered "B" for 1945. They find a head that, in multiple-choice questions, attends from the answer position to the option carrying "correct answer" features and copies its letter (Kamath et al., 2025; Lieberum et al., 2023) whose "about to give an answer" query features meet key-side "correct answer" features on option B's tokens. Turning those key features down on option B while adding them to option A or C makes Haiku output that letter instead.

Those same answer selection heads explain why harm pressure breaks Haiku's accuracy. Under harm pressure, the "correct answer" feature still fires more strongly on the right option than on the wrong one in all but 7% of the questions. The model still represents which option is right. Yet the answer selection heads now give both options similar attention, often slightly more to the wrong one, so the answer is lost inside the attention step itself. Their QK attributions keep the usual positive pair, "need a multiple-choice answer" queries meeting "correct answer" keys, and add a negative one. A query-side "refuse and redirect" feature fires when the model declines a harmful request. In one answer selection head, it interacts with key-side "harm detection" at 3.4 standard deviations below the mean of 1,000 random key-query pairs. Its interaction with "correct answer" is negligible. Key-side steering points the same way. Turning harm detection up on the wrong option restores accuracy to 81%, though that requires steering at more and earlier layers.

Whereas Kamath et al. trace chosen prompts, HeadVis (Luger et al., 2026) profiles individual heads across the full data distribution. It ranks heads by summary metrics, displays the dataset examples where each head attends most, and computes both QK attributions and the head's output split the same way, into terms for a feature at the attended token, read through the head's value and output maps, and a feature that the output writes at the query token. An a head's average attention on the query-key token pairs of a standard dataset that fit the literal pattern [A][B] … [A] → [B], from the second A to the first B locates induction heads throughout Claude 3.5 Haiku. Early-layer heads often copy literally, while later ones match on abstract features instead of exact tokens. In a poem, the second token of "gleam" attends to the newline after "dream" even though "gleam" has not appeared before. The top QK term pairs a query feature for "-ea sound at the end of a line" with a key feature for "newline after an ee sound". The top OV term is the literal induction pair, "current token is a newline" to "say a newline". The fuzziness sits entirely in the QK match.

HeadVis's clearest quantitative case is a mid-layer head that attends mostly between places, people, and sports teams. Dataset examples are hard to interpret, so the authors probe the rule with synthetic sentences. From "Europe", the head attends to "Zambia", the only non-European country in a list. The authors also test 185 sentences of the form "{five cities} are all cities in {country}", each naming four local cities and one foreign city. In 98% of them, the country token attends more to the foreign city than to any of its own. The rule sits directly in the head's query-key geometry. Take the head's query on "The country {X}" and its keys on "The city {Y} is well known", subtracting the mean over countries or cities from each. A country's query has mean cosine similarity −0.47-0.47 with its own cities' keys and +0.01+0.01 with foreign cities' keys. In the residual stream, a country and its own cities have mean cosine similarity +0.17+0.17. The query and key maps invert a relation the residual stream already carries, so belonging to the country lowers the score. Averaging the keys of each country's ten cities first, as the grid below does, sharpens the separation. Own-country cosines then run from −0.69-0.69 to −0.88-0.88, except −0.34-0.34 for the United States, averaging about −0.78-0.78.

A head's query-key score also concentrates in a few terms without any sparse dictionary. Franco and Crovella (2024) append each head's biases to WQKW_{QK} to form a matrix Ω\Omega acting on h~i\tilde h_i, the vector hih_i with a 1 appended. Its singular value decomposition Ω=∑mσmumwm⊤\Omega=\sum_m\sigma_m u_m w_m^\top splits the score into one term per singular direction:h~i⊤Ω h~j=∑mσm (um⊤h~i)(wm⊤h~j).\tilde h_i^\top\Omega\,\tilde h_j=\sum_m\sigma_m\,\big(u_m^\top\tilde h_i\big)\big(w_m^\top\tilde h_j\big).They test GPT-2 small on 256 prompts of the completing sentences such as "When Mary and John went to the store, John gave a drink to" with the name that is not repeated, Mary; its circuit in GPT-2 small was mapped by Wang et al. (2022). When a head puts more than half its attention on one token, it typically gets that score from 20 or fewer of its 64 terms, often 2 or 3. Measuring upstream heads' outputs along only those kept directions singles out the known circuit heads, while the full residual stream gives high scores to a large set of heads. Removing an upstream head's output along those directions, fewer than about 20 of 768 dimensions, lowers the logit difference between the right and repeated names for almost every traced edge.

Two other lines of work on GPT-2 small decompose query-key scores with sparse dictionaries instead of SVD. Kissane et al. (2024) study a name-mover head (9.9) in the same circuit, pairing attention-output SAE features on the query side with residual-stream SAE features on the key side. Over 100 prompts, eight interpretable pairs explain 62% of its score variance, against about 15% for all entries involving an error term. Wynroe and Sharkey (2024) instead train paired query and key dictionaries directly to reproduce the attention pattern, giving a weight for every query-key feature pair in each head. A 2026 dashboard post extends that method to all 12 layers of GPT-2 small (nuppal, 2026).

The HeadVis authors name rank as an obstacle that may remain even with the right units. They suspect that a sum of rank-one heads cannot approximate every real head, so attention units likely need rank above one. How far above is open, perhaps 2 to 6 for most units, or close to dheadd_{\rm head} for some. sparse autoencoders trained on an attention layer's output (Kissane et al., 2024), replacements for an attention layer whose features are read at a source token, moved by a learned mix of the layer's own attention patterns, and decoded at the destination (Jermyn et al., 2025), and Lorsa (He et al., 2025) all split the OV side into rank-one directions while leaving the QK side high-rank. Lorsa uses thousands of heads that each write a single direction, yet cutting their query-key dimension below the original head's 64 in Pythia-160M degrades the fit severely.

For any edge of an attribution graph, head loadings identify the heads that carry it and QK attributions isolate the feature pairs behind their scores. A named feature can then be steered inside the query or key input of those heads alone. HeadVis provides an open-source front end and a specification for the two back ends a user supplies, plus a hosted version covering every head of Gemma 3 1B. The workflow can therefore run on an open model, though typing in new sentences is left out of the release.

The steering tests provide clean causal evidence because each edits only the scores of the heads named by the account. The harm-pressure follow-up adds scale and a statistical baseline, testing 129 questions and comparing a key pair against random pairs. Franco and Crovella likewise control their singular-direction edits against random directions.

The remaining accounts are narrower. Kamath et al.'s other case studies each rest on one prompt in closed Claude 3.5 Haiku, without random-feature controls or counts over prompts. No source tests whether the few named pairs predict where a head attends on held-out text. Even the harm-pressure account is incomplete. Turning harm detection down on the right option does not reliably undo the drop, and error-term interactions with "refuse and redirect" remain unworked out. Across papers, accounts pick the largest QK terms by inspection and rely on unchecked feature descriptions. HeadVis tests its heads only by changing input text. Its same-set account is partial, because some place examples show no odd one out and others are not about places at all. On open models, the query-key work sits on GPT-2 small. There, Franco and Crovella recover the known circuit with precision 0.52 and recall 0.69, while Wynroe and Sharkey and the 2026 dashboard judge single pairs only inside their reconstructions.

Terms

QK attribution
one head's score split into terms af(i)ag(j)cfga_f(i)a_g(j)c_{fg}, one per query-key feature pair, plus bias and error terms
Head loading
the part of an attribution-graph edge carried by one head
Terms constant in the key
the same at every key position, so the softmax ignores them; the query bias meeting key features is not one of them
Rank at least 2
two strong matched pairs with weak cross terms; a rank-one TT has T12T21=T11T22T_{12}T_{21}=T_{11}T_{22}
Fuzzy induction
induction on a matched feature of an earlier token; the match is in QK, the copy in OV is literal
Harm pressure
harm detection keys meet a refuse-and-redirect query with a negative term; turning the query feature down restores accuracy from 48.1% to 93%
Same-set suppression
a country's query is anti-aligned with its own cities' keys (cosine -0.47) though aligned in the residual stream (+0.17)
Orthogonal slice
one term σmumwm⊤\sigma_mu_mw_m^\top of the head's form; a firing head's score typically uses 20 or fewer of 64 (Franco and Crovella)
Bilinear sparse dictionaries
query and key dictionaries trained to reproduce the attention pattern, giving a weight for every feature pair in every head (Wynroe and Sharkey)
High-rank obstacle
decompositions split OV into rank-one directions but keep QK at full head dimension

Sources