arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2111.09714cs.LGcs.CL
收藏

你只(几乎)抽样一次:线性成本自注意力的Bernoulli抽样

You Only Sample (Almost) Once: Linear Cost Self-Attention Via Bernoulli Sampling

University of Wisconsin(威斯康星大学);University of Illinois(伊利诺伊大学);American Family Insurance(美国家庭保险公司)

Zhanpeng Zeng, Yunyang Xiong, Sathya N. Ravi, Shailesh Acharya, Glenn Fung, Vikas Singh

摘要:

基于转换器的模型广泛应用于自然语言处理(NLP)中。Transformer模型的核心是自注意力机制,它捕获输入序列中标记对的交互,并二次依赖于序列长度。在更长的序列上训练这样的模型是昂贵的。在本文中,我们证明了一个伯努利抽样注意力机制的基础上局部敏感哈希(LSH),降低了这种模型的二次复杂性线性。我们通过将自注意力视为与伯努利随机变量相关的单个令牌的总和来绕过二次成本,原则上,可以通过单个散列一次采样(尽管在实践中,这个数字可能是一个小常数)。这导致了一个有效的采样方案来估计自注意力力,这依赖于LSH的特定修改(以实现在GPU架构上的部署)。我们在具有标准512序列长度的GLUE基准上评估我们的算法,其中我们看到相对于标准预训练的Transformer的有利性能。在长距离竞技场(LRA)基准测试中,为了评估长序列的性能,我们的方法实现了与softmax自注意力一致的结果,但具有相当大的加速和内存节省,并且通常优于其他有效自注意力方法。我们的代码可在https://github.com/mlpen/YOSO上获得

英文摘要:

Transformer-based models are widely used in natural language processing (NLP). Central to the transformer model is the self-attention mechanism, which captures the interactions of token pairs in the input sequences and depends quadratically on the sequence length. Training such models on longer sequences is expensive. In this paper, we show that a Bernoulli sampling attention mechanism based on Locality Sensitive Hashing (LSH), decreases the quadratic complexity of such models to linear. We bypass the quadratic cost by considering self-attention as a sum of individual tokens associated with Bernoulli random variables that can, in principle, be sampled at once by a single hash (although in practice, this number may be a small constant). This leads to an efficient sampling scheme to estimate self-attention which relies on specific modifications of LSH (to enable deployment on GPU architectures). We evaluate our algorithm on the GLUE benchmark with standard 512 sequence length where we see favorable performance relative to a standard pretrained Transformer. On the Long Range Arena (LRA) benchmark, for evaluating performance on long sequences, our method achieves results consistent with softmax self-attention but with sizable speed-ups and memory savings and often outperforms other efficient self-attention methods. Our code is available at https://github.com/mlpen/YOSO

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

↑