cosFormer: Rethinking Softmax in Attention
By Zhen Qin, Weixuan Sun, Huicai Deng, Dongxu Li, Yunshen Wei, Baohong Lv, Junjie Yan, Lingpeng Kong, Yiran Zhong. International Conference on Learning Representations, 2022
331 citations recorded by the source corpus.
Transformer has shown great successes in natural language processing, computer vision, and audio processing. As one of its core components, the softmax attention helps to capture long-range dependencies yet prohibits its scale-up due to the quadratic space and time complexity to the sequence length. Kernel methods are often adopted to reduce the complexity by approximating the softmax operator. Nevertheless, due to the approximation errors, their performances vary in different tasks/corpus and suffer crucial performance drops when compared with the vanilla softmax attention. In this paper, we propose a linear transformer called cosFormer that can achieve comparable or better accuracy to the vanilla transformer in both casual and cross attentions. cosFormer is based on two key properties of softmax attention: i). non-negativeness of the attention matrix; ii). a non-linear re-weighting scheme that can concentrate the distribution of the attention matrix. As its linear substitute, cosFormer fulfills these properties with a linear operator and a cosine-based distance re-weighting mechanism. Extensive experiments on language modeling and text understanding tasks demonstrate the effectiveness of our method. We further examine our method on long sequences and achieve state-of-the-art performance on the Long-Range Arena benchmark. The source code is available at https://github.com/OpenNLPLab/cosFormer.
Subfields: Computer Vision and Pattern Recognition
View Paper: https://www.semanticscholar.org/paper/c49ac1f916d6d2edeb187e6619c8d23acd95eb21
How researchers see this paper
The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.
In Computer Vision and Pattern Recognition
Citations in the corpus
- Long Range Language Modeling via Gated State Spaces (2022, methodology): “This idea is the underlying principle behind methods such as the Performer [Choromanski et al., 2021], Linear Attention [Katharopoulos et al., 2020], Random Feature Attention [Peng et al., 2021] or cosFormer [Qin et al., 2022].”
- Structure-Aware Transformer for Graph Representation Learning (2022, background): “Another important area for future work is to focus on reducing the high memory cost and time complexity of the self-attention computation, as is being done in recent efforts for developing a so-called linear transformer, which has linear complexity in both time and space requirements (Tay et al., 20”
- FLatten Transformer: Vision Transformer using Focused Linear Attention (2023, background): “Although enjoying linear computational complexity, various previous works have also proved that simply replacing Softmax attention with linear attention usually results in severe performance drop [34, 2, 7, 27].”
- Spike-driven Transformer (2023, methodology): “13 can also be written as: In this view, Eq.14 is a linear attention [23, 62] whose computational complexity is linear in token number N because K S and V S can participate in calculate first.”
- Spikformer: When Spiking Neural Network Meets Transformer (2022, methodology): “For example, in Performer (Choromanski et al., 2020), positive random feature is adopted to approximate softmax; CosFormer (Qin et al., 2022) replaces softmax with ReLU and cosine function.”
- LongCoder: A Long-Range Pre-trained Language Model for Code Completion (2023, background): “CosFormer (Qin et al., 2022) proposes a linear operator and a cosine-based distance re-weighting mechanism as the substitute for softmax attention.”
- Quasi Linear Kernel Attention with Infinite Capacity (2026, unknown): “The FFM idea was refined by Choro-manski et al. (2021); Peng et al. (2021); Qin et al. (2022) with feature maps tailored to the softmax kernel and by Schlag et al. (2021), who increased the feature dimension L after recognizing that it caps the attention capacity.”