NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Linearized Relative Positional Encoding

Zhen Qin, Weixuan Sun, Kaiyue Lu, Hui Deng, Dongxu Li, Xiaodong Han, Yuchao Dai, Lingpeng Kong, Yiran Zhong

Abstract: Relative positional encoding is widely used in vanilla and linear transformers to represent positional information. However, existing encoding methods of a vanilla transformer are not always directly applicable to a linear transformer, because the latter requires a decomposition of the query and key representations into separate kernel functions. Nevertheless, principles for designing encoding methods suitable for linear transformers remain understudied. In this work, we put together a variety of existing linear relative positional encoding approaches under a canonical form and further propose a family of linear relative positional encoding algorithms via unitary transformation. Our formulation leads to a principled framework that can be used to develop new relative positional encoding methods that preserve linear space-time complexity. Equipped with different models, the proposed linearized relative positional encoding (LRPE) family derives effective encoding for various applications. Experiments show that compared with existing methods, LRPE achieves state-of-the-art performance in language modeling, text classification, and image classification. Meanwhile, it emphasizes a general paradigm for designing broadly more relative positional encoding methods that are applicable to linear transformers.

Introduction

Standard Transformers have revolutionized sequence modeling but face a significant "quadratic bottleneck": their attention mechanism scales at $O(n^2)$ relative to sequence length $n$. Linear Transformers address this by utilizing kernel functions to decompose the attention matrix, reducing complexity to $O(n)$.

However, incorporating Relative Positional Encoding (RPE)—essential for capturing the distance between tokens—into Linear Transformers is non-trivial. Most RPE methods, such as Rotary Positional Encoding (RoPE), were designed for vanilla Transformers and break the mathematical decomposition required for linear efficiency. Consequently, many Linear Transformers have historically relied on less effective absolute positional encodings, sacrificing performance for scalability.

Comparison of quadratic complexity in standard RPE vs. linear complexity in LRPE.

Methodology: The LRPE Framework

This research introduces Linearized Relative Positional Encoding (LRPE), a principled framework that unifies existing methods under a canonical mathematical form. The core innovation lies in the requirement for the positional matrix ($W_{t-s}$) to be decomposable into separate components for the query and key ($M_s^H M_t$). The authors prove that for this decomposition to maintain $O(n)$ complexity while preserving relative information, the transformation must be unitary (or orthogonal in the real domain).

Based on this principle, the LRPE family includes three types:

  1. Type 1 (Unitary): Operates in the complex domain.
  2. Type 2 (Orthogonal): Uses rotation matrices in the real domain, generalizing the popular RoPE method.
  3. Type 3 (Permutation): Based on index shifting, inspired by PermuteFormer.

To optimize these transformations, the authors employ a Householder matrix to project token features into a coordinate system where rotations or permutations are most effective, significantly outperforming simple identity-matrix projections.

Experimental Results

The LRPE framework was evaluated across diverse benchmarks, including WikiText-103 for language modeling, GLUE for text classification, and ImageNet-1k for image recognition.

Performance Gains

LRPE consistently outperformed both baseline Linear Transformers and standard RoPE. On the GLUE CoLA task, LRPE (Type 2) achieved a score of 49.61, a substantial improvement over RoPE's 39.23. In language modeling, LRPE Type 1 achieved a Perplexity (PPL) of 31.60, compared to the baseline's 33.67.

Language modeling performance (Perplexity) of LRPE compared to Base, RoPE, and PER over training steps.

Efficiency and Robustness

While LRPE introduces a minor computational overhead (10-18% slower training than a no-positional baseline), it maintains strict $O(n)$ space-time complexity. Furthermore, LRPE demonstrated superior robustness on the Long-Range Arena (LRA) benchmark, proving its efficacy for the long-sequence tasks that Linear Transformers are designed to solve. Unlike absolute encodings, LRPE also supports length extrapolation, allowing models to handle sequences longer than those encountered during training.

Conclusion

LRPE provides a general paradigm for designing relative positional encoding methods compatible with linear attention. By identifying the unitary requirement for decomposability, this work bridges the gap between the efficiency of Linear Transformers and the representational power of relative positioning. Future work may extend this framework to multi-dimensional data such as 3D point clouds.

Summary updated

BibTeX
@article{qin2023linearized,
  author = {Zhen Qin and Weixuan Sun and Kaiyue Lu and Hui Deng and Dongxu Li and Xiaodong Han and Yuchao Dai and Lingpeng Kong and Yiran Zhong},
  title = {{Linearized Relative Positional Encoding}},
  journal = {Accepted by TMLR},
  year = {2023},
  url = {https://openreview.net/forum?id=xoLyps2qWc},
}
Figure