Migrate model card from transformers-repo
Browse filesRead announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/facebook/rag-sequence-base/README.md
README.md
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
thumbnail: https://huggingface.co/front/thumbnails/facebook.png
|
4 |
+
---
|
5 |
+
## RAG
|
6 |
+
|
7 |
+
This is a non-finetuned version of the RAG-Sequence model of the the paper [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/pdf/2005.11401.pdf)
|
8 |
+
by Patrick Lewis, Ethan Perez, Aleksandara Piktus et al.
|
9 |
+
|
10 |
+
Rag consits of a *question encoder*, *retriever* and a *generator*. The retriever should be a `RagRetriever` instance. The *question encoder* can be any model that can be loaded with `AutoModel` and the *generator* can be any model that can be loaded with `AutoModelForSeq2SeqLM`.
|
11 |
+
|
12 |
+
This model is a non-finetuned RAG-Sequence model and was created as follows:
|
13 |
+
|
14 |
+
```python
|
15 |
+
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration, AutoTokenizer
|
16 |
+
|
17 |
+
model = RagSequenceForGeneration.from_pretrained_question_encoder_generator("facebook/dpr-question_encoder-single-nq-base", "facebook/bart-large")
|
18 |
+
|
19 |
+
question_encoder_tokenizer = AutoTokenizer.from_pretrained("facebook/dpr-question_encoder-single-nq-base")
|
20 |
+
generator_tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large")
|
21 |
+
|
22 |
+
tokenizer = RagTokenizer(question_encoder_tokenizer, generator_tokenizer)
|
23 |
+
model.config.use_dummy_dataset = True
|
24 |
+
model.config.index_name = "exact"
|
25 |
+
retriever = RagRetriever(model.config, question_encoder_tokenizer, generator_tokenizer)
|
26 |
+
|
27 |
+
model.save_pretrained("./")
|
28 |
+
tokenizer.save_pretrained("./")
|
29 |
+
retriever.save_pretrained("./")
|
30 |
+
```
|
31 |
+
|
32 |
+
Note that the model is *uncased* so that all capital input letters are converted to lower-case.
|
33 |
+
|
34 |
+
## Usage:
|
35 |
+
|
36 |
+
*Note*: the model uses the *dummy* retriever as a default. Better results are obtained by using the full retriever,
|
37 |
+
by setting `config.index_name="legacy"` and `config.use_dummy_dataset=False`.
|
38 |
+
The model can be fine-tuned as follows:
|
39 |
+
|
40 |
+
```python
|
41 |
+
from transformers import RagTokenizer, RagRetriever, RagTokenForGeneration
|
42 |
+
|
43 |
+
tokenizer = RagTokenizer.from_pretrained("facebook/rag-sequence-base")
|
44 |
+
retriever = RagRetriever.from_pretrained("facebook/rag-sequence-base")
|
45 |
+
model = RagTokenForGeneration.from_pretrained("facebook/rag-sequence-base", retriever=retriever)
|
46 |
+
|
47 |
+
input_dict = tokenizer.prepare_seq2seq_batch("who holds the record in 100m freestyle", "michael phelps", return_tensors="pt")
|
48 |
+
|
49 |
+
outputs = model(input_dict["input_ids"], labels=input_dict["labels"])
|
50 |
+
|
51 |
+
loss = outputs.loss
|
52 |
+
|
53 |
+
# train on loss
|
54 |
+
```
|