akariasai commited on
Commit
e8d4b1c
1 Parent(s): 47fc277

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ This model is a 7B [Self-RAG](https://selfrag.github.io/) model that generates outputs to diverse user queries as well as *reflection tokens* to call the retrieval system adaptively and criticize its own output and retrieved passages.
6
+
7
+ Self-RAG is trained on our instruction-following corpora with interleaving passages and reflection tokens using the standard next-token prediction objective, enabling efficient and stable learning with fine-grained feedback.
8
+ At inference, we leverage reflection tokens covering diverse aspects of generations to sample the best output aligning users' preferences.
9
+ See full descriptions in [our paper](https://akariasai.github.io/files/adaptive_retrieval_augmented_lm_arxiv.pdf).
10
+
11
+ ## Usage
12
+ Here, we show an easy way to quickly download our model from HuggingFace and run with `vllm` with pre-given passages. Make sure to install dependencies listed at [self-rag/requirements.txt](https://github.com/AkariAsai/self-rag/requirements.txt).
13
+ To run our full inference pipeline with a retrieval system and fine-grained tree decoding, please use [our code](https://github.com/AkariAsai/self-rag).
14
+
15
+ ```py
16
+ from transformers import AutoTokenizer, AutoModelForCausalLM
17
+ from vllm import LLM, SamplingParams
18
+ model = LLM("selfrag/selfrag_llama2_13b", download_dir="/gscratch/h2lab/akari/model_cache", dtype="half")
19
+ sampling_params = SamplingParams(temperature=0.0, top_p=1.0, max_tokens=100, skip_special_tokens=False)
20
+ def format_prompt(input, paragraph=None):
21
+ prompt = "### Instruction:\n{0}\n\n### Response:\n".format(input)
22
+ if paragraph is not None:
23
+ prompt += "[Retrieval]<paragraph>{0}</paragraph>".format(paragraph)
24
+ return prompt
25
+ query_1 = "Leave odd one out: twitter, instagram, what'sup."
26
+ query_2 = "Can you tell me the difference between llamas and alpacas?"
27
+ queries = [query_1, query_2]
28
+ preds = model.generate([format_prompt(query) for query in queries], sampling_params)
29
+ for pred in preds:
30
+ print("Model prediction: {0}".format(pred.outputs[0].text))
31
+ # Model prediction: Twitter, Instagram, and WhatsApp are all social media platforms.[No Retrieval]WhatsApp is the odd one out because it is a messaging app, while Twitter and # Instagram are primarily used for sharing photos and videos.[Utility:5]</s> (this query doesn't require factual grounding; just skip retrieval and do normal instruction-following generation)
32
+ # Model prediction: Sure![Retrieval]<paragraph> ... (this query requires factual grounding, call a retriever)
33
+ # generate with the retrieved passage
34
+ prompt = format_prompt("Can you tell me the difference between llamas and alpacas?", paragraph="The alpaca (Lama pacos) is a species of South American camelid mammal. It is similar to, and often confused with, the llama. Alpacas are considerably smaller than llamas, and unlike llamas, they were not bred to be working animals, but were bred specifically for their fiber.")
35
+ preds = model.generate([prompt], sampling_params)
36
+ print([pred.outputs[0].text for pred in preds])
37
+ # ['[Relevant]Alpacas are considerably smaller than llamas, and unlike llamas, they were not bred to be working animals, but were bred specifically for their fiber.[Fully supported][Utility:5]</s>']
38
+ ```
39
+
40
+ ## Input Format
41
+ As described in the `format_prompt` function, your input should be formed as
42
+ ```
43
+ ### Instruction:\n{instruction}\n\n### Response:\n".format(instruction)
44
+ ```
45
+ or
46
+ ```
47
+ ### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:\n"
48
+ ```
49
+ If you have additional input.
50
+ You can insert paragraphs anywhere after `### Response:\n"`, but make sure to mark paragraphs as paragraph tokens (i.e., `<paragraph>{0}</paragraph>`).
51
+
52
+ ## Citation and contact
53
+ If you use this model, please cite our work:
54
+ ```
55
+ @article{asai2023selfrag,
56
+ author = {Asai, Akari and Wu, Zeqiu and Wang, Yizhong and Sil, Avirup and Hajishirzi, Hannaneh},
57
+ title = {{Self-RAG}: Learning to Retrieve, Generate, and Critique through Self-Reflection},
58
+ year = {2023},
59
+ }
60
+ ```