Update README.md
Browse files
README.md
CHANGED
@@ -7,19 +7,22 @@ license: apache-2.0
|
|
7 |
|
8 |
<!-- Provide a longer summary of what this model is. -->
|
9 |
|
10 |
-
|
11 |
|
|
|
|
|
|
|
12 |
- **Developed by:** https://github.com/xbmxb/RAG-query-rewriting
|
13 |
- **Model type:** google/t5-large
|
|
|
14 |
|
15 |
-
###
|
16 |
|
17 |
-
```
|
|
|
18 |
import torch
|
19 |
-
from google.colab import userdata
|
20 |
-
|
21 |
-
os.environ["HUGGINGFACE_TOKEN"] = userdata.get('HF_TOKEN')
|
22 |
|
|
|
23 |
quantization_config = BitsAndBytesConfig(
|
24 |
load_in_8bit=True)
|
25 |
|
@@ -30,6 +33,11 @@ model = T5ForConditionalGeneration.from_pretrained('catyung/t5l-turbo-hotpot-033
|
|
30 |
|
31 |
tokenizer = T5Tokenizer.from_pretrained('catyung/t5l-turbo-hotpot-0331')
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
input_ids = tokenizer(rewrite_prompt, return_tensors="pt").input_ids.to(device)
|
35 |
|
@@ -38,5 +46,4 @@ outputs = model.generate(input_ids,max_new_tokens=50)
|
|
38 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
39 |
|
40 |
print(result)
|
41 |
-
|
42 |
```
|
|
|
7 |
|
8 |
<!-- Provide a longer summary of what this model is. -->
|
9 |
|
10 |
+
Query Rewriting in Retrieval-Augmented Large Language Models
|
11 |
|
12 |
+
Arxiv : https://arxiv.org/abs/2305.14283
|
13 |
+
|
14 |
+
Large Language Models (LLMs) play powerful, black-box readers in the retrieve-then-read pipeline, making remarkable progress in knowledge-intensive tasks. This work introduces a new framework, Rewrite-Retrieve-Read instead of the previous retrieve-then-read for the retrieval-augmented LLMs from the perspective of the query rewriting. We first prompt an LLM to generate the query, then use a web search engine to retrieve contexts. Furthermore, to better align the query to the frozen modules, we propose a trainable scheme for our pipeline. A small language model is adopted as a trainable rewriter to cater to the black-box LLM reader. The rewriter is trained using the feedback of the LLM reader by reinforcement learning.
|
15 |
- **Developed by:** https://github.com/xbmxb/RAG-query-rewriting
|
16 |
- **Model type:** google/t5-large
|
17 |
+
- **Checkpoint:** checkpoint_20
|
18 |
|
19 |
+
### Inference
|
20 |
|
21 |
+
```
|
22 |
+
from transformers import T5Tokenizer,T5ForConditionalGeneration,BitsAndBytesConfig
|
23 |
import torch
|
|
|
|
|
|
|
24 |
|
25 |
+
# 8 bit Quantization
|
26 |
quantization_config = BitsAndBytesConfig(
|
27 |
load_in_8bit=True)
|
28 |
|
|
|
33 |
|
34 |
tokenizer = T5Tokenizer.from_pretrained('catyung/t5l-turbo-hotpot-0331')
|
35 |
|
36 |
+
rewrite_prompt = f"""rewrite a better search query: {user_query}
|
37 |
+
answer:"""
|
38 |
+
|
39 |
+
# Inference
|
40 |
+
user_query = "What profession does Nicholas Ray and Elia Kazan have in common?"
|
41 |
|
42 |
input_ids = tokenizer(rewrite_prompt, return_tensors="pt").input_ids.to(device)
|
43 |
|
|
|
46 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
47 |
|
48 |
print(result)
|
|
|
49 |
```
|