What are attention heads and QK/OV circuits?
Author: Mehdi Sadriu, independent educator. Last reviewed: 25 November 2026. How we check claims: methodology.
An attention head moves information between token positions. Elhage et al. (2021) split that job in two: the QK circuit decides where the head looks, and the OV circuit decides what it copies into the residual stream. The underlying function is still scaled dot-product attention from Vaswani et al. (2017).
In one paragraph. A head computes weights α = softmax(mask(QKᵀ / √d_k)) from queries and keys, then writes αV through the output map. QK is 'where'; OV is 'what'.
| THE | CAT | SAT | |
|---|---|---|---|
| Raw QKᵀ (query SAT) | 0.4 | 1.8 | −0.2 |
| Softmax weights | 0.18 | 0.73 | 0.09 |
Future tokens are masked to −∞ before softmax (not shown in this row, because SAT is last).
Weights always sum to 1. The output is 0.18·v_THE + 0.73·v_CAT + 0.09·v_SAT in this snapshot.
What is a head in plain language?
A head is a small specialist. For every word, it glances at other words, picks a mixture of them, and adds a note to the backpack. One head might mostly look at the previous word. Another might look at a name mentioned earlier. Many heads have no name a person would love.
What are Q, K, and V?
Three linear maps of the same residual vector: query ('what am I looking for?'), key ('what do I contain?'), value ('what should be copied if you look at me?'). Dot products of Q and K become scores; softmax turns scores into weights that sum to 1; those weights mix the V vectors.
What did the framework add?
Elhage et al. (2021) composed the maps into QK (low-rank bilinear score between two positions) and OV (the map from the attended residual to the write). That lets you ask 'this head copies the previous token's name' as a statement about OV, and 'it looks at the previous position' as a statement about QK. You still have to measure those maps in a trained model.
What is the math?
Attn(X) = softmax( (X W_Q)(X W_K)ᵀ / √d_k + mask ) (X W_V) W_O
The framework writes the score as a bilinear form xᵢᵀ W_QK xⱼ and the write as W_OV xⱼ. Multi-head attention concatenates h heads and mixes them with W_O (already folded into OV per head if you like).
Worked example
Query = SAT in THE CAT SAT. Suppose teaching scores are 0.4, 1.8, −0.2. Softmax ≈ 0.18, 0.73, 0.09. The head's output is a mixture that is mostly CAT's value. If OV maps CAT's residual toward the token cat, the unembedding will later see 'cat' more. That last 'if' is exactly what you would check with a logit-attribution or a patch, not with this teaching row.
Check your understanding
Five questions. Answers are in the disclosure under each item, so this page still works if JavaScript is off.
Further reading
- Attention Is All You Need — Vaswani et al. (2017). NeurIPS.
- A Mathematical Framework for Transformer Circuits — Elhage et al. (2021). Transformer Circuits (Anthropic).
- In-context Learning and Induction Heads — Olsson et al. (2022). Transformer Circuits (Anthropic).
- Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 Small — Wang et al. (2022). arXiv.