Adaptively Sparse Transformers

Gonçalo M. Correia, Vlad Niculae, André F. T. Martins
8/30/2019
cs.CLstat.ML

Official code: deep-spin/entmax (473 stars, MIT, last commit 2024-06-22).

Abstract

Attention mechanisms have become ubiquitous in NLP. Recent architectures, notably the Transformer, learn powerful context-aware word representations through layered, multi-headed attention. The multiple heads learn diverse types of word relationships. However, with standard softmax attention, all attention heads are dense, assigning a non-zero weight to all context words. In this work, we introduce the adaptively sparse Transformer, wherein attention heads have flexible, context-dependent sparsity patterns. This sparsity is accomplished by replacing softmax with $α$-entmax: a differentiable generalization of softmax that allows low-scoring words to receive precisely zero weight. Moreover, we derive a method to automatically learn the $α$ parameter -- which controls the shape and sparsity of $α$-entmax -- allowing attention heads to choose between focused or spread-out behavior. Our adaptively sparse Transformer improves interpretability and head diversity when compared to softmax Transformers on machine translation datasets. Findings of the quantitative and qualitative analysis of our approach include that heads in different layers learn different sparsity preferences and tend to be more diverse in their attention distributions than softmax Transformers. Furthermore, at no cost in accuracy, sparsity in attention heads helps to uncover different head specializations.

View on arXivView PDF

Code Implementations(1)

deep-spin/entmaxOfficial100%
MIT

The entmax mapping and its loss, a family of sparse softmax alternatives.

47347PythonMay 31, 20192 years agoMIT

Similar Papers

Cite this paper

@article{correia2019adaptively,
  title  = {Adaptively Sparse Transformers},
  author = {Gonçalo M. Correia and Vlad Niculae and André F. T. Martins},
  year   = {2019},
  eprint = {1909.00015},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1909.00015}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1909.00015.svg)](https://codeofpaper.com/paper/1909.00015)

Discussion