Multi-Head Attention
P10.attention.03 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Scaled Dot-Product Attention
Where next?
Later in Attention
This module unlocks
Go up a level
P10.attention.03 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Scaled Dot-Product Attention
Later in Attention
This module unlocks
Go up a level
A single attention pass produces only one weight pattern per sentence, so it has to squeeze grammar, meaning and position into that one pattern at once. A careful reader tracks these threads separately, and the Transformer gains the same faculty by running several smaller attention heads in parallel, each free to specialise in its own kind of relationship. Here we see how the heads divide the projection weights without ever splitting the input, and how a final learned projection recombines their separate readings into one representation.
Why it matters — One head averages all relationship types into one pattern; separate heads are free to specialise — BERT-base uses 12, GPT-3 uses 96.
Reference: Vaswani et al. 2017, §3.2.2
Reads /api/attention/mha/pipeline — loading
Computing…
For several heads over a three-layer stack on your corpus, open the attention demo.
Self-check
In multi-head attention, is the input matrix X split across heads?
Self-check
If d_model = 16 and num_heads = 4, what is d_k?
Self-check
What would be lost without the final W_O projection?
Practise this lesson's 3 self-checks
One per screen: you reveal each answer and mark it yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...