Skip to main content
QUICK REVIEW

[Paper Review] Mask Attention Networks: Rethinking and Strengthen Transformer

Zhihao Fan, Yeyun Gong|arXiv (Cornell University)|Mar 25, 2021
Topic ModelingComputer Science25 references7 citations
TL;DR

This paper proposes Dynamic Mask Attention Networks (DMAN), a novel attention mechanism that enhances Transformers by learning adaptive, context-dependent masks to improve local structure modeling. By unifying Self-Attention Networks (SAN) and Feed-Forward Networks (FFN) as special cases of Mask Attention Networks (MANs) with static masks, the authors introduce DMAN with a learnable, dynamic mask that boosts attention to neighboring tokens, achieving state-of-the-art performance in neural machine translation and text summarization through a sequential DMAN → SAN → FFN architecture.

ABSTRACT

Transformer is an attention-based neural network, which consists of two sublayers, namely, Self-Attention Network (SAN) and Feed-Forward Network (FFN). Existing research explores to enhance the two sublayers separately to improve the capability of Transformer for text representation. In this paper, we present a novel understanding of SAN and FFN as Mask Attention Networks (MANs) and show that they are two special cases of MANs with static mask matrices. However, their static mask matrices limit the capability for localness modeling in text representation learning. We therefore introduce a new layer named dynamic mask attention network (DMAN) with a learnable mask matrix which is able to model localness adaptively. To incorporate advantages of DMAN, SAN, and FFN, we propose a sequential layered structure to combine the three types of layers. Extensive experiments on various tasks, including neural machine translation and text summarization demonstrate that our model outperforms the original Transformer.

Motivation & Objective

  • To reframe Self-Attention Networks (SAN) and Feed-Forward Networks (FFN) as special cases of a unified Mask Attention Network (MAN) framework with static masks.
  • To identify the limitation of static masks in SAN and FFN for modeling local dependencies in text representation.
  • To propose a Dynamic Mask Attention Network (DMAN) with a context- and distance-dependent learnable mask to better capture local structure.
  • To design a new sequential architecture, DMAN → SAN → FFN, to synergistically combine the strengths of DMAN, SAN, and FFN.
  • To empirically validate the proposed model on neural machine translation and abstractive text summarization tasks.

Proposed method

  • Reformulate SAN and FFN as Mask Attention Networks (MANs) where attention is computed as the element-wise product of a key-query attention matrix and a mask matrix.
  • Define the mask matrix of SAN as an all-ones matrix and that of FFN as an identity matrix, establishing them as special cases of MANs.
  • Propose DMAN with a learnable mask matrix that dynamically adapts based on query context and relative token distance to emphasize neighboring tokens.
  • Design a sequential architecture: DMAN → SAN → FFN, where DMAN enhances local context modeling before SAN captures long-range dependencies and FFN performs non-linear transformation.
  • Train the model end-to-end with standard Transformer objectives, using the dynamic mask to attend more strongly to nearby tokens in a windowed context.
  • Compute attention score contributions within a window size $w$ using $attn\_s_{w,l,*}$, a metric to quantify local attention effectiveness.

Experimental results

Research questions

  • RQ1How can Self-Attention Networks (SAN) and Feed-Forward Networks (FFN) be systematically unified under a common framework?
  • RQ2Why do static mask matrices in SAN and FFN limit their ability to model local dependencies in text representations?
  • RQ3Can a learnable, dynamic mask mechanism improve local structure modeling in Transformers without sacrificing global modeling capacity?
  • RQ4What is the optimal architectural composition for combining DMAN, SAN, and FFN to maximize performance on NLP tasks?
  • RQ5To what extent does the proposed DMAN mechanism enhance attention to neighboring tokens compared to standard self-attention?

Key findings

  • In layer 1 of the IWSLT14 De-En test set, DMAN with a window size of 2 achieves 50% higher attention score contributions to neighboring tokens than SAN, with a gap of up to five times in some cases.
  • At window size 4, DMAN achieves 95.09% attention score contribution in layer 1, compared to only 30.38% for SAN, demonstrating superior local attention modeling.
  • The proposed DMAN → SAN → FFN architecture outperforms the original Transformer on both neural machine translation and abstractive text summarization tasks.
  • The dynamic mask in DMAN effectively reduces noise from non-neighboring, indirectly related tokens by suppressing their attention scores.
  • The attention score analysis confirms that DMAN assigns significantly higher attention to tokens within a local window than SAN, especially in early layers where local patterns are critical.
  • The model's performance gain is attributed to DMAN’s ability to adaptively emphasize local context while preserving SAN’s global modeling and FFN’s non-linear transformation capabilities.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.