Neural Machine Translation › Attention as Learned Soft Alignment

Michael BrenndoerferNovember 26, 20263 min read
Language AI HandbookAll chapters
Part 27 of 67Machine Translation and Speech Translation
Chapter 191Neural Machine Translation › Attention as Learned Soft Alignment
Reading section 4 of 12 · Attention as Learned Soft Alignment · 3 minSection 4 of 12 · 3 min

Section 4 of 12 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The attention matrix α∈Rn×m\alpha \in \mathbb{R}^{n \times m} assigns source-position weights at each target step. A row can serve as a soft alignment diagnostic when compared with known token correspondences.

In the IBM models, each target position has a latent link to one source position or NULL. The model sums over possible alignments, and expectation-maximization can estimate the parameters. A phrase extraction pipeline can consume a set of word links, which you can evaluate using Alignment Error Rate. Multiple targets can link to the same source.

Neural attention is a differentiable weighted sum inside a model trained on translation. Without explicit alignment supervision, the weights are determined by what helps the translation objective.

The differences matter:

  • Soft weights. A row can spread mass across several source positions. Compare the weights with a reference alignment before interpreting that spread as uncertainty about word correspondences.
  • Repeated use of a source position. Several target rows can assign high weights to one source position. IBM Model 3 explicitly models how many target words a source word produces. The attention sum here has no separate fertility variable.
  • Translation objective. The weights can route contextual information that differs from a reference word link. For a known correspondence, compare both the recorded weights and the prediction.
  • Interpretation. Jain and Wallace (2019) found that in some of their NLP models, very different attention distributions could give similar predictions. Wiegreffe and Pinter (2019) emphasized the comparison and controls needed for an explanation. Use a translation heatmap to identify cases for follow-up. To make a causal claim, use a test that intervenes on the quantity of interest.

What attention learns about reordering

Sketch the token correspondences for a specific sentence before inspecting attention. The following examples are candidate comparisons for such a diagnostic.

  • English → French. In “the red book” and “le livre rouge,” mark where “red” links to “rouge” and “book” to “livre.” Those links are off the diagonal.
  • English → German. In the example with “because she reads the book,” trace “reads” to the final “liest.” A content-word link can cover several positions even in a short clause.
  • Japanese → English. Compare “猫が魚を食べる” with “The cat eats fish.” Trace the cat, fish, and eating correspondences before interpreting rows associated with articles or particles.
  • English → Chinese. Compare “three books” with “三本书.” The classifier 本 has no separate English word in that pair. Mark it explicitly before interpreting its target row.

These are reference links for selected phrases. If a trained model's weights differ, inspect the translation and the tokenization before deciding what the difference means.

Attention failure modes

Compare the output with the source before using attention to investigate a failure.

  • Under-translation. If a clause is missing, inspect the source span corresponding to that clause and see how it was attended to during decoding.
  • Over-translation. If a phrase repeats, compare the attention weights at each repetition and check whether they cover the same source region.
  • Source mismatch. If an out-of-domain output changes the meaning, compare it with outputs for an in-domain example and check which source positions the weights emphasize.

The coverage penalty below discourages low cumulative attention on a source position. Once the coverage reaches one, additional weight leaves that source position's contribution unchanged.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy