“It doesn't really use them, it uses something called RoPE which is hardcoded rather than learned and is applied multiplicatively at every layer to both the key and the value.”
RoFormer: Enhanced Transformer with Rotary Position Embedding
用旋转矩阵编码绝对位置、在注意力中体现相对位置的旋转位置编码 RoPE。
论文先考察了把位置信息融入 Transformer 语言模型的各种方法,然后提出旋转位置编码(RoPE):用旋转矩阵编码绝对位置,同时在自注意力公式中显式引入相对位置依赖。RoPE 具有序列长度灵活、token 间依赖随相对距离增大而衰减、可让线性自注意力带上相对位置编码等性质。在多个长文本分类基准上,带 RoPE 的 RoFormer 持续优于对比方法,论文还给出理论分析。
评论者用它解释 LLM 如何表示位置(固定的而非学出来的),并说明 Llama 等模型依靠 RoPE 把上下文窗口扩展到训练长度之外。
学习路径
读这篇之前,按顺序读书架上的 4 篇 · 参考文献来自 OpenAlex,顺序和要点由 Claude Code 排出这条路径帮我理解 Transformer 的注意力与位置编码、BERT 和 Transformer-XL 的位置处理方式,以及线性注意力,用来读懂旋转位置编码在注意力中如何体现相对位置。
- 1
- 2
BERT 使用的是可学习的绝对位置嵌入,是目标论文对比的做法之一。
读输入表示里位置嵌入的加法方式。
- 3
Transformer-XL 提出相对位置编码,是目标论文要对比和改进的另一类做法。
读相对位置编码如何改写注意力分数的展开式。
- 4
目标论文说明 RoPE 能与线性注意力结合,需要知道线性注意力的形式。
读核特征映射代替 softmax 的线性注意力公式。
- 5RoFormer: Enhanced Transformer with Rotary Position Embedding
目标论文:用旋转矩阵编码绝对位置,在注意力内积中体现相对位置。
读二维旋转的推导、高维上的分块旋转,以及内积只依赖相对位置的性质。
HN 书评
推荐在前,同类按时间 · 每篇最多保留 20 条,统计用全部提及“Inspired largely by the RoFormer paper, I thought I'd write a post”
“The reference paper for rotary embedding is Roformer RoFormer”
“LLaMa 3 already has RoPE encoding which can handle arbitrarily long contexts (within reason)”
“the large context windows generally involve RoPE[0] which is a trick that allows the training window to be smaller but expand larger during inference.”
“But here are some notable ones, a couple of them are linked in their blog post.”
看全部 7 条 →
“I think they have a citation for it, though it might just be the RoPE paper.”