Alleviating the Inequality of Attention Heads for Neural Machine Translation

Zewei Sun, Shujian Huang, Xinyu Dai, Jiajun Chen

Abstract

The Multi-Head Attention (MHA) mechanism is a cornerstone of the Transformer architecture, yet it exhibits significant redundancy. Previous research has shown that the vast majority of attention heads can be pruned from a trained model with negligible impact on performance. This paper explores the "inequality" of attention heads, hypothesizing that a "rich-get-richer" phenomenon during training allows a few heads to dominate the learning process, leaving others underdeveloped. We propose HeadMask, a training-time intervention that masks heads to force the model to distribute information across all available heads. Our experiments across four translation tasks show that HeadMask leads to more robust models and consistent improvements in BLEU scores.

Introduction: The Inequality Problem

While MHA is designed to allow the model to attend to different parts of the sequence simultaneously, it often fails to utilize its full capacity. In a standard trained Transformer, a small subset of heads performs the bulk of the work. This imbalance is problematic because it limits the model's total representational power and makes it fragile to the loss of specific "superstar" heads.

Figure 1: The impact of head masking on BLEU scores in a standard Transformer. The rapid decline when masking "important" heads first highlights the model's over-reliance on a small number of components.

The authors suggest this inequality arises because heads that coincidentally learn useful features early in training receive more gradient updates, further improving their utility and reinforcing the model's reliance on them. This feedback loop prevents "weaker" heads from ever becoming useful.

Methodology: HeadMask

To break this cycle, we introduce HeadMask, which encourages a more even distribution of head importance by temporarily disabling heads during training. We explore two variants:

  1. Mask Randomly (Random-N): In each training batch, $n$ heads are randomly selected and masked. This simple approach ensures that no single head is consistently available, forcing the model to spread knowledge.
  2. Mask Important Ones (Impt-N): This targeted approach identifies the most "important" heads in a batch (using a gradient-based Taylor expansion metric) and masks them. This explicitly suppresses dominant heads to allow others to catch up.

Key Insights and Analysis

The primary effect of HeadMask is the "flattening" of the head importance distribution. By preventing any single head from becoming too dominant, the model is forced to utilize its entire capacity more effectively.

Figure 6: Comparison of head importance distributions. Both Random-18 (b) and Impt-18 (c) strategies result in a significantly flatter distribution with lower variance compared to the Baseline (a).

Statistical analysis confirms this shift; for example, in the Zh-En task, the variance of head importance dropped from 77.28 in the baseline to 9.13 with HeadMask. Furthermore, models trained with HeadMask exhibit greater robustness. When heads are masked at inference time, HeadMask-trained models maintain higher performance levels than the baseline, indicating that the workload is successfully shared across redundant, high-quality heads.

Experimental Results

We evaluated HeadMask on four NMT datasets: NIST Zh-En, WMT16 Ro-En, IWSLT15 Vi-En, and WMT17 Tr-En. The results demonstrate consistent gains:

  • Translation Quality: The Random-18 variant achieved gains of up to +0.87 BLEU on Chinese-English and +0.78 BLEU on Romanian-English tasks.
  • Efficiency: Interestingly, the Random masking strategy often performed as well as or better than the Important strategy. Since Random-N does not require the additional forward/backward pass to calculate importance, it serves as a highly efficient "drop-in" training enhancement.

Conclusion

HeadMask addresses the inherent inequality in Transformer attention heads by forcing a more equitable distribution of labor during training. This not only improves translation performance but also creates more robust models with better-utilized capacity. Future work may explore combining HeadMask with structured pruning to produce smaller, high-performance models for deployment.

Summary updated

BibTeX
@inproceedings{sun2022alleviating,
  author = {Zewei Sun and Shujian Huang and Xinyu Dai and Jiajun Chen},
  title = {{Alleviating the Inequality of Attention Heads for Neural Machine Translation}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=RU-mT0N5MGq},
}
Figure