Relaxed Attention for Transformer Models

Timo Lohrenz, Björn Möller, Zhengyang Li, Tim Fingscheidt

TL;DR

"Relaxed attention" is a deceptively simple technique that smoothes transformer attention weights by blending them with a uniform distribution. By applying this to the encoder for regularization and the decoder to suppress "internal language models," the authors achieve a new state-of-the-art in lip-reading and top-tier results in machine translation with virtually no additional parameters.

What Problem Does This Paper Address?

Transformer models are the heavyweights of modern AI, but they suffer from two persistent headaches:

  1. Overfitting: Their massive capacity makes them prone to memorizing training data rather than generalizing.
  2. The "Internal Language Model" (ILM) Bias: In sequence tasks like speech recognition, the autoregressive decoder often learns its own implicit language model based on the training text. When researchers try to plug in a high-quality external language model (LM) during inference to improve performance, this "internal" bias often clashes with the external one, limiting the overall gain.

While previous research touched on smoothing cross-attention for speech recognition, this paper explores whether a generalized "relaxation" of attention can serve as a universal regularizer across the entire architecture and multiple modalities (text, audio, video, and images).

Methods

The core idea is Relaxed Attention. Instead of using the raw attention weights ($G_i$) produced by the standard softmax function, the authors compute a "relaxed" version ($\tilde{G}_i$):

$$\tilde{G}_i = (1 - \gamma)G_i + \gamma \frac{\mathbf{1}}{T}$$

Where:

  • $\gamma$ (gamma): A relaxation coefficient between 0 and 1.
  • $\mathbf{1}/T$: A uniform distribution across the sequence length $T$.

Essentially, this "waters down" the attention peaks, forcing the model to consider the entire input sequence more broadly.

Key Innovations: * Encoder Relaxation: Applying this to self-attention layers in the encoder to act as a regularizer. * Matched Inference: Using the same relaxation during both training and testing. * Fuzzy Relaxation: For image tasks, they introduce a variant where $\gamma$ is randomly sampled from a normal distribution during training, providing a stochastic regularization effect similar to Dropout.

Datasets

The authors evaluated their method across four distinct domains:

  • Automatic Speech Recognition (ASR): Librispeech (100h and 960h subsets).
  • Lip-reading: LRS3 (Lip Reading Sentences 3), the largest public benchmark for visual speech recognition.
  • Machine Translation: IWSLT14 (German to English).
  • Image Classification: CIFAR-100 (using the Swin Transformer architecture).

Key Insights and Ideas

  • Suppressing the "Know-it-all" Decoder: The most significant "aha" moment is that relaxing cross-attention in the decoder specifically weakens the model's internal language model. This makes the model "humbler" and more receptive to the influence of a powerful external LM, leading to much better fusion results.
  • Universal Regularization: Unlike many techniques that are task-specific (like SpecAugment for audio), relaxed attention works as a general-purpose regularizer. In the encoder, it prevents the model from focusing too narrowly on specific input tokens too early.
  • Complementary Gains: Relaxed attention doesn't just replace existing methods like Label Smoothing or Dropout; it works alongside them to provide additive performance boosts.
  • Matched vs. Unmatched: The paper finds that for the encoder, "matched inference" (keeping the relaxation on during testing) is often beneficial, whereas for the decoder's cross-attention, it's sometimes better to only use it during training to "teach" the model not to rely on its ILM.

Key Results

The results are impressive, especially considering the simplicity of the implementation:

  • Lip-reading SOTA: On the LRS3 benchmark, they achieved a 26.31% Word Error Rate (WER), surpassing the previous state-of-the-art of 26.90%.
  • Machine Translation: On IWSLT14 (DE→EN), they reached a top-performing 37.67 BLEU score without using any external language models.
  • ASR Improvements: On Librispeech 100h, combining relaxed cross-attention with an external LM dropped the WER from 10.62% (baseline) to 9.33% on the dev-clean set.
  • Image Classification: Using "fuzzy relaxation" with a Swin Transformer on CIFAR-100 improved accuracy from 89.16% to 89.60%.

Limitations and Future Work

The authors note that relaxed cross-attention is primarily beneficial when an external language model is available. Without an external LM, the model relies on its internal biases to make sense of sequences; "relaxing" those biases without a replacement can actually hurt performance.

Future work could involve automatically tuning the $\gamma$ hyperparameter per layer or exploring the interaction between relaxed attention and even larger-scale pre-training regimes like those used in GPT-4 or Whisper.

Summary updated

BibTeX
@inproceedings{lohrenz2023relaxed,
  author = {Timo Lohrenz and Björn Möller and Zhengyang Li and Tim Fingscheidt},
  title = {{Relaxed Attention for Transformer Models}},
  booktitle = {IJCNN},
  year = {2023},
  doi = {10.1109/ijcnn54540.2023.10191643},
}
Figure