techtree / Attention
Multi-head attention
Run several small attentions side by side and combine them.
Transcript
In one attention, each token gets one set of weights, so it blends in one way. But a word relates to the others in more than one way.
Here, draws looks to robot, to find who is drawing. It also looks to circles, to find what is drawn.
So the model runs several attentions side by side. Each one is called a head. Each head has its own query, key, and value matrices, so each can look for something different.
The heads work with shorter vectors, so together they cost about as much as one big attention.
Each head gives each token a short new vector. Set them end to end, into one long vector. Then one more matrix mixes them together.
Real models use a dozen heads or more. Several ways of looking, combined into one vector.
Needs
- Self-attention video
Each token's output is a weighted average of the value vectors. - Matrix times vector video
Each output entry is a dot product of one row with the vector.
Leads to
- The transformer block video
Attention then MLP, each wrapped in normalization and a residual.