liveBook · Manning

Multi-head attention

As explained in Transfer Learning for Natural Language Processing

Multihead attention is an attention mechanism that computes multiple representations of relationships within an input sequence.

Multi-head attention refines self-attention into a multidimensional form. In a transformer, self-attention learns dependencies between parts of the same input sequence; multi-head attention can improve performance. section 7.1

Reading an attention visualization

In a visualization of pretrained BERT, the token “cells” is associated with “it” and “boring.” Different columns show the shading for each head. section 7.1.2 section 7.1

Figure 7.3 (Duplicated) Self-attention visualization in the final encoding layer of the pretrained uncased BERT model for our example sentence. It reveals that “cells” is associated with “it” and “boring.” Note that this is a multihead view, with the shadings in each single column representing each head.
07_04_07_03_duplicated

Inspect the multi-head view to compare attention shading across heads. section 7.1

How Transfer Learning for Natural Language Processing covers it

How deep it goes
Defines multi-head attention as a refinement of self-attention and visualizes its heads, without detailing their implementation.
Examples
Visualizes BERT attention in which “cells” is associated with “it” and “boring.”
What you can do after
Evaluate/understand attention visualizations by comparing shading across heads.
How it connects
Connects multi-head attention to self-attention, transformers, BERT, and attention visualization.

Also explained in

Compare how 15 books explain multi-head attention →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transfer Learning for Natural Language Processing. The section links point to the parts of the book it draws on.