Linformer: Self-Attention with Linear Complexity

Sinong Wang, Belinda Z. Li, Madian Khabsa, Han Fang, Hao Ma
6/8/2020
cs.LGstat.ML

Official code: facebookresearch/fairseq (32,213 stars, MIT, PyTorch, last commit 2025-09-30).

Abstract

Large transformer models have shown extraordinary success in achieving state-of-the-art results in many natural language processing applications. However, training and deploying these models can be prohibitively costly for long sequences, as the standard self-attention mechanism of the Transformer uses $O(n^2)$ time and space with respect to sequence length. In this paper, we demonstrate that the self-attention mechanism can be approximated by a low-rank matrix. We further exploit this finding to propose a new self-attention mechanism, which reduces the overall self-attention complexity from $O(n^2)$ to $O(n)$ in both time and space. The resulting linear transformer, the \textit{Linformer}, performs on par with standard Transformer models, while being much more memory- and time-efficient.

View on arXivView PDF

Code Implementations(1)

PyTorchMIT

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

32,2136,667C++, LuaAug 29, 20171 years agoMIT
artificial-intelligencepythonpytorch

Similar Papers

Cite this paper

@article{wang2020linformer,
  title  = {Linformer: Self-Attention with Linear Complexity},
  author = {Sinong Wang and Belinda Z. Li and Madian Khabsa and Han Fang and Hao Ma},
  year   = {2020},
  eprint = {2006.04768},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2006.04768}
}

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/2006.04768.svg)](https://codeofpaper.com/paper/2006.04768)

Discussion