ReLLa: Retrieval-enhanced Large Language Models for Lifelong Sequential Behavior Comprehension in Recommendation
This is the pytorch implementation of ReLLa proposed in the paper ReLLa: Retrieval-enhanced Large Language Models for Lifelong Sequential Behavior Comprehension in Recommendation.
In this repo, we implement ReLLa with transformers==4.28.1
. We also provide a newer version of implementation with transformers==4.35.2
in this repo.
pip install -r requirments.txt
You can directly use the processed data from this link. (including data w/o and w/ retrieval: full testing set, sampled training set, history length 30/30/60 for Ml-1m/Ml-25m/BookCrossing)
Or you can preprocess by yourself. Scripts for data preprocessing of BookCrossing, MovieLens-1M, MovieLens-25M are included in data_preprocess.
Get semantic item embeddings for retrieval.
python get_semantic_embed.py --model_path XXX --data_set BookCrossing/ml-1m/ml-25m --pooling average
- BookCrossing
python topK_relevant_BookCrossing.py
- MovieLens-1M
python topK_relevant_ml1m.py
- MovieLens-25M
python topK_relevant_ml25m.py
python data2json.py --K 10 --temp_type simple --set test --dataset ml-1m
Demo processed data is under ./data/ml-1m/proc_data/data/test/test_5_simple.json
This step samples training data from the whole training set, and constructs a mixture dataset of both original data and retrieval-enhanced data.
python training_set_construction.py --K 5
You should provide the model path in the scripts.
python scripts/script_inference.py --K 5 --dataset ml-1m --temp_type simple
python scripts/script_finetune.py --dataset ml-1m --K 5 --train_size 64 --train_type simple --test_type simple --epochs 5 --lr 1e-3 --total_batch_size 64