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

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

TL;DR

Graph Neural Networks (GNNs) used for session-based recommendation often lose track of the exact chronological order of user clicks due to their permutation-invariant nature. The proposed RESTC framework solves this by using an auxiliary cross-view contrastive learning mechanism to align spatial graph structures with temporal sequence patterns. Combined with a global collaborative filtering graph, RESTC achieves state-of-the-art performance in predicting a user's next action.

What Problem Does This Paper Address?

Session-based recommendation (SBR) systems predict what a user wants to see next based entirely on their anonymous, short-term click history (like a single shopping session) rather than a long-term user profile.

Recently, state-of-the-art SBR models have relied on Graph Neural Networks (GNNs). These models treat sessions as graphs where items are nodes and transitions between clicks are edges. However, standard GNNs suffer from a major flaw: their message-passing and aggregation functions are permutation-invariant. This means they treat a set of neighboring nodes as an unordered bag, completely discarding the exact timeline of user interactions.

As a result, two entirely different click sequences can map to the exact same graph representation, leading to critical information loss.

Fig. 1. Two distinct sessions may be represented as the same graph if the temporal information is omitted, indicating the temporal pattern should be sufficiently considered to supplement GNN-based models for SBR task.

While some researchers have tried adding temporal features back into GNNs, existing approaches fail to create sufficient interaction between the spatial (graph structure) and temporal (chronological sequence) patterns in the latent space.

Methods

The authors introduce RESTC (Session-based REcommendation with Spatio-Temporal Contrastive Learning Enhanced GNNs). Instead of simply concatenating time and graph features, RESTC uses a dual-encoder architecture optimized via multi-task learning:

  1. Spatial Encoder (MGAT): A Multi-relational Graph Attention Network that builds a session graph capturing four distinct edge types: incoming relations, outgoing relations, bi-directional transitions, and self-loops.
  2. Temporal Encoder (SESTrans): A Session Transformer paired with a specialized Temporal Enhanced Module to capture the chronological evolution of user preferences.
  3. Spatio-Temporal Contrastive Learning: This is the core novelty. RESTC treats the spatial graph and the temporal sequence as two different "views" of the same session. It uses an InfoNCE contrastive loss function to maximize the mutual information between these views, forcing the spatial and temporal embeddings to align in a shared latent space. It also introduces a mixed noise negative sampling strategy by shuffling temporal samples to make the model more robust.
  4. Global Collaborative Filtering Graph (CFG): To combat data sparsity in short sessions, the authors construct a global graph from all historical sessions across all users. This global context enriches the local spatial view during the main recommendation task.
Overview of the RESTC framework pipeline.

Datasets

The framework was evaluated on six standard, real-world public benchmark datasets:

  • Tmall: Online shopping logs from the IJCAI competition.
  • Diginetica: Click data from the CIKM Cup 2016.
  • Gowalla: Check-in data used for point-of-interest recommendations.
  • RetailRocket: E-commerce browser activity logs.
  • Nowplaying: Music listening behavior extracted from Twitter.
  • LastFM: A popular music track recommendation dataset.

All datasets were filtered to remove sessions of length 1 and rare items (appearing fewer than 5 times), following standard literature protocols.

Key Insights and Ideas

  • The Cycle Reconstruction Dilemma: The authors demonstrate that if a session graph contains directed cycles (loops where a user revisits items), it is mathematically impossible to accurately reconstruct the original chronological sequence from the graph alone. In the Diginetica dataset, graphs with these complex properties account for 23.85% of all samples, highlighting why temporal tracking is mandatory.
  • Avoid Destructive Augmentation: Traditional contrastive learning relies on data augmentations like masking, cropping, or reordering items. In SBR, these techniques can corrupt the fragile, intent-driven sequence of a short session. RESTC avoids this by using the natural duality of the graph view vs. the sequence view as its augmentation strategy.
  • Alignment over Fusion: Simply feeding spatial and temporal features into a final attention layer isn't enough because the individual encoders don't interact during training. Aligning them via contrastive learning regularizes the latent space, ensuring both encoders learn from each other's structural strengths.

Key Results

RESTC consistently outperformed strong baselines (including sequence models like BERT4Rec, GNN models like GCE-GNN, and contrastive models like $S^2$-DHCN) across all datasets.

Key performance metrics included Hit Rate (HR@N) and Mean Reciprocal Rank (MRR@N):

  • On the Tmall dataset, RESTC achieved an HR@20 of 42.47% and an MRR@20 of 18.52%, vastly outperforming the best baseline ($S^2$-DHCN at 31.42% HR@20 and GCE-GNN at 15.42% MRR@20).
  • Ablation studies proved that removing the Session Transformer (w/o SESTrans) or the contrastive loss (w/o Cont.) caused significant performance drops, validating the spatio-temporal alignment concept.

Limitations and Future Work

Not discussed in the paper.

Summary updated

BibTeX
@article{wan2022spatio,
  author = {Zhongwei Wan and Xin Liu and Benyou Wang 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