arXiv:2502.01951cs.LG2025-02ICML被引 62

揭示Transformer中位置偏见的根源及其形成机制。

On the Emergence of Position Bias in Transformers

  • 用图论建模注意力掩码,分析序列位置对信息交互的影响。
  • 发现深层注意力会强化早期位置的重要性,导致中间信息丢失。
  • 解释因果掩码与相对位置编码的协同作用,指导模型设计优化。

近期研究揭示了Transformer架构中多种位置偏见现象,如‘中间信息丢失’和注意力汇聚,但对注意力掩码与位置编码如何共同塑造这些偏见仍缺乏系统理论理解。本文提出一种基于图论的多层注意力位置偏见分析框架,将注意力掩码建模为有向图,量化不同位置的标记如何依赖上下文信息。研究发现:第一,因果掩码天然使注意力偏向早期位置,深层注意力逐渐聚焦于更早标记的上下文化表示;第二,因果掩码与相对位置编码(如衰减掩码、旋转位置编码RoPE)存在竞争效应:两者均在单个注意力图中引入距离衰减,但跨多层累积后,与因果掩码共同导致长期衰减与早期位置重要性之间的权衡。通过受控数值实验,我们不仅验证了理论结论,还复现了真实大模型中的位置偏见现象。该框架为理解Transformer中位置偏见提供了理论基础,揭示了注意力组件间的复杂互动,有助于更明智的架构设计。

原文摘要 · Abstract (English)

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.

Transformer位置偏见注意力机制

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。