mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-04 21:30:07 +06:00

* toctree * not-doctested.txt * collapse sections * feedback * update * rewrite get started sections * fixes * fix * loading models * fix * customize models * share * fix link * contribute part 1 * contribute pt 2 * fix toctree * tokenization pt 1 * Add new model (#32615) * v1 - working version * fix * fix * fix * fix * rename to correct name * fix title * fixup * rename files * fix * add copied from on tests * rename to `FalconMamba` everywhere and fix bugs * fix quantization + accelerate * fix copies * add `torch.compile` support * fix tests * fix tests and add slow tests * copies on config * merge the latest changes * fix tests * add few lines about instruct * Apply suggestions from code review Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * fix * fix tests --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * "to be not" -> "not to be" (#32636) * "to be not" -> "not to be" * Update sam.md * Update trainer.py * Update modeling_utils.py * Update test_modeling_utils.py * Update test_modeling_utils.py * fix hfoption tag * tokenization pt. 2 * image processor * fix toctree * backbones * feature extractor * fix file name * processor * update not-doctested * update * make style * fix toctree * revision * make fixup * fix toctree * fix * make style * fix hfoption tag * pipeline * pipeline gradio * pipeline web server * add pipeline * fix toctree * not-doctested * prompting * llm optims * fix toctree * fixes * cache * text generation * fix * chat pipeline * chat stuff * xla * torch.compile * cpu inference * toctree * gpu inference * agents and tools * gguf/tiktoken * finetune * toctree * trainer * trainer pt 2 * optims * optimizers * accelerate * parallelism * fsdp * update * distributed cpu * hardware training * gpu training * gpu training 2 * peft * distrib debug * deepspeed 1 * deepspeed 2 * chat toctree * quant pt 1 * quant pt 2 * fix toctree * fix * fix * quant pt 3 * quant pt 4 * serialization * torchscript * scripts * tpu * review * model addition timeline * modular * more reviews * reviews * fix toctree * reviews reviews * continue reviews * more reviews * modular transformers * more review * zamba2 * fix * all frameworks * pytorch * supported model frameworks * flashattention * rm check_table * not-doctested.txt * rm check_support_list.py * feedback * updates/feedback * review * feedback * fix * update * feedback * updates * update --------- Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
122 lines
4.7 KiB
Markdown
122 lines
4.7 KiB
Markdown
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations under the License.
|
|
|
|
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
|
rendered properly in your Markdown viewer.
|
|
|
|
-->
|
|
|
|
# RAG
|
|
|
|
<div class="flex flex-wrap space-x-1">
|
|
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
|
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
|
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
|
</div>
|
|
|
|
## Overview
|
|
|
|
Retrieval-augmented generation ("RAG") models combine the powers of pretrained dense retrieval (DPR) and
|
|
sequence-to-sequence models. RAG models retrieve documents, pass them to a seq2seq model, then marginalize to generate
|
|
outputs. The retriever and seq2seq modules are initialized from pretrained models, and fine-tuned jointly, allowing
|
|
both retrieval and generation to adapt to downstream tasks.
|
|
|
|
It is based on the paper [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/abs/2005.11401) by 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.
|
|
|
|
The abstract from the paper is the following:
|
|
|
|
*Large pre-trained language models have been shown to store factual knowledge in their parameters, and achieve
|
|
state-of-the-art results when fine-tuned on downstream NLP tasks. However, their ability to access and precisely
|
|
manipulate knowledge is still limited, and hence on knowledge-intensive tasks, their performance lags behind
|
|
task-specific architectures. Additionally, providing provenance for their decisions and updating their world knowledge
|
|
remain open research problems. Pre-trained models with a differentiable access mechanism to explicit nonparametric
|
|
memory can overcome this issue, but have so far been only investigated for extractive downstream tasks. We explore a
|
|
general-purpose fine-tuning recipe for retrieval-augmented generation (RAG) — models which combine pre-trained
|
|
parametric and non-parametric memory for language generation. We introduce RAG models where the parametric memory is a
|
|
pre-trained seq2seq model and the non-parametric memory is a dense vector index of Wikipedia, accessed with a
|
|
pre-trained neural retriever. We compare two RAG formulations, one which conditions on the same retrieved passages
|
|
across the whole generated sequence, the other can use different passages per token. We fine-tune and evaluate our
|
|
models on a wide range of knowledge-intensive NLP tasks and set the state-of-the-art on three open domain QA tasks,
|
|
outperforming parametric seq2seq models and task-specific retrieve-and-extract architectures. For language generation
|
|
tasks, we find that RAG models generate more specific, diverse and factual language than a state-of-the-art
|
|
parametric-only seq2seq baseline.*
|
|
|
|
This model was contributed by [ola13](https://huggingface.co/ola13).
|
|
|
|
## Usage tips
|
|
|
|
Retrieval-augmented generation ("RAG") models combine the powers of pretrained dense retrieval (DPR) and Seq2Seq models.
|
|
RAG models retrieve docs, pass them to a seq2seq model, then marginalize to generate outputs. The retriever and seq2seq
|
|
modules are initialized from pretrained models, and fine-tuned jointly, allowing both retrieval and generation to adapt
|
|
to downstream tasks.
|
|
|
|
## RagConfig
|
|
|
|
[[autodoc]] RagConfig
|
|
|
|
## RagTokenizer
|
|
|
|
[[autodoc]] RagTokenizer
|
|
|
|
## Rag specific outputs
|
|
|
|
[[autodoc]] models.rag.modeling_rag.RetrievAugLMMarginOutput
|
|
|
|
[[autodoc]] models.rag.modeling_rag.RetrievAugLMOutput
|
|
|
|
## RagRetriever
|
|
|
|
[[autodoc]] RagRetriever
|
|
|
|
<frameworkcontent>
|
|
<pt>
|
|
|
|
## RagModel
|
|
|
|
[[autodoc]] RagModel
|
|
- forward
|
|
|
|
## RagSequenceForGeneration
|
|
|
|
[[autodoc]] RagSequenceForGeneration
|
|
- forward
|
|
- generate
|
|
|
|
## RagTokenForGeneration
|
|
|
|
[[autodoc]] RagTokenForGeneration
|
|
- forward
|
|
- generate
|
|
|
|
</pt>
|
|
<tf>
|
|
|
|
## TFRagModel
|
|
|
|
[[autodoc]] TFRagModel
|
|
- call
|
|
|
|
## TFRagSequenceForGeneration
|
|
|
|
[[autodoc]] TFRagSequenceForGeneration
|
|
- call
|
|
- generate
|
|
|
|
## TFRagTokenForGeneration
|
|
|
|
[[autodoc]] TFRagTokenForGeneration
|
|
- call
|
|
- generate
|
|
|
|
</tf>
|
|
</frameworkcontent>
|