Introduction
The self-attention mechanism, central to the Transformer architecture, is inherently permutation invariant. To process sequences effectively, models require explicit positional information. Existing solutions typically fall into two categories: Learnable Lookup Tables (Absolute Position Encodings, APE) and Expert-Designed Methods (e.g., RoPE, ALiBi). While APE is flexible but fails to extrapolate to longer sequences, expert-designed methods offer better extrapolation but are often rigid and difficult to adapt to multi-dimensional data like images or video.
This paper introduces SeqPE (Sequential Position Encoding), a unified, learnable framework that treats position indices as symbolic sequences. By processing these sequences with a lightweight encoder, SeqPE achieves superior extrapolation and seamless multi-modal adaptation.
Methodology
The core of SeqPE is the conceptualization of position indices as sequences of digits. For instance, a 1D position index "123" is represented as the sequence [0, 1, 2, 3]. In multi-dimensional contexts, coordinates are concatenated into a single sequence.
Sequential Position Encoder ($\mathcal{E}$)
A small, two-layer Transformer encoder, denoted as $\mathcal{E}$, processes these digit sequences to generate position embeddings. Unlike lookup tables that memorize specific IDs, $\mathcal{E}$ learns the underlying logic of numbering, allowing it to produce embeddings for previously unseen positions.
Regularization Strategies
To ensure robust learning, the authors introduce two key regularization losses:
- Distance Regularization ($\mathcal{L}_\delta$): Prevents the model from falling into "lexical traps" where numerically distant but string-similar indices (e.g., 100 and 1000) are mapped too closely. This loss aligns embedding distances with actual numerical distances.
- Out-of-Distribution (OOD) Regularization ($\mathcal{L}_{OOD}$): Uses knowledge distillation to anchor embeddings of extremely high position numbers to the patterns established during training, ensuring stability during long-context extrapolation.
Experimental Setup
SeqPE was evaluated across three diverse domains:
- Language Modeling: Models were trained on Wikitext-103 with a 512-token context and tested on lengths up to 16,384.
- Long-context QA: Fine-tuning on SQuAD-based data was followed by evaluation on the RULER benchmark.
- Image Classification: A Vision Transformer (ViT) was trained on ImageNet-1K at $224 \times 224$ resolution and tested at resolutions up to $672 \times 672$.
Results and Discussion
Superior Extrapolation in Language Modeling
SeqPE demonstrates remarkable stability as sequence length increases. While traditional methods like RoPE show performance degradation at extreme lengths, SeqPE maintains a low average perplexity of 18.95, outperforming ALiBi (19.54) and significantly beating RoPE variants.
Long-Context Reasoning and Vision Scaling
In long-context QA tasks, SeqPE maintained stable performance up to 8K tokens, achieving a 2.6-point improvement in Exact Match (EM) over the strongest baseline. In the vision domain, SeqPE generalized to high-resolution spatial layouts ($672 \times 672$) more effectively than specialized mathematical biases like RoPE2D, confirming its modality-agnostic advantages.
Conclusion
SeqPE reimagines position encoding by treating indices as a language of digits. This approach provides a learnable, unified framework that excels in extrapolation and multi-modal tasks. Future work will focus on optimizing inference overhead and exploring complex distance functions for interleaved multi-modal data.
Summary updated