arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.01951cs.LG
收藏

论Transformer中位置偏置的涌现

On the Emergence of Position Bias in Transformers

MIT IDSS \& LIDS;MIT CSAIL

Xinyi Wu, Yifei Wang, Stefanie Jegelka, Ali Jadbabaie

AI总结:

本文提出图论框架分析多层attention中的位置偏置,揭示causal masking对早期位置的固有偏向及其与相对位置编码的竞争效应,为理解transformer位置偏置和指导架构设计提供了理论基础。

摘要:

近期研究揭示了transformer架构中位置偏置的各种表现形式,从“lost-in-the-middle”现象到attention sinks,但对attention masks和位置编码如何塑造这些偏置的全面理论理解仍然缺乏。本文提出了一个图论框架来分析多层attention中的位置偏置。我们将attention masks建模为有向图,量化了token如何基于其序列位置与上下文信息进行交互。我们揭示了两个关键见解:首先,causal masking本质上将注意力偏向较早的位置,因为较深层的token会关注早期token日益增多的上下文化表示。其次,我们刻画了causal mask与相对位置编码(如decay mask和旋转位置编码(RoPE))之间的竞争效应:尽管这两种机制在单个注意力图中引入了基于距离的衰减,但它们在多个注意力层中的聚合效应——加上causal mask——导致了长期衰减效应与早期序列位置累积重要性之间的权衡。通过受控的数值实验,我们不仅验证了理论发现,还重现了在真实LLMs中观察到的位置偏置。我们的框架为理解transformer中的位置偏置提供了有原则的基础,阐明了注意力机制组件之间的复杂相互作用,并指导更明智的架构设计。

英文摘要:

Recent studies have revealed various manifestations of position bias in transformer architectures, from the "lost-in-the-middle" phenomenon to attention sinks, yet a comprehensive theoretical understanding of how attention masks and positional encodings shape these biases remains elusive. This paper presents a graph-theoretic framework for analyzing position bias in multi-layer attention. Modeling attention masks as directed graphs, we quantify how tokens interact with contextual information based on their sequential positions. We uncover two key insights: First, causal masking inherently biases attention toward earlier positions, as tokens in deeper layers attend to increasingly more contextualized representations of earlier tokens. Second, we characterize the competing effects of the causal mask and relative positional encodings, such as the decay mask and rotary positional encoding (RoPE): while both mechanisms introduce distance-based decay within individual attention maps, their aggregate effect across multiple attention layers$\unicode{x2013}$coupled with the causal mask$\unicode{x2013}$leads to a trade-off between the long-term decay effects and the cumulative importance of early sequence positions. Through controlled numerical experiments, we not only validate our theoretical findings but also reproduce position biases observed in real-world LLMs. Our framework offers a principled foundation for understanding positional biases in transformers, shedding light on the complex interplay of attention mechanism components and guiding more informed architectural design.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑