RoFormer: 增强型 Transformer 与旋转位置嵌入

RoFormer: Enhanced Transformer with Rotary Position Embedding

苏剑林 Jianlin Su · Zhuiyi Technology · 2021-04-20 · arXiv:2104.09864 ↗ · 被引 5727

打开互动全文版(逐段中英对照 + 图/公式 + 论文问答)→

摘要 · Abstract

位置编码在 Transformer 架构中已被证明有效,它能为序列中不同位置的元素之间的依赖建模提供有价值的监督。本文首先研究了将位置信息整合到基于 Transformer 的语言模型学习过程中的各种方法。然后,我们提出了一种名为旋转位置嵌入(RoPE)的新方法,以有效利用位置信息。具体来说,所提出的 RoPE 通过旋转矩阵编码绝对位置,同时在自注意力公式中融入显式的相对位置依赖。值得注意的是,RoPE 具有有价值的特性,包括序列长度的灵活性、随着相对距离增加而衰减的令牌间依赖,以及为线性自注意力配备相对位置编码的能力。最后,我们在各种长文本分类基准数据集上评估了带有旋转位置嵌入的增强型 Transformer,也称为 RoFormer。我们的实验表明,它始终优于其他替代方案。此外,我们提供了理论分析来解释一些实验结果。RoFormer 已集成到 Huggingface 中:\url{https://huggingface.co/docs/transformers/model_doc/roformer}。

Position encoding recently has shown effective in the transformer architecture. It enables valuable supervision for dependency modeling between elements at different positions of the sequence. In this paper, we first investigate various methods to integrate positional information into the learning process of transformer-based language models. Then, we propose a novel method named Rotary Position Embedding(RoPE) to effectively leverage the positional information. Specifically, the proposed RoPE encodes the absolute position with a rotation matrix and meanwhile incorporates the explicit relative position dependency in self-attention formulation. Notably, RoPE enables valuable properties, including the flexibility of sequence length, decaying inter-token dependency with increasing relative distances, and the capability of equipping the linear self-attention with relative position encoding. Finally, we evaluate the enhanced transformer with rotary position embedding, also called RoFormer, on various long text classification benchmark datasets. Our experiments show that it consistently overcomes its alternatives. Furthermore, we provide a theoretical analysis to explain some experimental results. RoFormer is already integrated into Huggingface: \url{https://huggingface.co/docs/transformers/model_doc/roformer}.

核心贡献 · Key contributions

局限 · Limitations

论文章节 · Sections(共 17)

阅读逐段中英对照全文 →