What is the purpose of the output projection matrix after concatenating attention heads?

Last updated 22 November 2026

  • The output projection W_O mixes head outputs: concatenation only stacks them, while W_O makes each output dimension a learned combination of all heads (equivalently, a sum of per-head projections).

  • It maps the result back to d_model width so the residual add x + MHA(x) works, and decides where in the shared residual space each head writes.

  • Cost: d_model² parameters, about a quarter of the attention layer's weights.

  • https://arxiv.org/html/2603.08343v1
  • https://medium.com/@smohammedzubair0/multi-head-attention-in-transformers-explained-architecture-mathematics-and-implementation-33a64e4d4891
  • https://www.transformer101.com/multi-head-attention
All Transformers interview questions