Natural language relationships are not one-dimensional in this way.
the companion book defined scaled dot-product attention as a function of three matrices derived from an input sequence :
with a single, shared set of learned projections. This single-head formulation has a structural limitation that has nothing to do with capacity in the parameter-counting sense and everything to do with what one softmax can represent. For a fixed query position , the attention weights form a single probability distribution over key positions , and the output is a single convex combination of value vectors. One head, one query vector, one similarity function, one distribution, one weighted average โ every kind of relationship the model might need to represent at position (which token is the syntactic subject, which token is the most recent noun, which token is three positions back, which token shares a coreference chain) has to be blended into that one distribution and that one averaged output.
Natural language relationships are not one-dimensional in this way. A pronounโs representation may simultaneously need information about its syntactic antecedent (typically nearby), its semantic referent (which may be many tokens back), and its own local position in the clause. Forcing all of that through a single softmax over a single learned similarity metric means the model has to find one compromise attention pattern that serves every relationship at once, which is exactly the representational bottleneck multi-head attention is designed to remove.
The fix, introduced alongside scaled dot-product attention itself (Vaswani et al., 2017), is to stop using one full-width projection and instead use independent, lower-dimensional projections, each producing its own query, key, and value matrices, each running its own scaled dot-product attention, each therefore free to learn its own similarity function and produce its own distribution over key positions. Concretely, the model dimension is split into heads of dimension
and each head operates entirely within its own -dimensional subspace of the representation. โSubspaceโ here is doing real work: head โs query and key projections, , map the full -dimensional token representation down into a -dimensional space specific to that head, and the dot-product similarity that drives head โs attention pattern is computed entirely within that subspace, independent of what any other headโs projections do with the same input. Two heads reading the same token representation can therefore extract and compare completely different projections of it โ one subspace might end up encoding something like relative token distance, another something closer to a semantic-role relationship โ without either headโs softmax having to compromise with the otherโs.
Crucially, this added representational flexibility is close to free in terms of raw compute, because splitting into pieces of size and running attention computations of width costs, in aggregate, almost exactly what one attention computation of width would have cost. The next section makes this precise for both parameters and FLOPs; the short version is that multi-head attention does not multiply cost by โ it redistributes a fixed budget across parallel, lower-dimensional computations. The number of heads is therefore best understood not as a knob that trades cost for quality, but as a knob that trades subspace width for subspace count at roughly fixed total cost: fewer, wider heads compute richer per-head similarity functions over fewer distinct relationship types; more, narrower heads compute cheaper per-head similarity functions over more distinct relationship types. Neither extreme is free โ a single head with recovers exactly the companion bookโs mechanism and its one-compromise-pattern limitation, while very large eventually starves each head of enough dimensions to represent a useful similarity function at all โ which is why is a tuned architectural hyperparameter rather than a quantity derived from first principles.
Published architectures make this tradeoff differently at different scales, and the numbers are worth having as concrete anchors. The original Transformer (Vaswani et al., 2017) used with , giving . GPT-2โs largest published configuration (Radford et al., 2019) uses with , again giving . GPT-3 (Brown et al., 2020) scales up to with , once more landing on . The recurrence of values clustered around 64โ128 across three orders of magnitude of is not a coincidence forced by the mathematics derived above โ nothing in the multi-head formalism requires to stay roughly fixed as grows โ but an empirical convention: practitioners have generally chosen to scale roughly in proportion to , keeping each headโs subspace width in a range that has been found to work well, rather than fixing and letting grow arbitrarily large or fixing at some other value. Treat this as a documented design convention, not a theorem; later chapters revisit the memory-bandwidth motivations (the companion bookโs treatment of multi-query and grouped-query attention) that push some modern architectures away from this convention specifically for the key/value projections.
Whether individual heads specialize into cleanly interpretable roles is an empirical question, not a guarantee of the architecture. It is a documented phenomenon: Vaswani et al. (2017) themselves illustrate, via attention-weight visualizations of their trained model, heads that appear to track distinct patterns โ some concentrating on immediate neighbors or fixed positional offsets, others attending across long distances to what look like syntactically or referentially related tokens. Subsequent work probing trained transformer encoders has repeatedly found similar structure: some heads with attention patterns that align closely with syntactic dependencies, others that behave close to positional or โlocal windowโ detectors, and others still that are harder to characterize with any single human-readable label. This should be read as an observed regularity in specific trained models on specific tasks, not as a proof that heads always specialize, that a given headโs role is stable across layers or training runs, or that the resulting attention weights constitute a faithful explanation of the modelโs computation โ attention weights show what a head averages over, not why the rest of the network uses that average, and the interpretability literature (returned to in the companion book) treats attention patterns as suggestive evidence rather than a complete causal account of model behavior.
Continue with the book
Explore the full treatment, worked examples, and exercises in LLMs Derived.
Companion article for LLMs Derived, published by Choral Software. Article text and original examples ยฉ 2026 Choral Software. All rights reserved.
