TL;DR
Transformers are famously computationally expensive because every token attends to every other token. This paper demonstrates that this "global" attention might be overkill: token representations are far more sensitive to their immediate neighbors than to distant syntactic partners. By constraining attention to local windows and sharing parameters across heads, the authors achieve near-state-of-the-art performance on translation and language understanding tasks while significantly reducing model complexity.
What Problem Does This Paper Address?
The self-attention mechanism is the engine of the Transformer architecture, but it comes with a heavy "computational tax": its complexity scales quadratically ($O(T^2)$) with the sequence length. While researchers have observed that different attention heads specialize in syntactic or local patterns, it remained unclear whether global attention is truly necessary for high performance.
The authors set out to answer a fundamental question: Can we build accurate Transformers using only local information? If local attention is sufficient, we could potentially design much more efficient models that skip the expensive all-to-all calculations.
Methods
The researchers approached this problem in two phases: analysis and intervention.
- Sensitivity Analysis: They used gradients to measure how much the output representation of a token changes when an input token is perturbed. They compared sensitivity to local tokens (within a window of 2), syntactic tokens (distant but grammatically related), and unrelated tokens.
- Attention Bias Metric: They defined a score to quantify whether a specific head is "biased" toward local or syntactic information compared to a random baseline.
- Modified Transformers: To test their hypothesis, they modified standard Transformer (NMT) and BERT (NLU) models by:
- Masking: Multiplying the attention matrix by binary masks (e.g.,
prev-1,next-2,band-k) to force heads to only look at specific local neighborhoods. - Parameter Sharing: Forcing multiple heads within a layer—or even across different layers—to share the same Key ($W^k$) and Query ($W^q$) matrices, drastically reducing the number of trainable parameters.
Datasets
The models were evaluated on two major benchmarks:
- Machine Translation (NMT): WMT’14 English-Russian (EN-RU) and English-German (EN-DE) datasets, evaluated using BLEU scores.
- Natural Language Understanding (NLU): Four tasks from the GLUE benchmark: QQP (Quora Question Pairs), SST-2 (Sentiment), MRPC (Paraphrase), and QNLI (Natural Language Inference).
Key Insights and Ideas
- Locality is King: The sensitivity analysis revealed that at every single layer, a token's representation is significantly more influenced by its immediate neighbors than by distant tokens, even those that are syntactically related. As seen in Figure 1, the norm of the gradient for local tokens (blue) consistently dwarfs the others.
- Natural Emergence of Locality: Even without constraints, a large fraction of attention heads naturally develop a locality bias. In contrast, very few heads focus primarily on non-local syntactic relations (see Figure 2).
- Stacking Creates Receptive Fields: The authors argue that even if individual layers are constrained to look only at 5 tokens, the stacking of multiple layers allows information to propagate across the entire sentence, similar to how deep Convolutional Neural Networks (CNNs) achieve a global receptive field.
- BERT’s Last Layers are Special: Unlike NMT models, BERT models suffered when the last two layers were constrained by parameter sharing. This is because BERT lacks a decoder; its final encoder layers must do the "heavy lifting" for the specific downstream task.
Key Results
The results were surprisingly robust:
- Translation: A Transformer model where all encoder heads were constrained to be local achieved a BLEU score drop of only 0.14 on EN-RU and actually saw a slight increase (0.11) on EN-DE compared to the unconstrained baseline.
- Efficiency: In the "Fully Tied" configuration (sharing one set of parameters across all layers), the model used roughly 50% fewer attention parameters while maintaining comparable BLEU scores (dropping only ~0.1 to 0.24 points).
- Language Understanding: For BERT, constraining all heads to be local resulted in only a 2-3% performance drop. By "untying" just the last two layers, they recovered almost all the baseline accuracy.
Limitations and Future Work
While the paper proves that local attention is sufficient for accuracy, the authors acknowledge a few hurdles:
- Actual Speedups: The current implementation uses masks after computing the full attention matrix to maintain experimental control. To realize actual $O(T)$ speedups in practice, one would need to implement specialized kernels that avoid computing the full $T \times T$ matrix entirely.
- Decoder Analysis: This study focused almost exclusively on the Transformer encoder. The role of locality in the decoder (which handles generation) remains an open question.
- Long-Range Dependencies: While stacking layers helps, tasks requiring extremely long-range reasoning (e.g., long document summarization) might still require some global heads.
Reference: Pande, M., et al. (2020). On the Importance of Local Information in Transformer Based Models. arXiv:2008.05828v1 [cs.CL].
Summary updated