An attention head is one individual attention unit inside a transformer layer, with its own learned query, key and value projections. A layer contains many heads running in parallel, together forming multi-head attention. Each head computes its own pattern of which tokens should attend to which, and contributes part of the layer’s output.
Key takeaways
- A head is the smallest unit of attention in a transformer.
- Heads within a layer are independent during attention, then combined.
- Some heads take on recognisable roles; many are hard to interpret.
- Research has shown many heads can be pruned with little performance loss.
- Heads are a central object of study in AI interpretability.
An attention head explained in simple terms
If a transformer layer is a team reading a document, each head is one team member with a specific habit. One always checks who “it” refers to. One notices repeated phrases. One watches for the main verb. None of them was told to do this; each developed its habit during training because it reduced error.
What a single head does
- Projects every token into its own query, key and value vectors, usually of a smaller dimension such as 64 or 128.
- Scores every query against every key.
- Applies scaling, any masking, then softmax.
- Outputs a weighted mix of values for each position.
Its output is concatenated with the other heads’ outputs and passed through the layer’s output projection.
Roles heads can take on
| Observed role | What the head does |
|---|---|
| Previous-token head | Attends mainly to the token just before |
| Positional head | Focuses on fixed offsets or the first token |
| Syntactic head | Links subjects to verbs, or nouns to their modifiers |
| Coreference head | Connects pronouns to earlier nouns |
| Induction head | Finds an earlier occurrence of the current token and copies what followed it |
| Rare-token head | Attends to unusual or distinctive words |
Induction heads, described in interpretability research by Anthropic in 2022, are thought to play a part in in-context learning: copying patterns from earlier in the prompt.
A worked example
Prompt: “Riya works at NeerSoft. Riya’s role is”. A previous-token head helps carry local grammar. An induction head spots that “Riya” appeared before, looks at what followed it then, and raises the probability of related content. The combination of many heads across many layers produces a coherent continuation.
Attention sinks
Researchers have found that many heads place large attention weight on the first token, even when it carries little meaning. This “attention sink” behaviour appears to act as a default place to send attention when a head finds nothing relevant, and it matters when designing long-context and streaming systems.
Head pruning
A 2019 study titled “Are Sixteen Heads Really Better than One?” found that many heads could be removed after training with only small drops in performance. Pruning heads can speed up inference, though the effect varies by model and task.
Limitations
- Attention weights show where a head looks, not why the model answered as it did.
- Head roles are often mixed rather than clean and separable.
- Findings from one model do not always transfer to another.
