This repository provides the official PyTorch implementation and reproduction for the paper titled "SPRec: Self-Play to Debias LLM-based Recommendation"
-
Clone this git repository and change directory to this repository:
-
A new conda environment is suggested.
conda env create -f environment.yml
-
Activate the newly created environment.
conda activate SPRec
Due to GitHub's file size limitations, we have uploaded the minimal sample dataset Goodreads in ./data/Goodreads and ./eval/Goodreads for reproduction purposes. Additionally, the datasets used in our experiments—MovieLens, CDs and Vinyl, and Steam—have been uploaded to Datasets. If you wish to use a different dataset, please ensure that it is processed into a similar format.
Besides, to ensure that SPRec does not encounter more training data during multiple iterations compared to other baseline methods, it is recommended to sample the training dataset beforehand to limit its size. The sample dataset we provide has already been sampled and contains 5,000 entries. You can further sample it according to your requirements to control the total amount of data SPRec is exposed to during training.
- SFT Training:
Before using the SPRec training framework, you need to run SFT to fine-tune your base model for alignment with the recommendation task. Use the following command to perform SFT training:bash ./shell/SFT.sh 0 1 2 3 # Specify your GPUs, e.g., 0 1 2 3 - SPRec Training:
After completing SFT training, use the following command to perform SPRec training:bash ./shell/SPRec.sh 0 1 2 3 5 # Specify your GPUs, e.g., 0 1 2 3, and the number of iterations, e.g., 5
Once the above commands are executed, the evaluation results for top-1 and top-5 recommendations will be saved as eval_top1.json and eval_top5.json in the corresponding model directory.
This repository also includes implementations of baseline methods in our paper for research comparison. We sincerely acknowledge the original authors for their foundational work.
If you find this repository helpful, we kindly request citing our paper:
@article{gao2024sprec,
title={SPRec: Self-Play to Debias LLM-based Recommendation},
author={Gao, Chongming and Chen, Ruijun and Yuan, Shuai and Huang, Kexin and Yu, Yuanqing and He, Xiangnan},
journal={arXiv preprint arXiv:2412.09243},
year={2024}
}
