Towards Opening the Black Box of Neural Machine Translation: Source and Target Interpretations of the Transformer

Javier Ferrando, Gerard I. Gállego, Belen Alastruey, Carlos Escolano, Marta R. Costa-jussà

TL;DR

ALTI+ is a new interpretability method for Neural Machine Translation (NMT) that quantifies the influence of both the source sentence and the previously translated words (target prefix) on every new token prediction. By tracking these attributions through the "black box" of the Transformer, the authors reveal how models balance these two contexts and why they sometimes "hallucinate" by ignoring the source text entirely.

What Problem Does This Paper Address?

While Transformers have revolutionized translation, they remain notoriously difficult to interpret. In NMT, the model makes predictions based on two distinct inputs: the source sentence (what is being translated) and the target prefix (what has already been translated).

Most existing interpretability research focuses solely on the source sentence, often by looking at attention weights. However, attention weights can be misleading; high attention doesn't always equal high influence. Furthermore, ignoring the target prefix means we only see half the picture. We lack a holistic understanding of how the model weighs these two competing contexts to decide on the next word.

Methods

The authors introduce ALTI+, an adaptation of the Aggregation of Layer-wise Token-to-token Interactions (ALTI) method specifically designed for encoder-decoder architectures.

The core idea is to move beyond raw attention weights. The method decomposes each Transformer block (Multi-Head Attention + Residual Connection + Layer Normalization) into a summation of transformed input vectors. It then uses the Manhattan distance between these transformed vectors and the final output vector to measure the actual "contribution" of each input token at each layer.

To get a global view, ALTI+ uses a rollout mechanism. It builds a Directed Acyclic Graph where nodes are token representations and edges are these calculated contributions. By multiplying these contribution matrices across all layers of both the encoder and decoder, the method produces a final attribution score for every input token (source and target) relative to the predicted output.

ALTI+ results for a De-En translation example. We obtain source sentence and target prefix (columns) interpretations for every predicted token (row).

Datasets

The researchers evaluated their method on two types of models:

  • Bilingual: A 6-layer Transformer trained on the Europarl v7 German-English (De-En) corpus and evaluated on IWSLT’14.
  • Multilingual: The M2M Transformer (418M parameters), which can translate between 100 languages. For this, they used the FLORES-101 dataset, focusing on high-resource (English, Spanish, French) and low-resource (Zulu, Xhosa) language pairs.

Key Insights and Ideas

  • Information Mixing in the Encoder: The encoder doesn't just "smear" information across the sentence. ALTI+ shows that even in the final layer, tokens retain about 41-47% of their original identity, while the rest is contextual information from other tokens.
  • The EOS "No-Op" Strategy: Models often give high attention to the End-of-Sentence (</s>) token. ALTI+ reveals this is a "no-op" mechanism. When the model attends to </s>, it is actually "skipping" the source information to let more information flow from the target prefix via the residual connection.
  • Visualizing Hallucinations: When a model "hallucinates" (generates fluent but unrelated text), ALTI+ shows a dramatic drop in source contribution. The model effectively stops "listening" to the source and starts generating text based only on its own previous words.
  • Low-Resource Vulnerability: In multilingual models, translating from a high-resource language (English) to a low-resource one (Zulu) often triggers a "hallucination-like" state where the model ignores the source more than it would for high-resource pairs.

Key Results

  • Superior Alignment: ALTI+ achieved a significantly lower Alignment Error Rate (AER) of 38.8 compared to raw attention weights (47.7) and previous vector-norm methods (41.4). This suggests ALTI+ provides a much more faithful representation of how the model actually aligns words.
  • Hallucination Detection: The authors successfully used ALTI+ to quantitatively distinguish between normal translations and hallucinations by measuring the shift in source vs. target prefix contribution.
Source input attributions Rmodel yet←x.

Limitations and Future Work

The authors acknowledge a few key limitations:

  • Softmax Exclusion: The method tracks contributions to the hidden representations in the final layer but does not account for the final softmax layer. This means it can't explain why one specific vocabulary word was chosen over another (e.g., "cat" vs. "kitten").
  • Computational Complexity: While not explicitly detailed as a bottleneck, rollout methods involve multiple matrix multiplications that scale with sequence length and depth.

Future Work: The authors suggest using ALTI+ attributions to detect and mitigate gender bias in NMT or to build safety mechanisms that flag potential hallucinations in real-time by monitoring source contribution levels.

Summary updated

BibTeX
@inproceedings{ferrando2022towards,
  author = {Javier Ferrando and Gerard I. Gállego and Belen Alastruey and Carlos Escolano and Marta R. Costa-jussà},
  title = {{Towards Opening the Black Box of Neural Machine Translation: Source and Target Interpretations of the Transformer}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=87vt_XW9NcT},
}
Figure