MCPcopy Index your code
hub / github.com/WangXFng/RDRec

github.com/WangXFng/RDRec @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
130 symbols 452 edges 21 files 43 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RDRec (ACL'24)

Paper - [ArXiv] [ACL Anthology]

  • RDRec: Rationale Distillation for LLM-based Recommendation, ACL 2024 Main (short).

Note

  • Please use the latest code released on June 11th, 2024.
  • The checkpoints of the RDRec model for Step 2 were uploaded on Google Drive and Baidu Drive.
  • The experimental setup follows POD. If there is any problem, please check our code or [ArXiv].

Instruction

Step. 1 distill rationale before running RDRec

(a) Install llama 2 (download model weights and tokenizer)

    get the License from [the site](https://llama.meta.com/llama-downloads/)
    >> cd llama 
    >> ./download.sh (License required)
    >> pip install -e .

(b) Test llama 2 environment (under ./llama )

    >> torchrun --nproc_per_node 1 example_chat_completion.py \
      --ckpt_dir llama-2-7b-chat/ \
      --tokenizer_path tokenizer.model \
      --max_seq_len 512 --max_batch_size 6

(c) Rationale distillation ({dataset}: beauty, sports, and toys.) (under ./RDRec )

    >> torchrun --nproc_per_node 1 data/{dataset}/distillation_{dataset}.py \
      --ckpt_dir llama/llama-2-7b-chat/ \
      --tokenizer_path llama/tokenizer.model \
      --max_seq_len 512 --max_batch_size 6

Step. 2 train and test RDRec

(a) Install requirement (After installing torch)

    >> pip install transformers==4.36.2 -i https://pypi.python.org/simple
    >> pip install -r requirements.txt

(b) Pre-training ({dataset}: beauty, sports, and toys.) (under ./RDRec )

    >> python pretrain.py --data_dir ./data/{dataset}/ --cuda --batch_size 64 --checkpoint ./checkpoint/{dataset}/

(c) Recommendation inference

    >> python seq.py --data_dir ./data/{dataset}/ --cuda --batch_size 32 --checkpoint ./checkpoint/{dataset}/
    >> python topn.py --data_dir ./data/{dataset}/ --cuda --batch_size 32 --checkpoint ./checkpoint/{dataset}/
    >> python exp.py --data_dir ./data/{dataset}/ --cuda --batch_size 32 --checkpoint ./checkpoint/{dataset}/

Others

  • All experiments, including rationale distillation, can be conducted on a single Nvidia GeForce RTX 3090 (24GB memory). Reduce the batch size if you encounter an OOM error on some dataset.
  • There are some fluctuations in RDRec's results for sequential recommendations. We reported average results in 10-trial runs in the paper (See t_test.py for more details). If the results are not ideal, please pre-train the model once again.
  • If you have any questions, please feel free to contact me at kaysenn@163.com.

Citation

If this repository helps you, please cite:

@article{wang2024rdrec,
  title={RDRec: Rationale Distillation for LLM-based Recommendation},
  author={Wang, Xinfeng and Cui, Jin and Suzuki, Yoshimi and Fukumoto, Fumiyo},
  journal={arXiv preprint arXiv:2405.10587},
  year={2024}
}

Acknowledge

  • Code reference: P5, POD, and llama 2.
  • Thanks to Wei-Hsiang Huang's careful review, although RDRec independently generate user preferences and item attributes, the widely used review data (e.g., in P5 and POD) could potentially leak information. The follow-up work will avoid this.

Core symbols most depended-on inside this repo

now_time
called by 32
utils/utils.py
_split_into_words
called by 7
utils/rouge.py
decode
called by 7
llama/llama/tokenizer.py
build
called by 6
llama/llama/generation.py
compute_whole_word_id
called by 5
utils/utils.py
chat_completion
called by 5
llama/llama/generation.py
evaluate
called by 4
pretrain.py
sample
called by 4
utils/utils.py

Shape

Method 63
Function 44
Class 23

Languages

Python100%

Modules by API surface

utils/utils.py56 symbols
llama/llama/model.py21 symbols
utils/rouge.py13 symbols
llama/llama/generation.py10 symbols
model/module.py7 symbols
llama/llama/tokenizer.py4 symbols
llama/get_konwledge.py3 symbols
utils/bleu.py2 symbols
pretrain.py2 symbols
data/toys/distillation_toy.py2 symbols
data/sports/distillation_sports.py2 symbols
data/beauty/distillation_beauty.py2 symbols

For agents

$ claude mcp add RDRec \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact