Abstract
The Transformer architecture has revolutionized natural language processing through its two core components: Self-Attention (SAN) and Feed-Forward Networks (FFN). However, these components represent two extremes of information processing—global context versus strict point-wise locality. This paper introduces Mask Attention Networks (MANs), a unified framework that treats both SAN and FFN as specific instances of masked attention. By introducing a novel Dynamic Mask Attention Network (DMAN) that adaptively learns local dependencies, the authors propose a sequential architecture (DMAN → SAN → FFN) that significantly improves performance in machine translation and text summarization.
The "Localness" Problem in Transformers
Standard Transformers rely on SAN for global context and FFN for point-wise processing. This design creates a gap in modeling the immediate neighborhood of a token, which is often essential for understanding syntax and short-range semantics.
SAN typically uses an "all-ones" mask, allowing every token to attend to every other token. While powerful, this can introduce noise; for instance, two unrelated words might assign each other high attention scores simply because they share a common neighbor. Conversely, the FFN is an extreme localist, using an "identity" mask where a token only processes itself. The Transformer lacks a flexible mechanism to bridge these two extremes.
Methods: A Unified View of Attention
The authors propose that both SAN and FFN are specific types of Mask Attention Networks. In this framework, attention is multiplied element-wise by a mask matrix $M$:
- SAN is a MAN where $M$ is an all-ones matrix (global).
- FFN is a MAN where $M$ is an identity matrix (strictly local).
To fill the gap between global and strictly local processing, the authors introduce the Dynamic Mask Attention Network (DMAN). Unlike previous local attention methods that used fixed window sizes, DMAN employs a learnable, "soft" mask. This mask is dynamic, adapting based on the specific query token, the relative distance to neighbors, and the specific attention head or layer.
Architecture: The DMAN-SAN-FFN Sandwich
Building on this unified view, the researchers propose a new sequential structure for each Transformer block. Instead of the standard SAN → FFN sequence, they implement a DMAN → SAN → FFN pipeline. This allows the model to first capture local structures, then integrate global context, and finally perform self-evolution through the FFN.
Key Insights
- FFN as Attention: The paper provides a mathematical proof that a Feed-Forward Network is functionally equivalent to a Mask Attention Network with an identity mask, simplifying the conceptual landscape of the Transformer.
- Avoiding the "Common Neighbor" Trap: By masking out non-neighbors, DMAN prevents unrelated words from incorrectly attending to each other just because they are both related to a central word (e.g., "black" and "catch" in "a black dog jump to catch the frisbee").
- Locality Preference: Analysis shows that DMAN places up to 5x more weight on immediate neighbors than standard SAN in early layers, confirming it successfully learns to prioritize local structure.
Experimental Results
The MAN architecture was evaluated on standard benchmarks for natural language generation, including IWSLT14 (De-En), WMT14 (En-De), and abstractive summarization tasks (CNN/Daily Mail, Gigaword).
- Machine Translation: On the WMT14 En-De "big" task, the model achieved 30.4 BLEU, a +2.0 point improvement over the original Transformer. Notably, the MAN "base" model (63M params) outperformed the standard Transformer "big" model (213M params) in several metrics.
- Summarization: On the CNN/Daily Mail dataset, the model improved the ROUGE-L score by 1.25 points over the baseline.
- Efficiency: Despite adding a sublayer, the parameter count remains comparable to the baseline because the internal dimensionality of the FFN was reduced to compensate for the DMAN addition.
Conclusion and Future Work
By rethinking the Transformer through the lens of mask attention, this work provides both a theoretical unification and a practical performance boost. Future research may involve incorporating external structural priors, such as dependency trees, directly into the mask matrices or exploring the application of dynamic local-to-global masking in computer vision.
Summary updated