ReChorus is a general PyTorch framework for Top-K recommendation with implicit feedback, especially for research purpose. It aims to provide a fair benchmark to compare different state-of-the-art algorithms. We hope this can partially alleviate the problem that different papers adopt non-comparable experimental settings, so as to form a "Chorus" of recommendation algorithms.
This framework is especially suitable for researchers to compare algorithms under the same experimental setting, and newcomers to get familiar with classical methods. The characteristics of our framework can be summarized as follows:
-
Swift: concentrate on your model design in a single file and implement new models quickly.
-
Easy: the framework is accomplished in less than a thousand lines of code, which is easy to use with clean codes and adequate comments.
-
Efficient: multi-thread batch preparation, special implementations for the evaluation, and around 90% GPU utilization during training for deep models.
-
Flexible: implement new readers or runners for different datasets and experimental settings, and each model can be assigned with specific helpers.
Generally, ReChorus decomposes the whole process into three modules:
- Reader: read dataset into DataFrame and append necessary information to each instance
- Runner: control the training process and model evaluation
- Model: define how to generate ranking scores and prepare batches
- Install Anaconda with Python >= 3.5
- Clone the repository
git clone https://github.com/THUwangcy/ReChorus.git
- Install requirements and step into the
src
folder
cd ReChorus
pip install -r requirements.txt
cd src
- Run model with the build-in dataset
python main.py --model_name BPRMF --emb_size 64 --lr 1e-3 --l2 1e-6 --dataset Grocery_and_Gourmet_Food
-
(optional) Run jupyter notebook in
data
folder to download and build new datasets, or prepare your own datasets according to Guideline indata
-
(optional) Implement your own models according to Guideline in
src
The main arguments are listed below.
Args | Default | Description |
---|---|---|
model_name | 'BPRMF' | The name of the model class. |
lr | 1e-3 | Learning rate. |
l2 | 0 | Weight decay in optimizer. |
test_all | 0 | Wheter to rank all the items during evaluation. |
metrics | 'NDCG,HR' | The list of evaluation metrics (seperated by comma). |
topk | '5,10,20' | The list of K in evaluation metrics (seperated by comma). |
num_workers | 5 | Number of processes when preparing batches. |
batch_size | 256 | Batch size during training. |
eval_batch_size | 256 | Batch size during inference. |
load | 0 | Whether to load model checkpoint and continue to train. |
train | 1 | Wheter to perform model training. |
regenerate | 0 | Wheter to regenerate intermediate files. |
random_seed | 0 | Random seed of everything. |
gpu | '0' | The visible GPU device (pass an empty string '' to only use CPU). |
buffer | 1 | Whether to buffer batches for dev/test. |
history_max | 20 | The maximum length of history for sequential models. |
num_neg | 1 | The number of negative items for each training instance. |
test_epoch | -1 | Print test set metrics every test_epoch during training (-1: no print). |
We have implemented the following methods (still updating):
General Recommender
- Bayesian personalized ranking from implicit feedback (BPRMF [UAI'09])
- Neural Collaborative Filtering (NeuMF [WWW'17])
- Learning over Knowledge-Base Embeddings for Recommendation (CFKG [SIGIR'18])
- LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation (LightGCN [SIGIR'20])
- Bootstrapping User and Item Representations for One-Class Collaborative Filtering (BUIR [SIGIR'21])
- Towards Representation Alignment and Uniformity in Collaborative Filtering (DirectAU [KDD'22])
Sequential Recommender
- Factorizing Personalized Markov Chains for Next-Basket Recommendation (FPMC [WWW'10])
- Session-based Recommendations with Recurrent Neural Networks (GRU4Rec [ICLR'16])
- Neural Attentive Session-based Recommendation (NARM [CIKM'17])
- Personalized Top-N Sequential Recommendation via Convolutional Sequence Embedding (Caser [WSDM'18])
- Self-attentive Sequential Recommendation (SASRec [IEEE'18])
- Modeling Item-specific Temporal Dynamics of Repeat Consumption for Recommender Systems (SLRC [WWW'19])
- Time Interval Aware Self-Attention for Sequential Recommendation (TiSASRec [WSDM'20])
- Make It a Chorus: Knowledge- and Time-aware Item Modeling for Sequential Recommendation (Chorus [SIGIR'20])
- Controllable Multi-Interest Framework for Recommendation (ComiRec [KDD'20])
- Towards Dynamic User Intention: Temporal Evolutionary Effects of Item Relations in Sequential Recommendation (KDA [TOIS'21])
- Sequential Recommendation with Multiple Contrast Signals (ContraRec [TOIS'22])
The table below lists the results of these models in Grocery_and_Gourmet_Food
dataset (151.3k entries). Leave-one-out is applied to split data: the most recent interaction of each user for testing, the second recent item for validation, and the remaining items for training. We randomly sample 99 negative items for each test case to rank together with the ground-truth item (also support ranking over all the items with --test_all 1
).
Model | HR@5 | NDCG@5 | Time/iter | Sequential | Knowledge | Time-aware |
---|---|---|---|---|---|---|
BPRMF | 0.3574 | 0.2480 | 2.5s | |||
NeuMF | 0.3248 | 0.2235 | 3.4s | |||
LightGCN | 0.3713 | 0.2577 | 6.1s | |||
BUIR | 0.3639 | 0.2542 | 3.3s | |||
DirectAU | 0.3898 | 0.2755 | 3.3s | |||
FPMC | 0.3618 | 0.2816 | 3.4s | √ | ||
GRU4Rec | 0.3664 | 0.2597 | 4.9s | √ | ||
NARM | 0.3621 | 0.2586 | 8.2s | √ | ||
Caser | 0.3576 | 0.2518 | 7.8s | √ | ||
SASRec | 0.3888 | 0.2923 | 7.2s | √ | ||
ComiRec | 0.3763 | 0.2694 | 5.1s | √ | ||
ContraRec | 0.4269 | 0.3290 | 5.6s | √ | ||
TiSASRec | 0.3916 | 0.2922 | 35.7s | √ | √ | |
CFKG | 0.4228 | 0.3010 | 8.7s | √ | ||
SLRC+ | 0.4514 | 0.3329 | 4.3s | √ | √ | √ |
Chorus | 0.4739 | 0.3443 | 4.9s | √ | √ | √ |
KDA | 0.5174 | 0.3876 | 9.9s | √ | √ | √ |
For fair comparison, the embedding size is set to 64. We strive to tune all the other hyper-parameters to obtain the best performance for each model (may be not optimal now, which will be updated if better scores are achieved). Current commands are listed in run.sh. We repeat each experiment 5 times with different random seeds and report the average score (see exp.py). All experiments are conducted with a single GTX-1080Ti GPU.
This is also our public implementation for the following papers (codes and datasets to reproduce the results can be found at corresponding branch):
- Chenyang Wang, Min Zhang, Weizhi Ma, Yiqun Liu, and Shaoping Ma. Make It a Chorus: Knowledge- and Time-aware Item Modeling for Sequential Recommendation. In SIGIR'20.
git clone -b SIGIR20 https://github.com/THUwangcy/ReChorus.git
- Chenyang Wang, Weizhi Ma, Min Zhang, Chong Chen, Yiqun Liu, and Shaoping Ma. Towards Dynamic User Intention: Temporal Evolutionary Effects of Item Relations in Sequential Recommendation. In TOIS'21.
git clone -b TOIS21 https://github.com/THUwangcy/ReChorus.git
- Chenyang Wang, Weizhi Ma, Chong, Chen, Min Zhang, Yiqun Liu, and Shaoping Ma. Sequential Recommendation with Multiple Contrast Signals. In TOIS'22.
git clone -b TOIS22 https://github.com/THUwangcy/ReChorus.git
If you find ReChorus is helpful to your research, please cite either of the papers. Thanks!
@inproceedings{wang2020make,
title={Make it a chorus: knowledge-and time-aware item modeling for sequential recommendation},
author={Wang, Chenyang and Zhang, Min and Ma, Weizhi and Liu, Yiqun and Ma, Shaoping},
booktitle={Proceedings of the 43rd International ACM SIGIR Conference on Research and Development in Information Retrieval},
pages={109--118},
year={2020}
}
@article{王晨阳2021rechorus,
title={ReChorus: 一个综合, 高效, 易扩展的轻量级推荐算法框架},
author={王晨阳 and 任一 and 马为之 and 张敏 and 刘奕群 and 马少平},
journal={软件学报},
volume={33},
number={4},
pages={0--0},
year={2021}
}
Chenyang Wang ([email protected])