EulerFormer: Sequential User Behavior Modeling with Complex Vector Attention

Zhen Tian, Wayne Xin Zhao, Changwang Zhang, Xin Zhao 0018, Zhongrui Ma, Ji-Rong Wen

Introduction

In the realm of sequential recommendation, the order of user interactions is as critical as the items themselves. While Transformer architectures have become the standard for capturing these dependencies, they are inherently permutation-equivariant. To understand sequence, they rely on positional encodings. Current state-of-the-art methods, such as Rotary Position Embedding (RoPE), attempt to integrate position by rotating query and key vectors. However, these methods often suffer from a "mathematical mismatch": they model semantic similarity using dot products while modeling positional relationships through rotation angles. This inconsistency can hinder a model's ability to adapt to the noisy, high-variance nature of user behavior data.

EulerFormer addresses this gap by introducing a unified mathematical framework. By modeling both semantic and positional information as rotations in a complex vector space using Euler’s formula, EulerFormer provides a more robust and expressive approach to sequential modeling.

The EulerFormer Framework

EulerFormer reimagines the attention mechanism by shifting from real-valued embeddings to complex-valued representations. The core of the approach rests on three primary innovations:

1. Euler Transformation

Instead of standard embeddings, EulerFormer transforms tokens into polar-form complex vectors ($Ae^{i\theta}$). By leveraging Euler’s formula, the dot-product attention mechanism becomes mathematically equivalent to a complex rotation. This unification allows the model to process "what" an item is and "where" it is located within the same mathematical language.

2. Adaptive Rotation Mechanism

While RoPE uses a fixed rotation based on position, EulerFormer introduces a learnable adaptation function. This function dynamically adjusts semantic rotation angles based on the specific context of the sequence. This flexibility allows the model to balance the relative importance of item semantics versus sequence position, which is particularly useful in noisy datasets where the strict order might be less informative than the items themselves.

3. Phase Contrastive Learning

Transformer models often suffer from anisotropy, a phenomenon where hidden representations collapse into a narrow cone, making them difficult to distinguish. To combat this, the authors propose a Phase Contrastive Learning task. By forcing the model to spread the "phases" (angles) of items more uniformly across the complex plane, the model maintains high-resolution distinctions between different user interactions without distorting the semantic magnitude (modulus) of the vectors.

Theoretical Advantages

Beyond empirical performance, EulerFormer offers several theoretical strengths:

  • Generalization of RoPE: The authors demonstrate that RoPE is a restricted, special case of EulerFormer. By adding learnable scales and biases, EulerFormer provides the flexibility that RoPE lacks.
  • Guaranteed Long-Term Decay: A critical property for sequence models is the ability to prioritize recent interactions over distant ones. EulerFormer provides a theoretical guarantee of long-term decay, ensuring that the model can effectively ignore distant "noise" in long user histories.
  • Efficiency: Despite the shift to complex mathematics, EulerFormer maintains a linear complexity of $O(Nd)$. This ensures it remains as computationally efficient as standard Transformers and significantly faster than complex relative encoding methods like XLNet.

Empirical Evaluation

The model was evaluated across four diverse datasets: MovieLens (1M & 20M), Yelp2022, and Amazon_Books. To test its versatility, EulerFormer was integrated into several popular backbone architectures, including SASRec, BERT4Rec, and CORE.

Key Results

  • Consistent Accuracy Gains: On the MovieLens-1M dataset, EulerFormer improved the NDCG@10 of the SASRec backbone by 9.93% and the Mean Reciprocal Rank (MRR) by 12.64%.
  • Robustness in Sparse Data: EulerFormer consistently outperformed RoPE across all benchmarks, with the most significant gains observed in the sparser Yelp and Amazon datasets.
  • Long-Range Dependencies: The model showed its greatest strength in processing long sequences (users with >200 interactions), validating its superior handling of long-term decay and positional information.

Conclusion and Future Work

EulerFormer represents a significant step forward in unifying semantic and positional information for sequential recommendation. By grounding attention in complex vector space, it overcomes the expressive limitations of previous rotation-based methods.

While currently focused on user behavior, the potential for EulerFormer extends to other sequential domains. Future research may explore its application in Natural Language Processing (NLP) and time-series forecasting, as well as investigating its efficacy in "cold-start" scenarios where interaction data is limited.

Summary updated

BibTeX
@inproceedings{tian2024eulerformer,
  author = {Zhen Tian and Wayne Xin Zhao and Changwang Zhang and Xin Zhao and Zhongrui Ma and Ji-Rong Wen},
  title = {{EulerFormer: Sequential User Behavior Modeling with Complex Vector Attention}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2024},
}
Figure