Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
9f1544b9
"examples/vscode:/vscode.git/clone" did not exist on "908a28894cd4c3f6e31d73b39e470f59b1c19aef"
Unverified
Commit
9f1544b9
authored
Sep 18, 2020
by
Patrick von Platen
Committed by
GitHub
Sep 18, 2020
Browse files
Create README.md
parent
5c1d5ea6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
model_cards/facebook/rag-token-nq/README.md
model_cards/facebook/rag-token-nq/README.md
+25
-0
No files found.
model_cards/facebook/rag-token-nq/README.md
0 → 100644
View file @
9f1544b9
## RAG
This is the RAG-Token Model of the the paper
[
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
](
https://arxiv.org/pdf/2005.11401.pdf
)
by Aleksandra Piktus et al.
## Usage:
```
python
from
transformers
import
RagTokenizer
,
RagRetriever
,
RagTokenForGeneration
tokenizer
=
RagTokenizer
.
from_pretrained
(
"facebook/rag-token-nq"
)
retriever
=
RagRetriever
.
from_pretrained
(
"facebook/rag-token-nq"
,
index_name
=
"exact"
,
use_dummy_dataset
=
True
)
model
=
RagTokenForGeneration
.
from_pretrained
(
"facebook/rag-token-nq"
,
retriever
=
retriever
)
input_dict
=
tokenizer
.
prepare_seq2seq_batch
(
"How many people live in Paris?"
,
"In Paris, there are 10 million people."
,
return_tensors
=
"pt"
)
outputs
=
model
(
input_ids
=
input_dict
[
"input_ids"
],
labels
=
input_dict
[
"labels"
])
# outputs.loss should give 76.1230
generated
=
model
.
generate
(
input_ids
=
input_dict
[
"input_ids"
],
num_beams
=
4
)
generated_string
=
tokenizer
.
batch_decode
(
generated
,
skip_special_tokens
=
True
)
# generated_string should give 270,000 -> not quite correct the answer, but it also only uses a dummy index
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment