Why do Transformers use multi-head attention instead of a single large attention head?
Last updated
Multi-head attention lets each position attend in several different ways at once, at roughly the same cost as one full-width head. A single head produces only one softmax distribution per query, so it must average all the relationships it cares about into one weighting.
A single softmax is a bottleneck:
Each query gets one weighted average over values. If a token needs both its syntactic head and its previous token, one head blurs them together.
The original paper notes that averaging inhibits attending to different representation subspaces.
Heads work in different subspaces:
Each head has its own
W_Q, W_K, W_Vprojecting into ad_model/hspace.Different heads can therefore define different notions of similarity (position, syntax, coreference, copying).
It costs about the same: Splitting
d_modelacrosshheads keeps parameters and matmul FLOPs essentially unchanged. You get more attention patterns for free.Ensemble-like robustness: multiple heads give redundancy and more stable training.
Caveats:
Returns diminish. Many heads can be pruned after training with little loss (Michel et al., 2019).
With too many heads,
d_kgets so small that each head's expressiveness (rank) is limited.