4/42
Part 1 of 6 · Why headsLearn

Several heads, each with its own softmax

Each head is a whole attention function of its own.

One token through H headsInteractive
x, one token = C numbers.

So run several attention functions side by side. Each head projects the full input into its own queries, keys and values, each d=C/Hd = C / H wide. Then it runs its own softmax.

Their outputs sit in separate channels until a final projection mixes them.

The paper writes it like this:

headh=Attention(XWQ(h), XWK(h), XWV(h))MultiHead(X)=Concat(head1,…,headH) WO\begin{aligned} \text{head}_h &= \text{Attention}\big(X W_Q^{(h)},\ X W_K^{(h)},\ X W_V^{(h)}\big) \\ \text{MultiHead}(X) &= \text{Concat}(\text{head}_1, \dots, \text{head}_H)\, W_O \end{aligned}

In words:

  • XX is the input, one row of CC numbers per token.
  • WQ(h)W_Q^{(h)}, WK(h)W_K^{(h)} and WV(h)W_V^{(h)} are head hh's own query, key and value projections, each C×dC \times d.
  • Concat\text{Concat} puts the HH head outputs side by side, and WOW_O is the output projection, C×CC \times C.