
We propose a generalizable and efficient LLM-based recommendation framework RecCocktail. Our approach begins with fine-tuning a "base spirit" LoRA module using domain-general recommendation instruction data to align LLM with recommendation knowledge. Next, given users' behavior of a specific domain, we construct a domain-specific "ingredient" LoRA module. We then provide an entropy-guided adaptive merging method to mix the "base spirit" and the "ingredient" in the weight space. Please note that, RecCocktail combines the advantages of the existing two paradigms without introducing additional time or space overhead during the inference phase. Moreover,
RecCocktail is efficient with plug and play, as the "base spirit" LoRA is trained only once, and any domain-specific "ingredient" can be efficiently mixed with only domain-specific fine-tuning.
In the following, we will guide you how to use this repository step by step. 🤗
You can use the following commands to configure the environment required for codes.
conda create -n molorec python=3.11.9
conda activate molorec
sh scripts\env.shYou can use the following commands to download and process the dataset.
sh scripts\download_data.sh
sh scripts\make_data.shOf course, you can also directly download the processed data from the [Google Drive]. Note that the cold start test dataset does not have processing code and needs to be downloaded.
First, download Qwen2-7B-Instruct into folder models, then use the following commands to get general module and specific module.
sh scripts\train_lora.shSince the dataset involves random sampling, it may lead to fluctuations in the results, so you can download the module we provide from the [Google Drive]
First, replace the files in models\Qwen2-7B-Instruct with the files in models\Qwen2-7B-Instruct-edit, then use the following commands to learn the weights of module fusion.
sh scripts\beauty_weights.sh
sh scripts\toys_weights.sh
sh scripts\sports_weights.shYou can use the following commands to test model
sh scripts\test_weights.shAnd use the following commands to find best fusion weights and output the metrics
sh scripts\metrics.shOur code is based on the implementation of peft and transformers.
We also leverage LLaMA-Factory and vllm to better perform large model fine-tuning and inference.
Thanks for their wonderful works.