AI Research Scientist · Attention Mechanisms & Kernels
Multi-head attention design
Multi-head attention design
Multi-head attention
Multi-head attention splits the input into heads, each with its own learned query, key, and value projection matrices, so every head can compute attention independently before the results are combined.Split, Attend, Concatenate, Project
- 1SplitThe input is projected times with separate matrices, giving each head its own slice of the same tokens.
- 2AttendEach head runs scaled dot-product attention independently on its own Q, K, V, yielding one output vector per token.
- 3ConcatenateAll heads’ per-token outputs are concatenated into a single long vector.
- 4ProjectAn output matrix projects that vector back to , merging the heads into one representation.
- 1Head A’s scores peak 1-2 positions away.WhyIts own bias dot products toward small gaps.
- 2Head B’s scores peak on token 1 for every query.WhyDifferent let it learn a long-range pattern instead.
- 3Both heads’ outputs are concatenated, then projected by .WhyThis merges the local and long-range views into one vector.
Recall check from the same lesson
In a multi-head attention layer with d_model = 512 split into 8 heads, each producing a 64-dimensional output, the per-head outputs are concatenated into a 512-dimensional vector before being multiplied by the output projection matrix $W_O$.
Review the explanation
Answer: True. 512/8=64 per head matches the per-head output dimension, and concatenating 8 vectors of dimension 64 correctly reconstructs a 512-dimensional vector, exactly the mechanical order taught: split, attend per head, concatenate, then project via $W_O$.
Sources
One sitting · 20–30 minutes
A focused session on your AI Research Scientist interview
LearnBench starts from what you already know — skip what you have, master what you’re missing.
Start now