AI Skills AI技能 8h ago Updated 4h ago 更新于 4小时前 47

One Formula to Map the Positional Encoding Landscape 一个公式映射位置编码全景

Positional encoding techniques can be unified by identifying three injection points in the attention equation: additive to embeddings (yellow), transformation of queries/keys (blue), or bias on attention scores before softmax (pink) A 2×2 grid classifying methods by absolute vs. relative and fixed vs. learned collapses the entire landscape of positional encoding approaches into four quadrants RoPE and ALiBi, often presented as rivals, are revealed as conceptual siblings: both avoid modifying tok 位置编码的本质问题是:位置信息应在注意力计算的哪个阶段注入 提出三种注入方式:添加到输入嵌入(黄色)、变换查询/键矩阵(蓝色)、在softmax前添加偏置(粉色) 建立2×2分类网格:绝对vs相对位置 × 固定vs可学习编码,可涵盖所有主流方法 RoPE和ALiBi虽常被视作竞争方案,实则同属"相对+固定"类别,均不修改输入嵌入 近年趋势是从左上角(绝对+固定)向右列(相对位置)迁移,位置信息从嵌入层进入注意力计算层

62
Hot 热度
76
Quality 质量
65
Impact 影响力

Analysis 深度分析

TL;DR

  • Positional encoding techniques can be unified by identifying three injection points in the attention equation: additive to embeddings (yellow), transformation of queries/keys (blue), or bias on attention scores before softmax (pink)
  • A 2×2 grid classifying methods by absolute vs. relative and fixed vs. learned collapses the entire landscape of positional encoding approaches into four quadrants
  • RoPE and ALiBi, often presented as rivals, are revealed as conceptual siblings: both avoid modifying token embeddings and instead inject position directly into attention computations
  • The field has trended steadily from the top-left quadrant (fixed + absolute, e.g., sinusoidal embeddings) toward the right column (relative methods), driven by superior length extrapolation capabilities
  • The original Transformer added positional encoding exactly once at the input as fixed sinusoidal vectors, but later research questioned both the single-injection and sinusoidal design choices

Why It Matters

This framework gives AI practitioners a unified mental model for understanding and comparing positional encoding methods, rather than treating them as an isolated parade of papers. By mapping techniques to injection points and quadrants, researchers can make more informed architectural decisions when designing or modifying transformer models for specific tasks or sequence lengths.

Technical Details

  • Three injection points in the expanded attention formula: Yellow region = additive positional embeddings (sinusoidal/learned absolute); Blue region = query/key rotation or transformation (RoPE, relative position embeddings); Pink region = scalar bias added to attention scores before softmax (ALiBi, T5 learned relative bias)
  • 2×2 classification grid: Absolute vs. Relative (axis 1) crossed with Fixed vs. Learned (axis 2), producing four quadrants: fixed+absolute (sinusoidal), learned+absolute (BERT, GPT-2), learned+relative (Transformer-XL, T5), fixed+relative (RoPE, ALiBi)
  • RoPE mechanism: Rotates queries and keys by position-dependent angles; the dot product between query at position m and key at position n depends only on the relative offset (m−n)θ, achieving relative position encoding without trainable parameters
  • ALiBi mechanism: Adds a hand-crafted linear bias b_mn = −slope · |m−n| to raw attention scores, creating built-in recency bias that enables length extrapolation beyond training sequence lengths
  • Key insight: Methods in the blue and pink regions share the philosophy that positional and semantic information should remain separate, leaving word embeddings untouched and modifying attention weights at every layer instead

Industry Insight

  • The migration toward relative positional encoding (RoPE, ALiBi) reflects a strategic shift prioritizing length extrapolation and inference-time flexibility, making these approaches essential for production LLMs handling variable-length inputs
  • Practitioners should consider the injection point when debugging model performance: if extrapolation to longer sequences is critical, blue/pink region methods (RoPE, ALiBi) outperform traditional additive embeddings; if training efficiency with fixed-length sequences is paramount, learned absolute embeddings remain competitive
  • The unified framework suggests that novel positional encoding methods should be evaluated along two dimensions—injection point and grid quadrant—rather than as standalone innovations, accelerating both analysis and design of future architectures

TL;DR

  • 位置编码的本质问题是:位置信息应在注意力计算的哪个阶段注入
  • 提出三种注入方式:添加到输入嵌入(黄色)、变换查询/键矩阵(蓝色)、在softmax前添加偏置(粉色)
  • 建立2×2分类网格:绝对vs相对位置 × 固定vs可学习编码,可涵盖所有主流方法
  • RoPE和ALiBi虽常被视作竞争方案,实则同属"相对+固定"类别,均不修改输入嵌入
  • 近年趋势是从左上角(绝对+固定)向右列(相对位置)迁移,位置信息从嵌入层进入注意力计算层

为什么值得看

本文提供了一个统一的理论框架来理解位置编码的演进,帮助从业者跳出"按时间线罗列方法"的碎片化认知,建立系统化的设计空间地图。对模型架构研究者而言,该框架可直接指导新位置编码方案的设计与分类。

技术解析

  • 三种注入位置:黄色区域(输入嵌入加法)对应原始Transformer的正弦编码及BERT/GPT-2的可学习嵌入;蓝色区域(Q/K变换)对应RoPE的旋转操作和Shaw等人的相对位置嵌入;粉色区域(注意力分数偏置)对应ALiBi的线性衰减偏置和T5的可学习相对偏置
  • RoPE机制:通过对查询和键向量施加与位置相关的旋转,使注意力分数q_m·k_n^T自然依赖相对位置(m-n)θ,无需额外参数
  • ALiBi机制:在softmax前添加手crafted的线性偏置b_mn = -slope·|m-n|,产生内置的近期偏好,是其优秀长度外推能力的核心
  • 2×2网格分类:左上(绝对+固定)= 正弦编码;右上(相对+固定)= RoPE/ALiBi;左下(绝对+可学习)= BERT/GPT-2;右下(相对+可学习)= Transformer-XL/T5
  • 设计趋势:现代LLM普遍采用相对+固定方案,避免位置参数训练,同时获得更好的长度外推性能

行业启示

  • 位置编码设计应从"注入点+编码类型"两个正交维度系统思考,而非简单比较方法优劣
  • 相对位置编码配合固定/无参数方案(如RoPE、ALiBi)已成为大模型主流选择,兼顾性能与外推能力
  • 新位置编码方案可快速通过本文框架定位,避免重复探索已知设计空间

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 Research 科学研究 Training 训练 Embedding Model 嵌入模型