Abstract
Sequential recommendation systems aim to predict a user's future interactions based on their historical behavior. However, traditional models often suffer from data sparsity, where limited user-item interactions hinder the learning of high-quality representations. We introduce CL4SRec (Contrastive Learning for Sequential Recommendation), a multi-task learning framework that supplements the standard next-item prediction task with a self-supervised contrastive learning objective. By generating multiple augmented views of user sequences through cropping, masking, and reordering, CL4SRec forces the model to capture more robust, invariant features of user intent. Our experiments on four public datasets demonstrate that CL4SRec consistently outperforms state-of-the-art baselines, providing significant gains in recommendation accuracy and robustness.
1. Introduction
Modern sequential recommendation models, such as SASRec and GRU4Rec, typically rely on Transformer or RNN architectures to model the chronological dependencies of user actions. While effective, these models are often constrained by the "next-item prediction" paradigm. In real-world scenarios, interaction data is frequently sparse; many users have only a handful of recorded actions. This sparsity makes it difficult for complex models to generalize, as the training signal derived solely from predicting the immediate next item is insufficient to capture the broader nuances of user preferences.
To address this, we propose CL4SRec. By leveraging contrastive learning, we enable the model to perform "sequence understanding" rather than just "next-item guessing." This approach allows the model to learn from the intrinsic correlations within the behavior sequences themselves, leading to more resilient embeddings.
2. The CL4SRec Framework
The CL4SRec architecture is built upon a Transformer backbone, specifically the SASRec encoder, which processes item sequences into latent representations. The innovation lies in the dual-objective training process.
As shown in Figure 1, the model processes the original behavior sequence $s$ to compute a recommendation loss based on the predicted next item $v_{t+1}$. Simultaneously, the system generates two augmented versions of the sequence, $s^{a_i}$ and $s^{a_j}$, which are passed through the shared encoder. The contrastive loss is then calculated by maximizing the agreement between these two views of the same user while minimizing agreement with views from other users in the mini-batch. Interestingly, the authors found that omitting the non-linear projection head—a standard component in computer vision contrastive models like SimCLR—actually improved performance in the recommendation context.
2.1 Data Augmentation Strategies
The effectiveness of contrastive learning depends heavily on the quality of the "views" generated. We propose three stochastic augmentation operators to perturb the input sequences:
- Item Crop: A continuous sub-sequence is randomly selected, providing a "local" view of the user's interests.
- Item Mask: A fixed proportion of items are randomly hidden, forcing the model to be robust to missing data.
- Item Reorder: A sub-sequence is shuffled, acknowledging that the exact order of certain interactions may not be strictly rigid.
3. Experimental Evaluation
We evaluated CL4SRec on four diverse datasets: Amazon Beauty, Amazon Sports and Outdoors, Yelp, and MovieLens 1M. These datasets were pre-processed to ensure a "5-core" density, meaning all users and items included had at least five interactions.
3.1 Key Results
CL4SRec achieved a significant performance boost over state-of-the-art baselines. On average, the model improved HR@5 by 11.02% and NDCG@10 by 8.50% compared to the best-performing baselines. The gains were most pronounced on the sparser datasets (Amazon Beauty and Sports), confirming that the self-supervised signal is particularly valuable when explicit interaction data is limited. Ablation studies further revealed that the contrastive loss specifically provides a much stronger boost than simply adding augmented data to the training set.
4. Discussion and Insights
A qualitative analysis of the latent space revealed that CL4SRec naturally aligns users with similar behavioral patterns. On the Yelp dataset, the model clustered "friends" from the social graph closer together than baseline models did, despite having no access to social network information during training. This proves the model is capturing genuine behavioral similarities.
However, the model's performance is sensitive to the weight of the contrastive loss ($\lambda$). If the contrastive task dominates, it can detract from the primary goal of next-item recommendation. Additionally, the current augmentations are stochastic and "blind." Future work could explore "semantic" augmentations—for example, masking items based on their category or importance to the user's profile.
5. Conclusion
CL4SRec demonstrates that contrastive learning is a powerful tool for overcoming data sparsity in sequential recommendation. By shifting the focus from simple prediction to sequence-level representation learning, we can build recommendation engines that are more accurate, robust, and capable of capturing the complex underlying patterns of human behavior.
Summary updated