Bahdanau Attention › Visualizing Attention Alignments
Language AI HandbookAll chapters Bahdanau Attention › Visualizing Attention AlignmentsOne section · Sections in this chapter6 / 11 ↓
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 mechanisms are interpretable. We can visualize the attention weights to see what the model is "looking at" when generating each output token.

The attention heatmap reveals several interesting patterns:
- Monotonic alignment: For this simple sentence, attention roughly follows the diagonal. This reflects the similar word order between English and French.
- Word-to-word correspondence: "Le" attends strongly to "The," "chat" to "cat," and "tapis" to "mat."
- Many-to-one mapping: Both "était" and "assis" attend primarily to "sat," since the single English word requires two French words.
- Soft attention: Even when one position dominates, other positions receive small but non-zero weights.
We can also visualize how the attention distribution evolves step by step during decoding. Each row in the heatmap above represents a single decoding step, but viewing them as individual distributions makes the shifting focus more apparent:







This interpretability is valuable for debugging and understanding model behavior. If a translation is wrong, we can inspect the attention weights to see if the model was looking at the right parts of the input.
Attention Entropy: Measuring Focus
A useful metric for understanding attention behavior is entropy, which quantifies how spread out or focused the attention distribution is. Low entropy indicates concentrated attention on few positions; high entropy indicates diffuse attention across many positions.

The entropy analysis reveals that most decoding steps in this translation have relatively focused attention (entropy below 1.0), indicating clear word-to-word correspondences. Steps with higher entropy might indicate cases where the model needs to aggregate information from multiple source positions, such as translating idiomatic expressions or handling word reordering.
Non-Monotonic Alignment Patterns
While English-French translation often exhibits roughly monotonic alignment (words appear in similar order), attention can handle more complex patterns. Languages with different word orders, or sentences with long-distance dependencies, produce non-monotonic attention patterns.

This example demonstrates one of attention's key strengths: it can learn arbitrary alignment patterns without explicit supervision. The model discovers that German places the past participle ("gegessen") at the end of the clause, and learns to attend to the corresponding English words ("has eaten") regardless of their position.