这篇论文用严谨的实验和理论揭示了位置与符号注意力在长度泛化上的本质差异,做Transformer机制研究或长上下文优化的开发者值得细读,看完会对RoPE的几何解释有更深理解。
这篇论文通过训练GPT-J在两种结构等价的多跳推理任务(数字任务需位置推理,字母任务需符号推理)上,研究了注意力头的学习动态。作者引入新指标将注意力头分类为位置型或符号型,发现成功学习与纯头(即只表现一种类型)的出现相关。尽管任务结构等价,但数字任务需要位置和符号两种头,而字母任务只需符号头。论文进一步揭示了这些头的计算角色,并给出基于RoPE的几何可解释构造。关键发现是符号机制在长序列上泛化更可靠,而位置机制有更明显的局限性,并通过理论和实验验证了这种分离。
Positional versus Symbolic Attention Heads: Learning Dynamics, RoPE Geometry, and Length Generalization
Transformer-based language models are widespread in today's society. As such, understanding the mechanisms by which they solve structured tasks and predicting how they may behave in novel scenarios is of great importance for safe deployment. We study the learning dynamics of attention heads in a controlled setting by training a decoder-only Transformer (GPT-J) on two structurally equivalent multi-hop reasoning tasks: a number task requiring positional reasoning and a letter task requiring symbolic reasoning. Using a recently introduced metric that classifies attention-head behavior as positional or symbolic for a given prompt, we show that successful learning is associated with the emergence of pure heads, i.e., heads that express themselves as either positional or symbolic. Despite the tasks' structural equivalence, they impose different mechanistic demands: the number task requires both positional and symbolic heads, whereas the letter task requires only symbolic heads. We then identify the computational roles of these heads, characterize the basic functions they implement, and give theoretical constructions showing how single-layer RoPE-based attention can realize these functions through geometrically interpretable query, key, and value operations. This analysis yields a quantitative separation between positional and symbolic mechanisms in their robustness to longer sequences, formalized through a novel notion of discrepancy. We empirically validate the resulting predictions in both controlled and real-world models, showing that symbolic mechanisms extrapolate more reliably to longer sequences while positional mechanisms face sharper limitations.