[论文解读] RoFormer: Enhanced Transformer with Rotary Position Embedding
RoFormer 引入 Rotary Position Embedding(RoPE),通过旋转矩阵编码绝对和相对位置信息,在翻译、预训练和 GLUE 任务上提升性能,并与线性注意力兼容。
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}.
研究动机与目标
- 研究如何在变换器学习中引入位置信息,超越加法的绝对编码。
- 提出 Rotary Position Embedding (RoPE),用旋转矩阵对绝对位置进行编码,并在自注意力中编码相对位置。
- 展示 RoPE 在长文本分类、机器翻译和预训练任务中的优势。
- 提供 RoPE 特性理论分析,如序列长度灵活性和距离增大时 token 之间依赖的衰减。
提出的方法
- 通过将查询与键的内积建模为嵌入和相对位置的函数来推导 RoPE。
- 使用旋转矩阵 R_Θ,m 将 f_q 和 f_k 表示为令牌嵌入的旋转仿射变换(方程 14/15)。
- 表明 q_m^T k_n 等于 (W_q x_m)^T R^d_Θ,m^T R^d_Θ,n (W_k x_n),简化为相对位置相关项(方程 16)。
- 将 RoPE 与自注意力集成,对于线性注意力,将旋转后的 Q 和 K 与非负特征映射相乘(方程 19)。
- 证明 RoPE 通过角度项 θ_i 的长期衰减,并展示高效的旋转实现(方程 15–16,34)。
- 在机器翻译(WMT14 En-De)、MLM 预训练(BERT 基线)、GLUE 微调,以及带 RoPE 的 PerFormer 上评估 RoFormer。
实验结果
研究问题
- RQ1如何使用旋转在变换器中有效地编码绝对和相对位置信息?
- RQ2RoPE 是否在翻译、语言模型和下游任务中相对于加性位置编码提升性能和收敛性?
- RQ3在不牺牲稳定性或性能的情况下,RoPE 能否高效地与线性注意力集成?
- RQ4RoPE 的理论性质(如随距离衰减)及其与自然语言结构的关系是什么?
主要发现
| 模型 | MRPC | SST-2 | QNLI | STS-B | QQP | MNLI(m/mm) |
|---|---|---|---|---|---|---|
| BERT (Devlin et al. 2019) | 89.5 | 93.5 | 90.5 | 85.8 | 71.2 | 84.6/83.4 |
| RoFormer | 89.5 | 90.7 | 88.0 | 87.0 | 86.4 | 80.2/79.8 |
- RoFormer 在 WMT 2014 English-German 翻译上比 Transformer-base 获得更高的 BLEU(BLEU:27.5 vs 27.3)。
- RoFormer 在 BookCorpus+Wikipedia 上对 MLM 预训练收敛速度快于 vanilla BERT。
- RoFormer 在微调的多项 GLUE 任务上优于 BERT(MRPC、SST-2、QNLI、STS-B、QQP、MNLI)的表现,呈现混合性提升(例如 MRPC 89.5 vs 88.9;SST-2 90.7 vs 93.5;QNLI 88.0 vs 90.5;STS-B 87.0 vs 85.8;QQP 86.4 vs 71.2;MNLI 80.2/79.8 vs 84.6/83.4)。
- RoPE 与线性注意力(PerFormer)兼容,在编码相对位置信息的同时保持其线性复杂度。
- RoPE 提供序列长度灵活性和随相对距离增加而衰减的 token 依赖,与语言结构一致。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。