相对位置编码让模型泛化更长序列,绝对编码则只能记忆训练长度。
Relative Positions Generalize, Absolute Positions Memorize: An Implicit-Bias Account of Length Generalization in Attention

- 用隐式偏差解释注意力模型的长度外推能力差异。
- 旋转编码使注意力仅依赖相对位置,自然实现外推;绝对编码则固定在训练范围内的某位置。
- 适用于研究模型泛化、注意力机制或想理解大模型为何能处理超长文本的人。
使用相对位置编码的Transformer通常能外推到训练时未见的更长序列,而使用可学习绝对位置编码的Transformer则通常不能。这一现象已被反复验证,以往解释多集中于表达能力——即是否存在可外推的解。本文从优化角度出发,在一个最小化的固定偏移检索任务中揭示:梯度下降选择的解取决于注意力头的隐式偏差。我们证明,旋转编码使注意力得分仅依赖相对偏移,具有精确等变性,因此训练阶段学到的选择规则可在任意更长序列上直接复现。而可学习的绝对编码对超出范围的位置无约束,训练后注意力头会锁定在训练区间内的固定绝对位置。我们进一步将学到的旋转规则表征为与目标偏移对齐的低秩“载体”核,并推导出精度随长度衰减的注意力稀释定律,实验结果在不同随机种子和偏移量下均得到验证。线性注意力对照实验表明该机制特异于Softmax归一化:若无归一化,训练会选择最小范数插值解,无法外推。该现象、等变性和载体结构在全序列长度泛化任务的多层多头变压器中同样成立。该解释连接了注意力的隐式偏差、循环模型的外推隐式偏差,以及RASP-L猜想的学习层面。
原文摘要 · Abstract (English)
Transformers with relative positional encodings often extrapolate to sequences longer than those seen during training, whereas transformers with learned absolute encodings typically do not. This is a robust empirical regularity, and the explanations offered for it so far are chiefly about expressivity, that is, about whether a length-generalizing solution exists. We give an optimization explanation. On a minimal fixed-offset retrieval task that isolates positional selection, the gap is governed by the implicit bias of the trained attention head: among the many solutions that fit short sequences, which one gradient descent actually selects. We prove that rotary encodings make the attention logit a function of relative offset alone, an exact equivariance, so whatever selection rule is learned at training lengths is reproduced verbatim at every longer length. Learned absolute encodings instead leave out-of-range positions unconstrained, and the trained head pins to a fixed absolute position inside the training range. We characterize the learned rotary rule as a low-rank ``carrier'' kernel aligned with the target offset, and we derive the resulting graceful accuracy decay as an attention-dilution law; both predictions are confirmed across seeds and offsets. A linear-attention control shows the mechanism is specific to softmax: without normalization, training selects a min-norm interpolant that does not extrapolate. The phenomenon, the equivariance, and the carrier all transfer to a multi-layer, multi-head transformer trained on a full-sequence length-generalization task. The account connects the implicit bias of attention, implicit bias for extrapolation in recurrent models, and the learning side of the RASP-L conjecture.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。