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

A Contextual-Aware Position Encoding for Sequential Recommendation

Jun Yuan, Guohao Cai, Zhenhua Dong · DOI

TL;DR

This paper introduces CAPE, a novel Contextual-Aware Position Encoding method specifically designed for sequential recommendation (SR) systems. CAPE addresses the limitations of existing position encoding techniques by dynamically assigning positional information based on user history, leading to state-of-the-art performance improvements across various SR models and datasets, including real-world industrial deployment.

What Problem Does This Paper Address?

Modern recommendation systems heavily rely on sequential recommendation (SR) to predict user behavior based on their historical interactions. A key component in SR models is the attention mechanism, which helps synthesize user activities. However, attention mechanisms are inherently order-invariant, meaning they don't naturally account for the sequence of events. To address this, position encoding (PE) is used, but conventional methods, often borrowed from Natural Language Processing (NLP), simply assign a fixed, learnable vector to each position. This approach yields only modest gains and doesn't fully leverage the unique characteristics of SR, such as the importance of context and the need for efficient processing. The paper identifies a significant gap in research for PE methods tailored specifically to the nuances of sequential recommendation.

Methods

The core contribution of this paper is the Contextual-Aware Position Encoding (CAPE) method. CAPE tackles two main challenges:

  1. Context-Aware Dissimilarity: Instead of assigning fixed positions, CAPE first computes a "gate value" that measures the dissimilarity between the target item and each context item. This gate determines how much each context item contributes to the positional information. Then, it calculates position values by summing these gate values. This approach allows CAPE to assign similar positions to context items that are semantically related to the target item and distinct positions to unrelated ones, effectively capturing varying levels of positional abstraction.
  2. Gating and Interpolation for Fusion: Since item embeddings in SR are often heterogeneous (combining item IDs, categories, etc.) and may reside in different hidden spaces than position embeddings, a simple addition is insufficient. CAPE uses a gating architecture to fuse these heterogeneous features and align them into a common space. It then employs interpolation to efficiently generate position embeddings from these fused representations, making it computationally efficient.

CAPE is designed to be flexible and can be integrated into both target attention and self-attention mechanisms commonly used in SR.

Datasets

The authors evaluated CAPE on three widely-used public benchmark datasets for sequential recommendation:

  • AmazonElectronics: A subset of the Amazon dataset, preprocessed similarly to the DIN paper.
  • KuaiVideo: An open dataset for short video recommendations.
  • AmazonBooks: Another subset of the Amazon dataset, filtered for users with at least 5 interactions.

The paper also mentions experiments on a real-world commercial platform (Huawei AppGallery) for online A/B testing.

Key Insights and Ideas

  • SR has unique PE needs: The paper strongly argues that directly applying PE methods from NLP to SR is suboptimal due to differences in item embedding construction and attention mechanisms.
  • Dissimilarity is key for SR: Unlike similarity-based approaches, using dissimilarity to determine positional relevance for the target item proves more effective in capturing user intent in SR.
  • Efficient fusion is crucial: The proposed gating mechanism effectively handles heterogeneous item embeddings and aligns them with position embeddings, which is vital for SR models.
  • CAPE enhances scalability: The method shows promise for large-scale recommendation models, continuing to improve performance as model depth increases, unlike some baseline PE methods that degrade.
  • Real-world validation: The successful deployment and positive results from an online A/B test on a commercial platform provide strong evidence of CAPE's practical effectiveness.

Key Results

  • State-of-the-Art Performance: CAPE consistently improved the performance of various mainstream SR backbones (DIN, DIEN, BST, SASRec, DMIN) across benchmark datasets, achieving state-of-the-art results in terms of AUC and gAUC. For instance, on AmazonElectronics, CAPE achieved an AUC of 0.885698 with DIN, outperforming other PE methods.
  • Significant Improvements: In large-scale experiments with SASRec on AmazonBooks, CAPE showed an average improvement of up to 8.65% in NDCG and 4.84% in Recall compared to baselines.
  • Online A/B Testing: In a real-world A/B test on Huawei AppGallery, CAPE demonstrated a consistent daily improvement in the key metric (eCPM) of up to +6.12%, with an overall average improvement of 3.62% over the baseline.
  • Flexibility: CAPE showed effectiveness with both target attention (DIN) and self-attention (SASRec) models, highlighting its versatility.

Limitations and Future Work

  • Limitations: The paper notes that while CAPE is effective, the fusion method might be more critical for certain attention types (e.g., DIN's non-dot-product attention). The effectiveness of Naïve PE can sometimes be comparable or even better in very shallow models.
  • Future Work: The authors suggest exploring CAPE's effectiveness in multi-domain and multi-task recommendation scenarios. They also aim to conduct further theoretical research to deepen the understanding of position information in sequential recommendation.

Summary updated

BibTeX
@inproceedings{yuan2025contextual,
  author = {Jun Yuan and Guohao Cai and Zhenhua Dong},
  title = {{A Contextual-Aware Position Encoding for Sequential Recommendation}},
  booktitle = {The Web Conference},
  year = {2025},
  doi = {10.1145/3701716.3715206},
}
Figure