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

Algebraic Positional Encodings

Konstantinos Kogkalidis, Jean-Philippe Bernardy, Vikas Garg

Introduction

Standard Transformer models are inherently "permutation invariant"—they process input data as an unordered bag of tokens. To inject a sense of order, researchers rely on positional encodings (PE). However, most existing PE methods, such as classic sinusoidal waves or modern rotary encodings, are either ad hoc heuristics or strictly tailored to one-dimensional sequences. When applied to more complex data geometries like the hierarchical structure of a computer program (trees) or the spatial layout of an image (grids), these sequential methods often fail to capture the underlying relationships.

Algebraic Positional Encodings (APE) addresses this gap by providing a unified, "theory-first" framework. By treating positions as elements of mathematical groups and representing them as orthogonal matrix operators, APE naturally extends beyond simple sequences to handle complex structures with state-of-the-art performance.

Methodology: A Group-Theoretic Approach

The core innovation of APE lies in using Group Theory to define the "syntax" of a data domain. The authors propose mapping positions to the orthogonal group $O(d)$—a set of matrices that perform rotations and reflections while preserving vector lengths.

Key technical components of this framework include:

  • Homomorphic Mapping: Positions are interpreted as orthogonal operators. Moving from one position to another is mathematically equivalent to multiplying by a specific matrix.
  • Relative Positioning: Because these operators form a mathematical group, the relative path between any two tokens is simply the product of their individual position matrices (with one inverted).
  • Unified Implementation: The framework adapts to various structures by changing the underlying group definition:
  • Sequences: Modeled as a group with a single generator (isomorphic to integers $\mathbb{Z}$).
  • Trees: Modeled as a free group with multiple generators, assigning one for each branching direction.
  • Grids: Modeled as a "direct sum" of sequential groups, assigning one for each spatial axis.
Relative paths on binary branching trees computed via matrix multiplication.

Key Insights and Theoretical Advantages

APE offers several theoretical and practical advantages over traditional positional encodings:

  1. Generalizing RoPE: The authors mathematically prove that the widely used Rotary Positional Encoding (RoPE) is a specific, fixed-parameter instance of sequential APE. APE generalizes this concept, allowing the model to learn the optimal rotation angles rather than relying on fixed heuristics.
  2. Structure Preservation: Because the encodings are derived directly from the algebraic properties of the domain, the Transformer is forced to respect the data's geometry. For example, the model inherently understands that moving "left" then "right" in a tree yields a different position than moving "right" then "left".
  3. Stability by Design: By utilizing orthogonal matrices, APE ensures that positional transformations do not cause the norms of hidden representations to explode or vanish, leading to highly stable training dynamics.
A 2D grid where each axis contributes a separable factor to the attention score.

Experimental Results

The authors evaluated APE across 13 different experimental setups spanning three distinct structural domains, consistently matching or outperforming strong, specialized baselines without the need for extensive hyper-parameter tuning.

  • Sequence Transduction: On the standard WMT14 EN→DE machine translation benchmark, APE achieved a BLEU score of 23.93. This significantly outperformed vanilla Sinusoidal (14.57) and Absolute (22.09) encodings, performing on par with heavily tuned RoPE.
  • Tree Transduction: In complex algorithmic tasks on binary trees (such as copying, rotation, and expression reduction), tree-structured APE frequently achieved near-perfect perplexity (1.00). In contrast, sequential baselines struggled to capture the hierarchy, often exceeding a perplexity of 20.00.
  • Image Recognition: Testing 2D grid encodings on CIFAR-10 using a Compact Convolutional Transformer, grid-structured APE reached 94.67% accuracy, surpassing both 2D Sinusoidal (92.79%) and standard Absolute encodings (92.68%).

Limitations and Future Work

While highly effective, APE does present some computational overhead. For very deep or complete trees, recomputing positional encodings for every batch can be slower than sequential methods, as it currently requires explicit loops rather than optimized logarithmic-time operations.

Future work will focus on expanding the scope of algebraic groups to encompass more complex constructions, such as those found in graphs or non-Euclidean geometries. Additionally, scaling APE to test its viability on massive Large Language Models (LLMs) remains an exciting open direction.

Summary updated

BibTeX
@inproceedings{kogkalidis2024algebraic,
  author = {Konstantinos Kogkalidis and Jean-Philippe Bernardy and Vikas Garg},
  title = {{Algebraic Positional Encodings}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=PfOeAKxx6i},
}
Figure