ZillionZhao commited on
Commit
7ca5ecc
·
verified ·
1 Parent(s): 1f418f0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -3
README.md CHANGED
@@ -1,3 +1,41 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## RAG-Tuning: Towards Generalized Retrieval-Augmented Generation with Data Synthesis
2
+
3
+ <img src="./Rag-Tuning.png" alt="Rag-Tuning" style="zoom:33%;" />
4
+
5
+ **Paper**: *would be released soon*
6
+
7
+ **Abstract**: Retrieval-Augmented Generation (RAG) extends the generative capabilities of large language models by integrating external document retrieval. Most existing studies train and evaluate RAG models predominantly on Knowledge-Intensive Question Answering (KIQA) scenarios. However, this focus often leads to overfitting on KIQA tasks, resulting in poor performance in other RAG scenarios, which is considered not generalized enough. To address this challenge, we introduce RAG-Tuning, a novel approach designed to improve the generalization of RAG models through data synthesis. Our method involves using GPT-4 to generate large-scale training data covering a wide range of RAG scenarios with diverse query topics and formats from scratch. To better mimic real-world RAG conditions, for the passages in training data, we also combine passages from different dense and sparse retrievers for different queries and introduce random noise into the retrieved passages. Unlike previous RAG studies that primarily focus on evaluation on KIQA tasks, we emphasize the importance of evaluating RAG-Tuning on open RAG tasks in addition to traditional in-domain and out-of-domain KIQA benchmarks. Experimental results show significant improvements across all these benchmarks. Additionally, RAG-Tuning demonstrates enhanced generalization when paired with different retrievers or when the retrieved documents are noisy.
8
+
9
+ **Models**: We release the RT-KS and RT-S in this Huggingface Repo. Please use the following codes to load the models (remember to download the original Mistral-7B model first):
10
+
11
+ ``````python
12
+ from transformers import AutoTokenizer, AutoModelForCausalLM
13
+ from peft import PeftModel # , PeftConfig
14
+
15
+
16
+ def load_fine_tuned_model(model_name, adapters_name=None):
17
+ """
18
+ model_name: original Mistral-7B path
19
+ adapters_name: RT-KS or RT-S path
20
+ """
21
+ def set_tokenizer(tokenizer):
22
+ tokenizer.bos_token_id = 1
23
+ tokenizer.eos_token_id = 2
24
+ tokenizer.pad_token_id = tokenizer.eos_token_id
25
+ tokenizer.padding_side = "left"
26
+ tokenizer.truncation_side = "left"
27
+ return tokenizer
28
+
29
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
30
+ tokenizer = set_tokenizer(tokenizer)
31
+
32
+ model = AutoModelForCausalLM.from_pretrained(
33
+ model_name,
34
+ torch_dtype=torch.bfloat16,
35
+ device_map={"": 0}
36
+ )
37
+ if adapters_name:
38
+ model = PeftModel.from_pretrained(model, adapters_name)
39
+ model = model.merge_and_unload()
40
+ return model, tokenizer
41
+ ``````