arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2202.08791cs.CL
收藏

cosFormer:重新思考Softmax的注意力

cosFormer: Rethinking Softmax in Attention

SenseTime Research(商汤科技研究院);Shanghai AI Laboratory(上海人工智能实验室);Australian National University(澳大利亚国立大学);Northwestern Polytechnical University(西北工业大学);The University of Hong Kong(香港大学)

Zhen Qin, Weixuan Sun, Hui Deng, Dongxu Li, Yunshen Wei, Baohong Lv, Junjie Yan, Lingpeng Kong, Yiran Zhong

摘要:

Transformer在自然语言处理、计算机视觉和音频处理方面取得了巨大的成功。作为其核心组件之一,softmax attention有助于捕获长范围依赖关系,但由于序列长度的二次空间和时间复杂度,它阻止了其扩展。核方法通常通过近似softmax算子来降低复杂度。然而,由于近似误差,它们的性能在不同的任务/语料库中有所不同,并且与vanilla softmax attention相比,它们的性能下降了。在本文中,我们提出了一个线性的Transformer称为cosFormer,可以实现可比或更好的准确性香草Transformer在休闲和交叉关注。cosFormer基于softmax attention的两个关键属性:i)。注意力矩阵的非负性; ii).一种非线性的重新加权方案,可以集中注意力矩阵的分布。作为其线性替代品,cosFormer通过线性算子和基于余弦的距离重新加权机制来实现这些属性。语言建模和文本理解任务的大量实验证明了我们的方法的有效性。我们进一步研究了我们的方法对长序列和实现国家的最先进的性能上的远程竞技场基准。源代码可在https://github.com/OpenNLPLab/cosFormer上获得。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑