What it shows
In a transformer every token decides, head by head, how much to take from every other token. Those weights are a softmax per query, so each row adds up to one, and for a sentence of n tokens they fill an n × n grid. Drawing it shows what a head pays attention to: the previous word, a separator, the noun a pronoun refers to. Text generators hide later tokens, which makes the map triangular.
How to read it
- Row
- The query token: the one gathering information.
- Column
- The key token: the one being read from.
- Bright cell
- A large share of that row’s attention. Each row adds up to 100%.
- Diagonal stripe
- A positional head: each token looks at itself or a neighbour.
- Bright column
- A token everyone looks at, often a separator used as a resting place.
What it does not tell you
Attention weight is not importance: a head can attend strongly to a token and pass on almost nothing, and studies have found attention maps that can be changed without changing the answer. One head in one layer is a small part of the model; real models have dozens of heads per layer. The map shows where information could flow, not what was used.
Exploring what transformer heads do, finding positional or syntactic heads, debugging tokenization, and illustrating how self-attention works.
In WeightSpace
Sixteen models in WeightSpace contain attention, among them the emotion, retrieval and question-answering text models and the vision transformers. None of their workbenches draws attention maps yet: the figure uses five hand-set heads that imitate patterns reported in trained models, and says so.
Where to see it
No workbench draws this yet: the figure at the top of this page is the only place in WeightSpace for now.
Model structures: Name the emotion in a sentence, Find the most relevant answer, Find an answer in a passage, Fill a gap in Chinese, Translate a Chinese sentence, Estimate depth from a photo