Introduction
The Transformer architecture has redefined natural language processing by leveraging self-attention to capture long-range dependencies. However, this global perspective often comes at the cost of "attention dispersion," where the model fails to adequately prioritize the local context essential for understanding phrasal structures. This paper proposes a novel method to re-introduce an inductive bias for locality into the Transformer without sacrificing its global reach.
The Challenge of Attention Dispersion
Standard self-attention treats all positions in a sequence with equal potential importance. While this allows for capturing distant relationships, it forces the model to learn basic linguistic properties—such as the fact that adjacent words are often highly related—from scratch. In contrast, architectures like RNNs and CNNs possess an inherent bias toward locality. The authors argue that the "blurry" focus of standard Transformers can lead to inefficiencies, particularly in tasks like machine translation where local syntax is paramount.
Methodology: Learnable Gaussian Bias
To address this, the researchers introduce a "soft" locality constraint using a learnable Gaussian bias. Instead of a hard window, the attention scores are modified by adding a Gaussian distribution $G$ before the softmax operation:
$$\text{Attention} = \text{softmax}(\text{energy} + G)$$
This Gaussian mask is dynamic and query-specific. For every word (query), the model predicts two key parameters:
- Central Position ($P_i$): The focal point of the attention window.
- Window Size ($D_i$): The standard deviation, determining the breadth of the local focus.
The authors found that a Query-Specific strategy, where these parameters are calculated for each individual word, yielded the best performance. Furthermore, they observed that applying this bias primarily to the lower layers of the encoder is most effective, as these layers typically handle syntactic and local structural information.
Experimental Results
The model was evaluated on the WMT17 Chinese⇒English and WMT14 English⇒German translation tasks. The results demonstrated a consistent performance boost. On the Zh⇒En task, the BLEU score increased from 24.13 to 24.77 (+0.64).
Phrasal Accuracy and N-gram Analysis
A key finding of the study is the model's improved ability to capture long phrases. By analyzing the BLEU score gaps across different n-gram lengths, the researchers confirmed that the Gaussian bias significantly enhances the translation of 4-gram to 8-gram sequences, where standard Transformers often struggle.
Insights: The Hierarchy of Scope
The research also uncovered a "hierarchy of scope" within the Transformer. As information moves through the layers, the optimal attention window naturally expands. Lower layers benefit from a tighter focus (10-20 words), while higher layers require a broader view (30-40+ words) to integrate semantic information across the entire sentence. By enforcing locality at the base, the model constructs more coherent local representations that serve as better building blocks for higher-level global reasoning.
Conclusion
Modeling localness via a learnable Gaussian bias provides a simple yet powerful enhancement to the Transformer. It mitigates attention dispersion and improves the capture of phrasal context, leading to state-of-the-art results in machine translation while maintaining computational efficiency. Future work may involve integrating explicit linguistic structures, such as syntax trees, to further refine the model's local focus.
Summary updated