Multi-head attention

Multi-head attention is a key component of the transformer architecture, running several attention mechanisms in parallel. Instead of a single computation trying to capture all the relationships in the data, the input queries, keys and values are first split and linearly projected separately for each “head”. Each head then performs the attention computation independently, which lets it specialise in a different type of relationship or semantic feature in the data. The outputs of all the heads are finally concatenated and jointly transformed into the final output, giving the model a richer, more comprehensive representation.


Imagine trying to understand a complicated sentence. Instead of reading it just once, you call in a small team of experts to help. One expert focuses on the grammatical structure, the second looks for who is doing what in the sentence, and the third concentrates on the overall topic. Multi-head attention works exactly like this team. The model has several “heads”, and each of them looks at the input data from a slightly different angle, hunting for a different kind of information. In the end all these different views are brought together, allowing the model a far deeper and more comprehensive understanding than if it had looked at the sentence in only one way.

Is this article useful to you and are you citing it? Copy the citation