Skip to content

Commit 0611eab

Browse files
authored
Document RAG again (#7377)
Do not merge before Monday
1 parent 7563d5a commit 0611eab

File tree

4 files changed

+115
-3
lines changed

4 files changed

+115
-3
lines changed

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ conversion utilities for the following models:
231231
model_doc/lxmert
232232
model_doc/bertgeneration
233233
model_doc/layoutlm
234+
model_doc/rag
234235
internal/modeling_utils
235236
internal/tokenization_utils
236237
internal/pipelines_utils

docs/source/model_doc/rag.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
RAG
2+
----------------------------------------------------
3+
4+
Overview
5+
~~~~~~~~~~~~~~~~~~~~~
6+
7+
Retrieval-augmented generation ("RAG") models combine the powers of pretrained dense retrieval (DPR) and
8+
sequence-to-sequence models. RAG models retrieve documents, pass them to a seq2seq model, then marginalize to generate
9+
outputs. The retriever and seq2seq modules are initialized from pretrained models, and fine-tuned jointly, allowing
10+
both retrieval and generation to adapt to downstream tasks.
11+
12+
It is based on the paper `Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
13+
<https://arxiv.org/abs/2005.11401>`__ by Patrick Lewis, Ethan Perez, Aleksandara Piktus, Fabio Petroni, Vladimir
14+
Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, Douwe Kiela.
15+
16+
The abstract from the paper is the following:
17+
18+
*Large pre-trained language models have been shown to store factual knowledge
19+
in their parameters, and achieve state-of-the-art results when fine-tuned on
20+
downstream NLP tasks. However, their ability to access and precisely manipulate
21+
knowledge is still limited, and hence on knowledge-intensive tasks, their
22+
performance lags behind task-specific architectures. Additionally, providing
23+
provenance for their decisions and updating their world knowledge remain open
24+
research problems. Pre-trained models with a differentiable access mechanism to
25+
explicit nonparametric memory can overcome this issue, but have so far been only
26+
investigated for extractive downstream tasks. We explore a general-purpose
27+
fine-tuning recipe for retrieval-augmented generation (RAG) — models which combine
28+
pre-trained parametric and non-parametric memory for language generation. We
29+
introduce RAG models where the parametric memory is a pre-trained seq2seq model and
30+
the non-parametric memory is a dense vector index of Wikipedia, accessed with
31+
a pre-trained neural retriever. We compare two RAG formulations, one which
32+
conditions on the same retrieved passages across the whole generated sequence, the
33+
other can use different passages per token. We fine-tune and evaluate our models
34+
on a wide range of knowledge-intensive NLP tasks and set the state-of-the-art
35+
on three open domain QA tasks, outperforming parametric seq2seq models and
36+
task-specific retrieve-and-extract architectures. For language generation tasks, we
37+
find that RAG models generate more specific, diverse and factual language than a
38+
state-of-the-art parametric-only seq2seq baseline.*
39+
40+
41+
42+
RagConfig
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44+
45+
.. autoclass:: transformers.RagConfig
46+
:members:
47+
48+
49+
RagTokenizer
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
.. autoclass:: transformers.RagTokenizer
53+
:members: prepare_seq2seq_batch
54+
55+
56+
Rag specific outputs
57+
~~~~~~~~~~~~~~~~~~~~~
58+
59+
.. autoclass:: transformers.modeling_rag.RetrievAugLMMarginOutput
60+
:members:
61+
62+
.. autoclass:: transformers.modeling_rag.RetrievAugLMOutput
63+
:members:
64+
65+
66+
RAGRetriever
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+
.. autoclass:: transformers.RagRetriever
70+
:members:
71+
72+
73+
RagModel
74+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75+
76+
.. autoclass:: transformers.RagModel
77+
:members: forward
78+
79+
80+
RagSequenceForGeneration
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
.. autoclass:: transformers.RagSequenceForGeneration
84+
:members: forward, generate
85+
86+
87+
RagTokenForGeneration
88+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89+
90+
.. autoclass:: transformers.RagTokenForGeneration
91+
:members: forward, generate

docs/source/model_summary.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,27 @@ DPR consists in three models:
672672

673673
DPR's pipeline (not implemented yet) uses a retrieval step to find the top k contexts given a certain question, and then it calls the reader with the question and the retrieved documents to get the answer.
674674

675+
RAG
676+
-----------------------------------------------------------------------------------------------------------------------
677+
678+
.. raw:: html
679+
680+
<a href="https://huggingface.co/models?filter=rag">
681+
<img alt="Models" src="https://img.shields.io/badge/All_model_pages-rag-blueviolet">
682+
</a>
683+
<a href="model_doc/rag.html">
684+
<img alt="Doc" src="https://img.shields.io/badge/Model_documentation-rag-blueviolet">
685+
</a>
686+
687+
`Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks <https://arxiv.org/abs/2005.11401>`_,
688+
Patrick Lewis, Ethan Perez, Aleksandara Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, Douwe Kiela
689+
690+
Retrieval-augmented generation ("RAG") models combine the powers of pretrained dense retrieval (DPR) and Seq2Seq models.
691+
RAG models retrieve docs, pass them to a seq2seq model, then marginalize to generate outputs.
692+
The retriever and seq2seq modules are initialized from pretrained models, and fine-tuned jointly, allowing both retrieval and generation to adapt to downstream tasks.
693+
694+
The two models RAG-Token and RAG-Sequence are available for generation.
695+
675696
More technical aspects
676697
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
677698

utils/check_repo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ def check_repo_quality():
314314
print("Checking all models are properly tested.")
315315
check_all_decorator_order()
316316
check_all_models_are_tested()
317-
# Uncomment me when RAG is back
318-
# print("Checking all models are properly documented.")
319-
# check_all_models_are_documented()
317+
print("Checking all models are properly documented.")
318+
check_all_models_are_documented()
320319

321320

322321
if __name__ == "__main__":

0 commit comments

Comments
 (0)