Tensorized Self-Attention: Efficiently Modeling Pairwise and Global Dependencies Together

Tao Shen, Tianyi Zhou, Guodong Long, Jing Jiang, Chengqi Zhang · DOI

TL;DR

This paper introduces Multi-Mask Tensorized Self-Attention (MTSA), a novel attention mechanism that efficiently models both local (pairwise) and global dependencies in natural language processing tasks. MTSA achieves state-of-the-art performance on nine NLP benchmarks while being as memory-efficient as CNNs and scalable to long sequences, addressing the computational bottlenecks of previous advanced attention models.

What Problem Does This Paper Address?

Traditional neural network architectures for Natural Language Processing (NLP) tasks, like Recurrent Neural Networks (RNNs) and Convolutional Neural Networks (CNNs), have been augmented with attention mechanisms to improve their ability to capture contextual information. While self-attention mechanisms offer advantages like parallelizability and fewer parameters, existing approaches often struggle to efficiently model both the fine-grained, pairwise relationships between tokens (e.g., syntactic dependencies) and the broader, global importance of tokens to the entire sequence. Specifically, methods that enhance expressive power by expanding attention scores into tensors lead to significant memory and computational overhead, making them impractical for long sequences. This paper aims to bridge this gap by proposing an attention mechanism that effectively integrates both types of dependencies without sacrificing efficiency.

Methods

The core innovation is Multi-Mask Tensorized Self-Attention (MTSA). It builds upon Tensorized Self-Attention (TSA), which combines two types of self-attention:

  • Token2token self-attention: This captures pairwise dependencies using an efficient dot-product compatibility function, similar to standard multi-head self-attention.
  • Source2token self-attention: This models global dependencies by assessing the importance of each token to the entire sequence, often using a multi-dimensional approach for richer representation.

TSA integrates these by creating a tensor of alignment scores, where each token pair has a score for each feature dimension. To improve efficiency and scalability, MTSA introduces:

  • Multi-head attention: The computation is distributed across multiple "heads," each operating on a lower-dimensional subspace of the input.
  • Multi-masking: Each head is assigned a distinct positional mask (e.g., forward or backward) to encode sequential and structural information. This allows for parallel processing and distributes the computational load.
  • Computation Optimization: The paper presents an algorithm that achieves the same results as tensor operations but relies solely on matrix multiplications, significantly reducing memory and computational costs.

Datasets

The paper evaluates MTSA on a variety of NLP tasks, utilizing the following datasets:

  • SNLI (Stanford Natural Language Inference): Used for natural language inference tasks.
  • MultiNLI (Multi-Genre Natural Language Inference): Also used for natural language inference.
  • CoNLL-05: Used for Semantic Role Labeling (SRL).
  • CR (Customer Reviews): A sentiment classification benchmark.
  • MPQA (Multi-Perspective Question Answering): An opinion polarity detection benchmark.
  • SUBJ (Subjectivity): A subjectivity classification benchmark.
  • TREC (Text REtrieval Conference): A question-type classification benchmark.
  • SST-5 (Stanford Sentiment Treebank): A sentiment analysis benchmark with five labels.
  • WMT 2014 English-German: Used for Machine Translation evaluation.

Key Insights and Ideas

  • Unified Dependency Modeling: The key insight is that effectively modeling NLP tasks requires a synergistic approach that captures both local, token-to-token interactions and global, sequence-wide context. MTSA achieves this by combining token2token and source2token attention.
  • Tensorization for Expressiveness, Matrix Ops for Efficiency: The paper demonstrates that while tensorization can increase model expressiveness, it's possible to achieve similar benefits using efficient matrix operations, thus avoiding computational bottlenecks.
  • Parallelism and Distribution: The multi-head and multi-masking strategy is crucial for distributing computation and memory load, making the model scalable to longer sequences.
  • Complementary Nature of Components: Ablation studies highlight that pairwise dependencies, global dependencies, and positional information are all vital and complementary for achieving high performance.

Key Results

MTSA achieved state-of-the-art or competitive performance on nine NLP benchmarks. Specifically:

  • On the SNLI dataset, MTSA achieved state-of-the-art results with significantly less time and memory compared to other models, outperforming even complex RNN and parsing tree-based encoders.
  • When integrated with a pretrained language model, MTSA achieved new state-of-the-art accuracy on both SNLI and MultiNLI datasets for sentence-encoding tasks.
  • For Semantic Role Labeling (SRL), MTSA achieved new state-of-the-art performance on the CoNLL-05 dataset with similar training time to CNN and multi-head self-attention baselines.
  • On five sentence classification benchmarks, MTSA achieved the best prediction accuracy with better time efficiency and lower memory load.
  • In Machine Translation, MTSA significantly outperformed multi-head self-attention in the Transformer encoder, demonstrating its enhanced expressiveness.

Limitations and Future Work

  • Computational Resources: While MTSA is designed for efficiency, the paper notes that experiments were conducted on a single NVIDIA GTX 1080Ti, and for machine translation, limited computational resources were used.
  • State-of-the-Art BLEU: For machine translation, the reported BLEU scores did not surpass the absolute state-of-the-art, but the experiment successfully verified MTSA's effectiveness compared to multi-head self-attention.
  • Future Work: The paper implicitly suggests that further exploration of different positional masks and combinations within the multi-head framework could lead to even better performance. The success across diverse NLP tasks also points to MTSA's broad applicability for future research.

Summary updated

BibTeX
@inproceedings{shen2019tensorized,
  author = {Tao Shen and Tianyi Zhou and Guodong Long and Jing Jiang and Chengqi Zhang},
  title = {{Tensorized Self-Attention: Efficiently Modeling Pairwise and Global Dependencies Together}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2019},
  doi = {10.18653/v1/n19-1127},
}
Figure