Multi-Head Attention (MHA) runs h attention operations in parallel, each on a lower-dimensional subspace, then concatenates the results and projects them back to d_model. The intuition: instead of one attention pass that has to capture all relational patterns at once, give the model h shorter "specialists" — different heads can learn different patterns.
head_i = Attention(Q · W_i^Q, K · W_i^K, V · W_i^V)
Concretely: pick h (typically 8, 12, 32, or 64). Set d_head = d_model / h (typically 64 or 128). Each head has its own W^Q_i, W^K_i, W^V_i of shape (d_model, d_head). Concatenate the h outputs of shape (seq_len, d_head) into one tensor of shape (seq_len, d_model). Apply a final output projection W_O of shape (d_model, d_model) to mix information across heads.
Why this matters
Different heads, observed in trained models, often specialize:
- Some heads attend only to the previous token ("position −1 head").
- Some attend to the same token across recent context ("induction heads").
- Some attend to syntactically related tokens (subject ↔ verb).
- Some attend nearly uniformly to capture semantic averaging.