Delete README.md
Browse files
README.md
DELETED
@@ -1,124 +0,0 @@
|
|
1 |
-
# LC-Rec
|
2 |
-
|
3 |
-
This is the official PyTorch implementation for the paper:
|
4 |
-
|
5 |
-
> [Adapting Large Language Models by Integrating Collaborative Semantics for Recommendation](https://arxiv.org/abs/2311.09049)
|
6 |
-
|
7 |
-
## Overview
|
8 |
-
|
9 |
-
We propose **LC-Rec**, a new approach to integrate **L**anguage and **C**ollaborative semantics for improving LLMs in **Rec**ommender systems. To tackle the large gap between the language semantics modeled by LLMs and collaborative semantics implied by recommender systems, we make two major contributions in two aspects. For item indexing, we design a learning-based vector quantization method with uniform semantic mapping, which can assign meaningful and non-conflicting IDs (called item indices) for items. For alignment tuning, we propose a series of specially designed tuning tasks to enhance the integration of collaborative semantics in LLMs. Our fine-tuning tasks enforce LLMs to deeply integrate language and collaborative semantics (characterized by the learned item indices), so as to achieve an effective adaptation to recommender systems.
|
10 |
-
|
11 |
-

|
12 |
-
|
13 |
-
## Requirements
|
14 |
-
|
15 |
-
```
|
16 |
-
torch==1.13.1+cu117
|
17 |
-
accelerate
|
18 |
-
bitsandbytes
|
19 |
-
deepspeed
|
20 |
-
evaluate
|
21 |
-
peft
|
22 |
-
sentencepiece
|
23 |
-
tqdm
|
24 |
-
transformers
|
25 |
-
```
|
26 |
-
|
27 |
-
## Model Checkpoint
|
28 |
-
|
29 |
-
The delta weights on the three datasets can be downloaded from huggingface hub ([Instruments](https://huggingface.co/bwzheng0324/lc-rec-instruments-delta), [Arts](https://huggingface.co/bwzheng0324/lc-rec-arts-delta), [Games](https://huggingface.co/bwzheng0324/lc-rec-games-delta)). After downloading, you can add our deltas to the original LLaMA weights to obtain LC-Rec weights:
|
30 |
-
|
31 |
-
1. Get the original [LLaMA](https://huggingface.co/huggyllama/llama-7b) weights.
|
32 |
-
2. Use the following scripts to get LC-Rec weights by applying our delta.
|
33 |
-
|
34 |
-
```shell
|
35 |
-
python -m convert/merge_delta.py \
|
36 |
-
--base-model-path /path/to/llama-7b \
|
37 |
-
--target-model-path /path/output/lc-rec \
|
38 |
-
--delta-path bwzheng0324/lc-rec-games-delta
|
39 |
-
```
|
40 |
-
|
41 |
-
## Dataset
|
42 |
-
|
43 |
-
We use three datasets in our paper, all of which have been uploaded to [Google Drive](https://drive.google.com/drive/folders/1RcJ2M1l5zWPHYuGd9l5Gibcs5w5aI3y6?usp=sharing)
|
44 |
-
|
45 |
-
## Train
|
46 |
-
|
47 |
-
The detailed scripts for all three datasets are in `run.sh`:
|
48 |
-
|
49 |
-
```shell
|
50 |
-
DATASET=Games
|
51 |
-
BASE_MODEL=huggyllama/llama-7b
|
52 |
-
DATA_PATH=./data
|
53 |
-
OUTPUT_DIR=./ckpt/$DATASET/
|
54 |
-
|
55 |
-
torchrun --nproc_per_node=8 --master_port=3324 finetune.py \
|
56 |
-
--base_model $BASE_MODEL \
|
57 |
-
--output_dir $OUTPUT_DIR \
|
58 |
-
--dataset $DATASET \
|
59 |
-
--data_path $DATA_PATH \
|
60 |
-
--per_device_batch_size 8 \
|
61 |
-
--gradient_accumulation_steps 2 \
|
62 |
-
--learning_rate 5e-5 \
|
63 |
-
--epochs 4 \
|
64 |
-
--weight_decay 0.01 \
|
65 |
-
--save_and_eval_strategy epoch \
|
66 |
-
--deepspeed ./config/ds_z3_bf16.json \
|
67 |
-
--bf16 \
|
68 |
-
--only_train_response \
|
69 |
-
--tasks seqrec,item2index,index2item,fusionseqrec,itemsearch,preferenceobtain \
|
70 |
-
--train_prompt_sample_num 1,1,1,1,1,1 \
|
71 |
-
--train_data_sample_num 0,0,0,100000,0,0 \
|
72 |
-
--index_file .index.json
|
73 |
-
|
74 |
-
|
75 |
-
cd convert
|
76 |
-
nohup ./convert.sh $OUTPUT_DIR >convert.log 2>&1 &
|
77 |
-
cd ..
|
78 |
-
```
|
79 |
-
|
80 |
-
## Test
|
81 |
-
|
82 |
-
Test with a single GPU:
|
83 |
-
|
84 |
-
```shell
|
85 |
-
DATASET=Games
|
86 |
-
DATA_PATH=./data
|
87 |
-
OUTPUT_DIR=./ckpt/$DATASET/
|
88 |
-
RESULTS_FILE=./results/$DATASET/result.json
|
89 |
-
|
90 |
-
python test.py \
|
91 |
-
--gpu_id 0 \
|
92 |
-
--ckpt_path $CKPT_PATH \
|
93 |
-
--dataset $DATASET \
|
94 |
-
--data_path $DATA_PATH \
|
95 |
-
--results_file $RESULTS_FILE \
|
96 |
-
--test_batch_size 1 \
|
97 |
-
--num_beams 20 \
|
98 |
-
--test_prompt_ids all \
|
99 |
-
--index_file .index.json
|
100 |
-
```
|
101 |
-
|
102 |
-
Test with multiple GPUs:
|
103 |
-
|
104 |
-
```shell
|
105 |
-
DATASET=Games
|
106 |
-
DATA_PATH=./data
|
107 |
-
OUTPUT_DIR=./ckpt/$DATASET/
|
108 |
-
RESULTS_FILE=./results/$DATASET/result.json
|
109 |
-
|
110 |
-
torchrun --nproc_per_node=8 --master_port=4324 test_ddp.py \
|
111 |
-
--ckpt_path $CKPT_PATH \
|
112 |
-
--dataset $DATASET \
|
113 |
-
--data_path $DATA_PATH \
|
114 |
-
--results_file $RESULTS_FILE \
|
115 |
-
--test_batch_size 1 \
|
116 |
-
--num_beams 20 \
|
117 |
-
--test_prompt_ids all \
|
118 |
-
--index_file .index.json
|
119 |
-
```
|
120 |
-
|
121 |
-
## Acknowledgement
|
122 |
-
|
123 |
-
The implementation is based on [HuggingFace](https://github.com/huggingface/transformers).
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|