Abstract
While Rotary Position Embeddings (RoPE) for natural language performs well and has become widely adopted, its adoption for other modalities has been slower. Here, we introduce Lie group Relative position Encodings (LieRE) that goes beyond RoPE in supporting higher dimensional inputs. We evaluate the performance of LieRE on 2D and 3D image classification tasks and observe that LieRE leads to marked improvements in performance (up to 6%), training efficiency (3.5x reduction), data efficiency (30%) compared to the baselines of RoFormer, DeiT III, RoPE-Mixed and Vision-Llama.
Introduction
Transformers are inherently permutation invariant, treating input tokens as an unordered set unless spatial or sequential information is explicitly provided. While Absolute Positional Encodings and Relative Positional Encodings like RoPE have addressed this in 1D sequences (e.g., text), extending these methods to higher dimensions remains a challenge. RoPE, specifically, utilizes fixed 2D block-diagonal rotation matrices with a predefined frequency decay. This rigid structure often fails to capture the complex spatial correlations present in 2D images or 3D video, where distant elements may retain high relevance.
Methodology
LieRE (Lie Relative Encodings) generalizes RoPE by transitioning from handcrafted, fixed rotations to learned, high-dimensional rotation matrices derived from Lie group theory. This approach allows the model to adaptively learn spatial relationships.
The core of LieRE involves three primary steps:
- Lie Algebra Basis: The model learns a basis of skew-symmetric matrices, which are elements of a Lie algebra.
- Matrix Exponential Mapping: These matrices are mapped to high-dimensional rotation matrices (Lie group elements) via the matrix exponential: $R(p) = \exp(\sum p_i A_i)$.
- Differentiable Integration: This mapping is fully differentiable, enabling the Transformer to optimize the rotation of keys and queries to best represent spatial distances during training.
By adjusting the "tile size" of these matrices, the representational capacity can be tuned. A tile size of 2 recovers a learnable variant of RoPE, while larger tiles facilitate denser, more complex spatial interactions.
Experimental Evaluation
The efficacy of LieRE was evaluated across diverse benchmarks:
- 2D Image Classification: CIFAR-100 and ImageNet-1k.
- 3D Video Classification: UCF101.
- Synthetic Spatial Reasoning: A task requiring the identification of arrow directions relative to specific anchors.
- Resolution Invariance: Assessing performance on resolutions higher than those used during training (e.g., $448 \times 448$ test vs. $224 \times 224$ train).
Results and Discussion
LieRE demonstrates significant improvements over existing positional encoding methods. On CIFAR-100, LieRE achieved 70.3% accuracy, notably higher than RoPE-Mixed (68.8%) and Absolute Encodings (63.9%). In 3D contexts, such as the UCF101 benchmark, LieRE showed a relative improvement of up to 15.1% over absolute embeddings.
Beyond raw accuracy, LieRE exhibits remarkable efficiency. Models utilizing LieRE reached the same accuracy as standard Vision Transformers (ViTs) with 3.9x less training compute. Furthermore, LieRE maintains high performance under resolution scaling, whereas baseline methods like RoPE-Mixed tend to degrade.
A key insight is the "spatial reasoning gap." Relative encodings like LieRE are fundamentally superior at spatial logic tasks compared to absolute encodings, which often struggle with complex geometric relationships. Despite its performance gains, LieRE is lightweight, adding only approximately 0.68% to the total parameter count of a ViT-Base model.
Conclusion and Future Work
LieRE provides a principled, flexible framework for positional encoding in multi-dimensional data. While currently optimized for attention-based architectures, future work could extend these Lie group principles to other structures or more complex manifolds like $SE(3)$ for robotics. Additionally, optimizing the numerical stability and speed of the matrix exponential operation remains a priority for scaling to even larger models.
Summary updated