liveBook · Manning

Multi-head attention

As explained in Machine Learning Algorithms in Depth

Multihead attention runs multiple attention mechanisms in parallel and combines their output representations.

Multihead attention runs several attention mechanisms in parallel, producing independent output heads that are concatenated and transformed through a dense layer. This gives a transformer multiple ways to interpret the same input. section 11.3

Within transformer models, multihead attention connects to:

  • Self-attention, where the model attends to elements within a sequence. section 11.3
  • Encoder–decoder attention, where target queries attend to source keys and values during translation. section 11.3
  • Positional encodings, normalization, dense layers, and residual connections surrounding the attention mechanism. section 11.3

Transformer text classification

A transformer classifier uses a Keras MultiHeadAttention layer alongside embeddings, pooling, normalization, dense layers, and training callbacks. section 11.3

Figure 11.11 Multihead attention
sidebar figure

Use the multihead-attention figure to inspect how parallel heads are combined. section 11.3

How Machine Learning Algorithms in Depth covers it

How deep it goes
Defines parallel heads, concatenation, and dense transformation, but does not derive attention equations or head computations.
Examples
Illustrates translation attention, transformer architecture, multihead-attention structure, and Keras text classification.
What you can do after
Apply multihead attention through Keras in a transformer text classifier.
How it connects
Connects self-attention with positional encodings, normalization, residual connections, dense layers, and encoder–decoder models.

Also explained in

Compare how 14 books explain multi-head attention →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.