Probing Word Translations in the Transformer and Trading Decoder for Encoder Layers

Hongfei Xu, Josef van Genabith, Qiuhui Liu, Deyi Xiong · DOI

TL;DR

This paper investigates how word translation actually happens within Transformer models, revealing that translation begins much earlier than expected, even in the encoder layers. This insight leads to a practical finding: we can significantly speed up translation by using more encoder layers and fewer decoder layers without sacrificing much quality, and sometimes even improving it.

What Problem Does This Paper Address?

The Transformer architecture has revolutionized Neural Machine Translation (NMT), but its internal workings, particularly how it translates words across its layers, remain somewhat opaque. Previous research has focused on how source-side linguistic features are captured in the encoder. However, a key question was: at what point in the Transformer's layers does actual word translation occur, and what is the role of each layer in this process? Understanding this could lead to more efficient model designs.

Methods

The authors propose a "probing" approach to analyze word translation accuracy at each layer of a trained Transformer model. This involves:

  • Freezing the Transformer: The pre-trained model is kept fixed to ensure consistent analysis.
  • Linear Projection Layer: A small, trainable linear layer is added to extract relevant translation features from the representations of a specific layer being analyzed.
  • Frozen Classifier: These extracted features are then fed into the original, frozen decoder classifier of the Transformer.
  • Probing Accuracy: The accuracy of this setup in predicting target words serves as a measure of word translation capability at that specific layer.

For analyzing encoder layers, a novel step involves learning a weight vector to combine multiple attention matrices (from multi-head attention) into a single alignment matrix, which is then used to transform source representations to a target shape. For decoder layers, they analyze the impact of bypassing either the self-attention (language modeling) or cross-attention (source encoding) sub-layers to understand their individual contributions.

Datasets

The primary dataset used for training and evaluation is the WMT 14 English-German news translation task. They also report results on the WMT 15 Czech-English and WMT 14 English-French tasks to verify their findings across different language pairs.

Key Insights and Ideas

  • Translation Starts Early: Contrary to a naive assumption that encoders only capture source information and decoders translate, this work reveals that word translation begins surprisingly early, even in the input embeddings and lower encoder layers.
  • Encoder Layers are Not "Lazy": All encoder layers contribute to translation, with improvements being relatively consistent across layers. This suggests that increasing encoder depth is beneficial.
  • Decoder Layers Can Be "Lazy": Some lower decoder layers contribute less to translation accuracy compared to their encoder counterparts. This suggests potential for compression.
  • Source Encoding Dominates in Deep Decoders: In deeper decoder layers, the influence of the source "encoding" (via cross-attention) becomes more critical than the decoding history (via self-attention).
  • Trading Layers for Speed: The findings strongly motivate a structural change: using more encoder layers and fewer decoder layers can significantly boost decoding speed without a substantial loss in translation quality, and can even improve it.

Key Results

  • Encoder Layer Contributions: Word translation accuracy increases progressively through encoder layers. Layer 0 (embeddings) already shows a notable accuracy (e.g., 40.73% on WMT 14 En-De).
  • Decoder Layer Performance: Shallow decoder layers (0-3) perform worse than corresponding encoder layers. Layers 4 and 5 show larger improvements.
  • Speed-up: A Transformer with 10 encoder and 2 decoder layers achieved a 2.32x speed-up in decoding compared to a standard 6-layer Transformer, with a slightly higher BLEU score.
  • Quality Improvement with Layer Trading: A configuration with 18 encoder layers and 4 decoder layers achieved +1.42 BLEU improvement over a baseline, with a 1.38x speed-up.
  • BLEU-1 Score: When analyzing translation without re-ordering (using BLEU-1), the gap between encoder-only translation and the full Transformer is smaller, highlighting that word-level translation is indeed happening in the encoder.

Limitations and Future Work

  • Probing Classifier: While the authors argue their probing approach is minimally invasive, they acknowledge that probing methods can sometimes be sensitive to classifier training data. They address this by using a frozen classifier from the pre-trained model and showing significant gaps between random and pre-trained models.
  • "Lazy" Layers: The paper identifies "lazy" layers in the decoder, suggesting potential for compression. Future work could explore optimal layer distributions for different tasks and languages.
  • Practical Implications: The authors suggest that their findings are valuable for back-translation and production applications, implying that further exploration of these layer-trading configurations could lead to more efficient and effective NMT systems.

Summary updated

BibTeX
@inproceedings{xu2021probing,
  author = {Hongfei Xu and Josef van Genabith and Qiuhui Liu and Deyi Xiong},
  title = {{Probing Word Translations in the Transformer and Trading Decoder for Encoder Layers}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.naacl-main.7},
}
Figure