PyTorch implementation for the Paper: Semantic Relation Guided Dual-view Contrastive Learning for Session-based Recommendations.
Dual-view from the data source perspective: (user-item) intent view and (item) attribute view: In the intent-view of users, users tend to demand items that complement their historical sequences rather than substitutable ones. Therefore, the intent information included in complementary items should exhibit similarity, while the intent included in substitutable items should demonstrate dissimilarity. In the attribute-view of items, substitutable items should have similar attribute information, while attribute information included in complementary items should be dissimilar.
Figure 1. Illustration of positive and negative signals observed between substitutable and complementary items from intent and attribute views.
Figure 2. Overview of SCL-SR.
├─ DIREC/
├── experiments # Experimental results and visualizations of model performance
├── models/ # Code for model architectures, contrastive learning, and attention mechanisms.
├── attention.py/
...
├── preprocess/ # Scripts for data preprocessing and sample extraction.
├── utils/ # Code for dataset loading, model configuration, and training.
main.py # Scripts for training/testing the model on the Tmall/E-Commerce dataset.
main_cosmetics.py # Scripts for training/testing the model on the cosmetics dataset.
parse.py # Parses command-line arguments for configuring the dataset, model, training, and hyper-parameters.
- Python 3.9
- PyTorch 1.12
- Tmall: alpha=0.02, beta=100, num_coarse_sampling=90
- E-Commerce (CIKM19): alpha=0.02, beta=150, num_coarse_sampling=90
- Cosmetics: alpha=0.02, beta=100, num_coarse_sampling=90
-
Step 1: Data preprocessing
python preprocess.py --dataset Tmall python preprocess.py --dataset Cosmetics python preprocess.py --dataset CIKM19
-
Step 2: Negative sampling
python get_samples.py --dataset Tmall python get_samples.py --dataset Cosmetics python get_samples.py --dataset CIKM19
-
Step 3: Train & Test:
- For Tmall and E-Commerce(CIKM19):
python main.py --dataset Tmall --alpha 0.02 --beta 100 python main.py --dataset CIKM19 --alpha 0.02 --beta 150
- For Cosmetics:
python main_cosmetics.py --dataset Cosmetics --alpha 0.02 --beta 100
The datasets have been preprocessed and encoded with pickle, which can be downloaded from the link (password: v3bj)
To enhance the reproducibility of the model, we provide the trained model files in this link.
Figure 3. Comparison of prediction accuracy with different variants of our model.
2. How do different hyper-parameter configurations, such as the weight of the contrastive loss $(\alpha)$ , impact the performance of SCL-SR?
Figure 4. Hyper-parameter analysis and negative sample quantity analysis on different datasets.
Figure 5: Visualization of the learned item embeddings on Tmall dataset with and without intent-attribute disentangler.
If you find our work useful to your research, we kindly ask that you cite the following paper:
@article{qian2025semantic,
title = {Semantic Relation Guided Dual-view Contrastive Learning for Session-based Recommendations},
author = {Zhang, Qian and Wang, Shoujin and Cao, Longbing and Lian, Defu and Zhang, Haibo and Lu, Wenpeng},
journal = {ACM Transactions on Information Systems},
year = {2025}
}






