Attention Intuition › Visualizing Attention Patterns

Michael BrenndoerferMay 16, 20253 min read
Language AI HandbookAll chapters
Part 12 of 67Sequence-to-Sequence
Chapter 86Attention Intuition › Visualizing Attention Patterns
Reading section 11 of 20 · Visualizing Attention Patterns · 3 minSection 11 of 20 · 3 min

Book contents

Section 11 of 20 · 3 min read

Attention Intuition › Visualizing Attention PatternsOne section · Sections in this chapter11 / 20 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Attention weights are typically visualized as heatmaps, with rows representing decoder steps (outputs) and columns representing encoder positions (inputs). The resulting matrix provides an intuitive view of what the model focused on when generating each output token.

Out[10]:
Visualization
Heatmap of attention weights between English source words and French target words, showing a near-diagonal alignment pattern.
Attention weight heatmap for English-to-French translation, showing which source words the model attends to when generating each target word. Darker blue cells indicate stronger attention. The near-diagonal pattern reflects similar word order in English and French, while the swapped positions for 'chat' (attends to 'cat') and 'noir' (attends to 'black') reflect French adjective-after-noun ordering.

Several patterns emerge from this visualization:

  • Diagonal tendency: Many languages share similar word order, so attention often follows a rough diagonal path from upper-left to lower-right
  • Reordering: French adjectives follow nouns ("chat noir" vs "black cat"), visible in the swapped attention for "chat" (attending to "cat") and "noir" (attending to "black")
  • Many-to-one mapping: Both "etait" and "assis" attend primarily to "sat", which reflects how French uses two words where English uses one
  • Article alignment: Function words like "Le" and "le" align with their English counterparts

This kind of alignment matrix became a key piece of evidence in the original Bahdanau et al. (2014) paper showing that attention had learned meaningful linguistic structure without explicit supervision. The heatmaps showed structured, interpretable correspondences that matched human linguistic intuition rather than leaving the translation process entirely opaque.