What is Multi-head attention?
In Turkish: Çok başlı dikkat · Topic: Models and training
A way of running the attention computation in several parallel heads, each looking at the input from a different angle. The results are then combined into a single output.
How does it work?
The input vectors pass through query, key and value transformations that are learned separately for each head. Each head performs its own attention computation independently and at the same time. The head outputs are then concatenated and mapped to a single representation by a linear layer. Because the heads work in smaller dimensions, the total cost stays close to that of one large head. During training, what each head focuses on is determined on its own.
Why does it matter?
A single attention computation struggles to capture a word's grammatical, semantic and positional relationships all at once. Multiple heads give the model the flexibility to track these relationships separately. As a standard part of the Transformer, it appears in most large language models, and variants such as GQA modify it to cut memory cost.
Example
In a sentence, one head might focus on the link between a verb and its subject while another focuses on an adjective and its noun, although what heads attend to cannot always be interpreted clearly.
FAQ
How many heads does a model have?
It depends on model size. Small models may have a handful of heads and larger ones dozens; the number is an architectural design choice.
Does each head learn a different task?
The division of labor is not clear-cut. Some heads have been observed to capture interpretable patterns, but not all do, and removing some heads can barely affect the model.