[Paper Review] RealFormer: Transformer Likes Residual Attention
RealFormer introduces a simple, parameter-free technique that enhances Transformer models by adding residual connections to attention scores, significantly improving performance across diverse NLP tasks such as GLUE, SQuAD, and machine translation. It achieves state-of-the-art results with faster convergence and sparser, more stable attention patterns.
Transformer is the backbone of modern NLP models. In this paper, we propose RealFormer, a simple and generic technique to create Residual Attention Layer Transformer networks that significantly outperform the canonical Transformer and its variants (BERT, ETC, etc.) on a wide spectrum of tasks including Masked Language Modeling, GLUE, SQuAD, Neural Machine Translation, WikiHop, HotpotQA, Natural Questions, and OpenKP. We also observe empirically that RealFormer stabilizes training and leads to models with sparser attention. Source code and pre-trained checkpoints for RealFormer can be found at https://github.com/google-research/google-research/tree/master/realformer.
Motivation & Objective
- To improve the performance of Transformer-based models across diverse NLP tasks without adding parameters or hyperparameters.
- To investigate whether creating a direct path for attention scores—similar to residual connections in ResNets—can stabilize training and improve generalization.
- To evaluate the effectiveness of residual attention as a drop-in replacement in established models like BERT, ADMIN, and ETC.
- To analyze the qualitative behavior of attention mechanisms in RealFormer, particularly regarding sparsity and correlation across layers.
Proposed method
- Introduces a residual attention mechanism by adding a skip connection that directly propagates raw attention scores from the previous layer to the current layer.
- Modifies the standard Transformer encoder block by combining the original multi-head attention scores with a residual stream of attention scores from the previous layer before applying softmax.
- Uses a running sum of attention scores as the residual component, preserving the original attention computation while enabling gradient flow through the residual path.
- Applies the technique universally across different Transformer variants, including encoders, decoders, and sparse attention mechanisms like ETC.
- Employs the same pre-training and fine-tuning recipes as baseline models to ensure fair comparison, with minimal code changes required.
- Uses checkpoint averaging during inference to improve robustness, especially for large models.
Experimental results
Research questions
- RQ1Can adding residual connections to attention scores improve the performance of standard and state-of-the-art Transformer models across diverse NLP tasks?
- RQ2Does residual attention lead to more stable training dynamics and improved convergence speed compared to Post-LN and Pre-LN Transformers?
- RQ3How does residual attention affect attention sparsity and inter-layer correlation in trained models?
- RQ4Can RealFormer serve as a generic, plug-and-play improvement for existing Transformer architectures without architectural or hyperparameter changes?
- RQ5Does residual attention enable better performance with fewer pre-training epochs compared to standard baselines?
Key findings
- RealFormer outperforms both Post-LN and Pre-LN Transformers across all model sizes on masked language modeling and downstream GLUE tasks, with improvements up to 2.5 points on average.
- On the WMT’14 En-Fr translation benchmark, RealFormer achieves a new state-of-the-art BLEU score of 43.97 with only 50 pre-training epochs, outperforming the baseline ADMIN model by 0.25 BLEU points.
- On the WikiHop benchmark, RealFormer improves accuracy to 84.4%, a 2.1% absolute improvement over the previous SOTA, and ranks first on the official leaderboard.
- RealFormer improves ETC-Large across all four long-context benchmarks: HotpotQA (joint F1: 73.57 vs. 73.12), Natural Questions (average F1: 68.51 vs. 68.07), and OpenKP (F1@3: 44.27 vs. 44.06).
- Qualitative analysis shows that RealFormer produces sparser attention patterns both within heads and across adjacent layers, suggesting regularization effects that may stabilize training.
- Despite using only half the number of pre-training epochs as baseline models, RealFormer achieves competitive fine-tuning results, indicating faster convergence and better sample efficiency.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.