Attention map
Tap a word and see where it looks, with the attention arithmetic laid open.
What this lab shows
In a Transformer, each word asks every other word how much it matters to it. Here you see that question in miniature: short sentences, two attention heads and the arithmetic laid open, from the query Q and the key K to the softmax and the mix of the values V.
Attributes and matrices written by hand to show the mechanism. The arithmetic is that of attention; the numbers of a real model come from training.
How to use it
- Pick a sentence and tap a word in the left column.
- Switch between the meaning head and the position head and compare the links.
- Open the five steps, turn off the division by √dk and watch the weights get more extreme.
Illustrative dataThe attributes and matrices were written by hand to show the mechanism. The arithmetic (Q, K, V, softmax and weighted sum) is the real one; in a real model, the numbers come from training and have no names.
the cat drank the milk
Attention weights of «drank» (Head 1: meaning)
- the7%
- cat39%
- drank7%
- the7%
- milk39%
The verb «drank» splits its attention between who drank and what was drunk. Swap «milk» for «quickly» and watch the attention on the last word drop.
The lab could not load. The summary above still applies.
Books that use this lab
No published book uses this lab yet.