Spatio-Temporal Contrastive Learning Enhanced GNNs for Session-based Recommendation

Zhongwei Wan, Benyou Wang, Xin Liu, Jiezhong Qiu, Boyu Li, Ting Guo, Guangyong Chen, Yang Wang · DOI

Abstract

Session-based recommendation (SBR) systems aim to utilize the user's short-term behavior sequence to predict the next item without the detailed user profile. Most recent works try to model the user preference by treating the sessions as between-item transition graphs and utilize various graph neural networks (GNNs) to encode the representations of pair-wise relations among items and their neighbors. Some of the existing GNN-based models mainly focus on aggregating information from the view of spatial graph structure, which ignores the temporal relations within neighbors of an item during message passing and the information loss results in a sub-optimal problem. Other works embrace this challenge by incorporating additional temporal information but lack sufficient interaction between the spatial and temporal patterns. To address this issue, inspired by the uniformity and alignment properties of contrastive learning techniques, we propose a novel framework called Session-based Recommendation with Spatio-Temporal Contrastive Learning Enhanced GNNs (RESTC). The idea is to supplement the GNN-based main supervised recommendation task with the temporal representation via an auxiliary cross-view contrastive learning mechanism. Furthermore, a novel global collaborative filtering graph (CFG) embedding is leveraged to enhance the spatial view in the main task. Extensive experiments demonstrate the significant performance of RESTC compared with the state-of-the-art baselines e.g., with an improvement as much as 27.08% gain on HR@20 and 20.10% gain on MRR@20.

Introduction: The Challenge of Session-based Recommendation

Session-based recommendation (SBR) is a critical task in modern e-commerce and content platforms, where the goal is to predict a user's next action based on a short sequence of interactions within a single session. Unlike traditional recommendation systems, SBR operates without long-term user profiles, relying entirely on the immediate context of the current session.

Current research has diverged into two primary methodologies: GNN-based models and sequence-based models. GNNs excel at capturing complex, non-linear transitions between items by representing sessions as graphs. However, they are inherently permutation-invariant, meaning they often discard the precise chronological order of clicks—a vital signal for understanding how a user's interest evolves.

Transformation of temporal timelines into a spatial graph structure

The RESTC Framework

To bridge the gap between spatial structure and temporal order, we introduce RESTC (Session-based REcommendation with Spatio-Temporal Contrastive Learning Enhanced GNNs). RESTC integrates these perspectives through four main pillars:

  • Spatial Encoder (MGAT): A Multi-relational Graph Attention Network that categorizes item transitions into four types: in-relation, out-relation, bi-directional, and self-loops. This provides a richer structural view than standard unweighted graphs.
  • Temporal Encoder (SESTrans): A "Session Transformer" augmented with a Temporal Enhanced Module. It uses a [CLS] token to capture global session preference and a specialized attention mechanism to track shifting interests.
  • Cross-View Contrastive Learning: This is the core innovation. The model treats the spatial and temporal representations of the same session as a positive pair, forcing the model to align these two different perspectives in a shared latent space.
  • Global Collaborative Filtering Graph (CFG): To combat data sparsity, the model builds a global graph from all sessions, allowing it to "borrow" transition knowledge from other users to enrich local session representations.

Key Insight: Addressing Information Loss

A key motivation for RESTC is the "Information Loss" inherent in graph-only models. Standard GNNs struggle to distinguish between sessions that result in the same graph structure but follow different temporal paths, such as "rings" (e.g., A -> B -> A). Analysis of the Diginetica dataset reveals that nearly 24% of sessions contain such patterns, leading to significant ambiguity in reconstruction when temporal order is ignored.

Illustration of information loss where multiple sessions map to the same graph structure

Experimental Results

RESTC achieved a new state-of-the-art (SOTA) performance across six diverse benchmark datasets: Tmall, Diginetica, Gowalla, RetailRocket, Nowplaying, and LastFM.

Key performance highlights include:

  • Accuracy Gains: On the Tmall dataset, RESTC improved HR@10 from 28.01% to 35.57%.
  • Ranking Quality: Significant improvements were noted in MRR@20, particularly in the Gowalla and RetailRocket datasets, indicating the model places correct recommendations higher in the list.
  • Robustness: Ablation studies confirmed that removing any component—the Transformer, the Global Graph, or the Contrastive Loss—led to a measurable drop in performance, proving the synergy of the design.

Conclusion

RESTC successfully addresses the sub-optimal interaction between spatial and temporal patterns in session-based recommendation. By leveraging contrastive learning to align these distinct views, the framework provides a more holistic understanding of user behavior, setting a new benchmark for accuracy and ranking quality in the field.

Summary updated

BibTeX
@article{wan2022spatio,
  author = {Zhongwei Wan and Benyou Wang and Xin Liu and Jiezhong Qiu and Boyu Li and Ting Guo and Guangyong Chen and Yang Wang},
  title = {{Spatio-Temporal Contrastive Learning Enhanced GNNs for Session-based Recommendation}},
  journal = {ACM Trans. Information Systems},
  year = {2022},
  doi = {10.1145/3626091},
}
Figure