import{S as Lb,i as Sb,s as Db,e as s,k as p,w as T,t as o,M as Ib,c as a,d as t,m as h,a as d,x as w,h as n,b as l,N as Ub,G as e,g as v,y,q as k,o as q,B as x,v as Hb,L as an}from"../../chunks/vendor-hf-doc-builder.js";import{T as ge}from"../../chunks/Tip-hf-doc-builder.js";import{D as A}from"../../chunks/Docstring-hf-doc-builder.js";import{C as dn}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as _e}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as sn}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Wb(F){let c,b,m,g,f;return g=new dn({props:{code:`# To load the default "wiki_dpr" dataset with 21M passages from wikipedia (index name is 'compressed' or 'exact')
from transformers import RagRetriever

retriever = RagRetriever.from_pretrained(
    "facebook/dpr-ctx_encoder-single-nq-base", dataset="wiki_dpr", index_name="compressed"
)

# To load your own indexed dataset built with the datasets library. More info on how to build the indexed dataset in examples/rag/use_own_knowledge_dataset.py
from transformers import RagRetriever

dataset = (
    ...
)  # dataset must be a datasets.Datasets object with columns "title", "text" and "embeddings", and it must have a faiss index
retriever = RagRetriever.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base", indexed_dataset=dataset)

# To load your own indexed dataset built with the datasets library that was saved on disk. More info in examples/rag/use_own_knowledge_dataset.py
from transformers import RagRetriever

dataset_path = "path/to/my/dataset"  # dataset saved via *dataset.save_to_disk(...)*
index_path = "path/to/my/index.faiss"  # faiss index saved via *dataset.get_index("embeddings").save(...)*
retriever = RagRetriever.from_pretrained(
    "facebook/dpr-ctx_encoder-single-nq-base",
    index_name="custom",
    passages_path=dataset_path,
    index_path=index_path,
)

# To load the legacy index built originally for Rag's paper
from transformers import RagRetriever

retriever = RagRetriever.from_pretrained("facebook/dpr-ctx_encoder-single-nq-base", index_name="legacy")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To load the default &quot;wiki_dpr&quot; dataset with 21M passages from wikipedia (index name is &#x27;compressed&#x27; or &#x27;exact&#x27;)</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> RagRetriever

<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/dpr-ctx_encoder-single-nq-base&quot;</span>, dataset=<span class="hljs-string">&quot;wiki_dpr&quot;</span>, index_name=<span class="hljs-string">&quot;compressed&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To load your own indexed dataset built with the datasets library. More info on how to build the indexed dataset in examples/rag/use_own_knowledge_dataset.py</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> RagRetriever

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = (
<span class="hljs-meta">... </span>    ...
<span class="hljs-meta">... </span>)  <span class="hljs-comment"># dataset must be a datasets.Datasets object with columns &quot;title&quot;, &quot;text&quot; and &quot;embeddings&quot;, and it must have a faiss index</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(<span class="hljs-string">&quot;facebook/dpr-ctx_encoder-single-nq-base&quot;</span>, indexed_dataset=dataset)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To load your own indexed dataset built with the datasets library that was saved on disk. More info in examples/rag/use_own_knowledge_dataset.py</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> RagRetriever

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset_path = <span class="hljs-string">&quot;path/to/my/dataset&quot;</span>  <span class="hljs-comment"># dataset saved via *dataset.save_to_disk(...)*</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>index_path = <span class="hljs-string">&quot;path/to/my/index.faiss&quot;</span>  <span class="hljs-comment"># faiss index saved via *dataset.get_index(&quot;embeddings&quot;).save(...)*</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/dpr-ctx_encoder-single-nq-base&quot;</span>,
<span class="hljs-meta">... </span>    index_name=<span class="hljs-string">&quot;custom&quot;</span>,
<span class="hljs-meta">... </span>    passages_path=dataset_path,
<span class="hljs-meta">... </span>    index_path=index_path,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># To load the legacy index built originally for Rag&#x27;s paper</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> RagRetriever

<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(<span class="hljs-string">&quot;facebook/dpr-ctx_encoder-single-nq-base&quot;</span>, index_name=<span class="hljs-string">&quot;legacy&quot;</span>)`}}),{c(){c=s("p"),b=o("Examples:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Examples:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function Bb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function Qb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function Kb(F){let c,b,m,g,f;return g=new dn({props:{code:`from transformers import AutoTokenizer, RagRetriever, RagModel
import torch

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-base")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-token-base", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = RagModel.from_pretrained("facebook/rag-token-base", retriever=retriever)

inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
outputs = model(input_ids=inputs["input_ids"])`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, RagModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = RagModel.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>, retriever=retriever)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids=inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function Vb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function Yb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function Jb(F){let c,b,m,g,f;return g=new dn({props:{code:`from transformers import AutoTokenizer, RagRetriever, RagSequenceForGeneration
import torch

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-sequence-nq")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-sequence-nq", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = RagSequenceForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)

inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
targets = tokenizer(text_target="In Paris, there are 10 million people.", return_tensors="pt")
input_ids = inputs["input_ids"]
labels = targets["input_ids"]
outputs = model(input_ids=input_ids, labels=labels)

# or use retriever separately
model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", use_dummy_dataset=True)
# 1. Encode
question_hidden_states = model.question_encoder(input_ids)[0]
# 2. Retrieve
docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors="pt")
doc_scores = torch.bmm(
    question_hidden_states.unsqueeze(1), docs_dict["retrieved_doc_embeds"].float().transpose(1, 2)
).squeeze(1)
# 3. Forward to generator
outputs = model(
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
    decoder_input_ids=labels,
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, RagSequenceForGeneration
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = RagSequenceForGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, retriever=retriever)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>targets = tokenizer(text_target=<span class="hljs-string">&quot;In Paris, there are 10 million people.&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = targets[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids=input_ids, labels=labels)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or use retriever separately</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = RagSequenceForGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 1. Encode</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>question_hidden_states = model.question_encoder(input_ids)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2. Retrieve</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>doc_scores = torch.bmm(
<span class="hljs-meta">... </span>    question_hidden_states.unsqueeze(<span class="hljs-number">1</span>), docs_dict[<span class="hljs-string">&quot;retrieved_doc_embeds&quot;</span>].<span class="hljs-built_in">float</span>().transpose(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)
<span class="hljs-meta">... </span>).squeeze(<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 3. Forward to generator</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>    decoder_input_ids=labels,
<span class="hljs-meta">... </span>)`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function Xb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function Zb(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function eT(F){let c,b,m,g,f;return g=new dn({props:{code:`from transformers import AutoTokenizer, RagRetriever, RagTokenForGeneration
import torch

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-nq")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-token-nq", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)

inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
targets = tokenizer(text_target="In Paris, there are 10 million people.", return_tensors="pt")
input_ids = inputs["input_ids"]
labels = targets["input_ids"]
outputs = model(input_ids=input_ids, labels=labels)

# or use retriever separately
model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", use_dummy_dataset=True)
# 1. Encode
question_hidden_states = model.question_encoder(input_ids)[0]
# 2. Retrieve
docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors="pt")
doc_scores = torch.bmm(
    question_hidden_states.unsqueeze(1), docs_dict["retrieved_doc_embeds"].float().transpose(1, 2)
).squeeze(1)
# 3. Forward to generator
outputs = model(
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
    decoder_input_ids=labels,
)

# or directly generate
generated = model.generate(
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
)
generated_string = tokenizer.batch_decode(generated, skip_special_tokens=True)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, RagTokenForGeneration
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = RagTokenForGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, retriever=retriever)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>targets = tokenizer(text_target=<span class="hljs-string">&quot;In Paris, there are 10 million people.&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = targets[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids=input_ids, labels=labels)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or use retriever separately</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = RagTokenForGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 1. Encode</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>question_hidden_states = model.question_encoder(input_ids)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2. Retrieve</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>doc_scores = torch.bmm(
<span class="hljs-meta">... </span>    question_hidden_states.unsqueeze(<span class="hljs-number">1</span>), docs_dict[<span class="hljs-string">&quot;retrieved_doc_embeds&quot;</span>].<span class="hljs-built_in">float</span>().transpose(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)
<span class="hljs-meta">... </span>).squeeze(<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 3. Forward to generator</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>    decoder_input_ids=labels,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or directly generate</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated = model.generate(
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_string = tokenizer.batch_decode(generated, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function tT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function oT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function nT(F){let c,b,m,g,f;return g=new dn({props:{code:`from transformers import AutoTokenizer, RagRetriever, TFRagModel
import torch

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-base")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-token-base", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = TFRagModel.from_pretrained("facebook/rag-token-base", retriever=retriever, from_pt=True)

input_dict = tokenizer.prepare_seq2seq_batch(
    "How many people live in Paris?", "In Paris, there are 10 million people.", return_tensors="tf"
)
input_ids = input_dict["input_ids"]
outputs = model(input_ids)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, TFRagModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFRagModel.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-base&quot;</span>, retriever=retriever, from_pt=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>input_dict = tokenizer.prepare_seq2seq_batch(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, <span class="hljs-string">&quot;In Paris, there are 10 million people.&quot;</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = input_dict[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids)`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function rT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function sT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function aT(F){let c,b,m,g,f;return g=new dn({props:{code:`from transformers import AutoTokenizer, RagRetriever, TFRagSequenceForGeneration

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-sequence-nq")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-sequence-nq", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = TFRagSequenceForGeneration.from_pretrained(
    "facebook/rag-sequence-nq", retriever=retriever, from_pt=True
)

input_dict = tokenizer.prepare_seq2seq_batch(
    "How many people live in Paris?", "In Paris, there are 10 million people.", return_tensors="tf"
)
outputs = model(input_dict, output_retrieved=True)

# or use retriever separately
# 1. Encode
input_ids = input_dict["input_ids"]
question_hidden_states = model.question_encoder(input_ids)[0]
# 2. Retrieve
docs_dict = retriever(input_ids.numpy(), question_hidden_states.numpy(), return_tensors="tf")
doc_scores = tf.squeeze(
    tf.matmul(
        tf.expand_dims(question_hidden_states, axis=1), docs_dict["retrieved_doc_embeds"], transpose_b=True
    ),
    axis=1,
)
# 3. Forward to generator
outputs = model(
    inputs=None,
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
    decoder_input_ids=input_dict["labels"],
)

# or directly generate
generated = model.generate(
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
)
generated_string = tokenizer.batch_decode(generated, skip_special_tokens=True)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, TFRagSequenceForGeneration

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFRagSequenceForGeneration.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-sequence-nq&quot;</span>, retriever=retriever, from_pt=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>input_dict = tokenizer.prepare_seq2seq_batch(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, <span class="hljs-string">&quot;In Paris, there are 10 million people.&quot;</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_dict, output_retrieved=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or use retriever separately</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 1. Encode</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = input_dict[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>question_hidden_states = model.question_encoder(input_ids)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2. Retrieve</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>docs_dict = retriever(input_ids.numpy(), question_hidden_states.numpy(), return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>doc_scores = tf.squeeze(
<span class="hljs-meta">... </span>    tf.matmul(
<span class="hljs-meta">... </span>        tf.expand_dims(question_hidden_states, axis=<span class="hljs-number">1</span>), docs_dict[<span class="hljs-string">&quot;retrieved_doc_embeds&quot;</span>], transpose_b=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    axis=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 3. Forward to generator</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(
<span class="hljs-meta">... </span>    inputs=<span class="hljs-literal">None</span>,
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>    decoder_input_ids=input_dict[<span class="hljs-string">&quot;labels&quot;</span>],
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or directly generate</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated = model.generate(
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_string = tokenizer.batch_decode(generated, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function dT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function iT(F){let c,b,m,g,f;return{c(){c=s("p"),b=o("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=s("code"),g=o("Module"),f=o(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(u,"CODE",{});var R=d(m);g=n(R,"Module"),R.forEach(t),f=n(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(t)},m(i,u){v(i,c,u),e(c,b),e(c,m),e(m,g),e(c,f)},d(i){i&&t(c)}}}function cT(F){let c,b,m,g,f;return g=new dn({props:{code:`import tensorflow as tf
from transformers import AutoTokenizer, RagRetriever, TFRagTokenForGeneration

tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-nq")
retriever = RagRetriever.from_pretrained(
    "facebook/rag-token-nq", index_name="exact", use_dummy_dataset=True
)
# initialize with RagRetriever to do everything in one forward call
model = TFRagTokenForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever, from_pt=True)

input_dict = tokenizer.prepare_seq2seq_batch(
    "How many people live in Paris?", "In Paris, there are 10 million people.", return_tensors="tf"
)
outputs = model(input_dict, output_retrieved=True)

# or use retriever separately
# 1. Encode
input_ids = input_dict["input_ids"]
question_hidden_states = model.question_encoder(input_ids)[0]
# 2. Retrieve
docs_dict = retriever(input_ids.numpy(), question_hidden_states.numpy(), return_tensors="tf")
doc_scores = tf.squeeze(
    tf.matmul(
        tf.expand_dims(question_hidden_states, axis=1), docs_dict["retrieved_doc_embeds"], transpose_b=True
    ),
    axis=1,
)
# 3. Forward to generator
outputs = model(
    inputs=None,
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
    decoder_input_ids=input_dict["labels"],
)

# or directly generate
generated = model.generate(
    context_input_ids=docs_dict["context_input_ids"],
    context_attention_mask=docs_dict["context_attention_mask"],
    doc_scores=doc_scores,
)
generated_string = tokenizer.batch_decode(generated, skip_special_tokens=True)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, RagRetriever, TFRagTokenForGeneration

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>retriever = RagRetriever.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, index_name=<span class="hljs-string">&quot;exact&quot;</span>, use_dummy_dataset=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize with RagRetriever to do everything in one forward call</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFRagTokenForGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/rag-token-nq&quot;</span>, retriever=retriever, from_pt=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>input_dict = tokenizer.prepare_seq2seq_batch(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;How many people live in Paris?&quot;</span>, <span class="hljs-string">&quot;In Paris, there are 10 million people.&quot;</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_dict, output_retrieved=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or use retriever separately</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 1. Encode</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = input_dict[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>question_hidden_states = model.question_encoder(input_ids)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2. Retrieve</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>docs_dict = retriever(input_ids.numpy(), question_hidden_states.numpy(), return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>doc_scores = tf.squeeze(
<span class="hljs-meta">... </span>    tf.matmul(
<span class="hljs-meta">... </span>        tf.expand_dims(question_hidden_states, axis=<span class="hljs-number">1</span>), docs_dict[<span class="hljs-string">&quot;retrieved_doc_embeds&quot;</span>], transpose_b=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    axis=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 3. Forward to generator</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(
<span class="hljs-meta">... </span>    inputs=<span class="hljs-literal">None</span>,
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>    decoder_input_ids=input_dict[<span class="hljs-string">&quot;labels&quot;</span>],
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># or directly generate</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated = model.generate(
<span class="hljs-meta">... </span>    context_input_ids=docs_dict[<span class="hljs-string">&quot;context_input_ids&quot;</span>],
<span class="hljs-meta">... </span>    context_attention_mask=docs_dict[<span class="hljs-string">&quot;context_attention_mask&quot;</span>],
<span class="hljs-meta">... </span>    doc_scores=doc_scores,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_string = tokenizer.batch_decode(generated, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),{c(){c=s("p"),b=o("Example:"),m=p(),T(g.$$.fragment)},l(i){c=a(i,"P",{});var u=d(c);b=n(u,"Example:"),u.forEach(t),m=h(i),w(g.$$.fragment,i)},m(i,u){v(i,c,u),e(c,b),v(i,m,u),y(g,i,u),f=!0},p:an,i(i){f||(k(g.$$.fragment,i),f=!0)},o(i){q(g.$$.fragment,i),f=!1},d(i){i&&t(c),i&&t(m),x(g,i)}}}function lT(F){let c,b,m,g,f,i,u,R,ai,Ba,Ut,cn,ln,b_,Qa,ke,Ve,Mr,Ht,di,Gr,ii,Ka,pn,ci,Va,Ye,li,Wt,pi,hi,Ya,hn,ui,Ja,un,Pr,mi,Xa,Je,gi,Bt,_i,fi,Za,mn,vi,ed,gn,Nr,bi,td,qe,Xe,Or,Qt,Ti,Cr,wi,od,ee,Kt,yi,de,_n,ki,qi,Lr,xi,Ri,fn,Fi,$i,vn,zi,Ei,ji,Ze,Vt,Ai,Yt,Mi,bn,Gi,Pi,Ni,et,Jt,Oi,Xt,Ci,Tn,Li,Si,nd,xe,tt,Sr,Zt,Di,Dr,Ii,rd,eo,to,sd,Re,ot,Ir,oo,Ui,Ur,Hi,ad,Fe,no,Wi,Hr,Bi,dd,ro,so,id,$e,nt,Wr,ao,Qi,Br,Ki,cd,Z,io,Vi,Qr,Yi,Ji,rt,Xi,st,co,Zi,Kr,ec,tc,at,lo,oc,ze,nc,Vr,rc,sc,Yr,ac,dc,ic,dt,po,cc,ho,lc,Jr,pc,hc,ld,Ee,it,Xr,uo,uc,Zr,mc,pd,L,mo,gc,je,_c,wn,fc,vc,es,bc,Tc,wc,ct,yc,ts,kc,qc,te,xc,os,Rc,Fc,yn,$c,zc,ns,Ec,jc,kn,Ac,Mc,Gc,M,Pc,qn,Nc,Oc,rs,Cc,Lc,ss,Sc,Dc,as,Ic,Uc,ds,Hc,Wc,xn,Bc,Qc,is,Kc,Vc,Rn,Yc,Jc,Fn,Xc,Zc,cs,el,tl,ol,go,nl,$n,rl,sl,al,_o,dl,fo,il,cl,ll,ie,vo,pl,Ae,hl,zn,ul,ml,ls,gl,_l,fl,lt,vl,pt,hd,Me,ht,ps,bo,bl,hs,Tl,ud,E,To,wl,Ge,yl,En,kl,ql,us,xl,Rl,Fl,ut,$l,ms,zl,El,gs,jl,Al,oe,Ml,_s,Gl,Pl,jn,Nl,Ol,fs,Cl,Ll,An,Sl,Dl,Il,G,Ul,Mn,Hl,Wl,vs,Bl,Ql,bs,Kl,Vl,Ts,Yl,Jl,ws,Xl,Zl,Gn,ep,tp,ys,op,np,Pn,rp,sp,Nn,ap,dp,ks,ip,cp,lp,wo,pp,On,hp,up,mp,yo,gp,ko,_p,fp,vp,ce,qo,bp,Pe,Tp,Cn,wp,yp,qs,kp,qp,xp,mt,Rp,gt,Fp,_t,xo,$p,Ro,zp,Ln,Ep,jp,md,Ne,ft,xs,Fo,Ap,Rs,Mp,gd,j,$o,Gp,Oe,Pp,Sn,Np,Op,Fs,Cp,Lp,Sp,vt,Dp,$s,Ip,Up,zs,Hp,Wp,ne,Bp,Es,Qp,Kp,Dn,Vp,Yp,js,Jp,Xp,In,Zp,eh,th,P,oh,Un,nh,rh,As,sh,ah,Ms,dh,ih,Gs,ch,lh,Ps,ph,hh,Hn,uh,mh,Ns,gh,_h,Wn,fh,vh,Bn,bh,Th,Os,wh,yh,kh,zo,qh,Qn,xh,Rh,Fh,Eo,$h,jo,zh,Eh,jh,le,Ao,Ah,Ce,Mh,Kn,Gh,Ph,Cs,Nh,Oh,Ch,bt,Lh,Tt,Sh,wt,Mo,Dh,Ls,Ih,_d,Le,yt,Ss,Go,Uh,Ds,Hh,fd,N,Po,Wh,Se,Bh,Vn,Qh,Kh,Is,Vh,Yh,Jh,kt,Xh,Us,Zh,eu,re,tu,Hs,ou,nu,Yn,ru,su,Ws,au,du,Jn,iu,cu,lu,S,pu,Xn,hu,uu,Bs,mu,gu,Qs,_u,fu,Ks,vu,bu,Vs,Tu,wu,Zn,yu,ku,Ys,qu,xu,er,Ru,Fu,Js,$u,zu,Eu,No,ju,tr,Au,Mu,Gu,Oo,Pu,Co,Nu,Ou,Cu,Xs,Lu,Su,pe,Lo,Du,De,Iu,or,Uu,Hu,Zs,Wu,Bu,Qu,qt,Ku,xt,vd,Ie,Rt,ea,So,Vu,ta,Yu,bd,$,Do,Ju,Ue,Xu,nr,Zu,em,oa,tm,om,nm,Ft,rm,na,sm,am,ra,dm,im,se,cm,sa,lm,pm,rr,hm,um,aa,mm,gm,sr,_m,fm,vm,D,bm,ar,Tm,wm,da,ym,km,ia,qm,xm,ca,Rm,Fm,la,$m,zm,dr,Em,jm,pa,Am,Mm,ir,Gm,Pm,ha,Nm,Om,Cm,Io,Lm,cr,Sm,Dm,Im,Uo,Um,Ho,Hm,Wm,Bm,ua,Qm,Km,he,Wo,Vm,He,Ym,lr,Jm,Xm,ma,Zm,eg,tg,$t,og,zt,ng,Et,Bo,rg,Qo,sg,pr,ag,dg,Td,We,jt,ga,Ko,ig,_a,cg,wd,z,Vo,lg,Be,pg,hr,hg,ug,fa,mg,gg,_g,At,fg,va,vg,bg,ba,Tg,wg,ae,yg,Ta,kg,qg,ur,xg,Rg,wa,Fg,$g,mr,zg,Eg,jg,I,Ag,gr,Mg,Gg,ya,Pg,Ng,ka,Og,Cg,qa,Lg,Sg,xa,Dg,Ig,_r,Ug,Hg,Ra,Wg,Bg,fr,Qg,Kg,Fa,Vg,Yg,Jg,Yo,Xg,vr,Zg,e_,t_,Jo,o_,Xo,n_,r_,s_,$a,a_,d_,ue,Zo,i_,Qe,c_,br,l_,p_,za,h_,u_,m_,Mt,g_,Gt,__,Pt,en,f_,Ea,v_,yd;return i=new _e({}),Ht=new _e({}),Qt=new _e({}),Kt=new A({props:{name:"class transformers.RagConfig",anchor:"transformers.RagConfig",parameters:[{name:"vocab_size",val:" = None"},{name:"is_encoder_decoder",val:" = True"},{name:"prefix",val:" = None"},{name:"bos_token_id",val:" = None"},{name:"pad_token_id",val:" = None"},{name:"eos_token_id",val:" = None"},{name:"decoder_start_token_id",val:" = None"},{name:"title_sep",val:" = ' / '"},{name:"doc_sep",val:" = ' // '"},{name:"n_docs",val:" = 5"},{name:"max_combined_length",val:" = 300"},{name:"retrieval_vector_size",val:" = 768"},{name:"retrieval_batch_size",val:" = 8"},{name:"dataset",val:" = 'wiki_dpr'"},{name:"dataset_split",val:" = 'train'"},{name:"index_name",val:" = 'compressed'"},{name:"index_path",val:" = None"},{name:"passages_path",val:" = None"},{name:"use_dummy_dataset",val:" = False"},{name:"reduce_loss",val:" = False"},{name:"label_smoothing",val:" = 0.0"},{name:"do_deduplication",val:" = True"},{name:"exclude_bos_score",val:" = False"},{name:"do_marginalize",val:" = False"},{name:"output_retrieved",val:" = False"},{name:"use_cache",val:" = True"},{name:"forced_eos_token_id",val:" = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagConfig.title_sep",description:`<strong>title_sep</strong> (<code>str</code>, <em>optional</em>, defaults to  <code>&quot; / &quot;</code>) &#x2014;
Separator inserted between the title and the text of the retrieved document when calling <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>.`,name:"title_sep"},{anchor:"transformers.RagConfig.doc_sep",description:`<strong>doc_sep</strong> (<code>str</code>, <em>optional</em>, defaults to  <code>&quot; // &quot;</code>) &#x2014;
Separator inserted between the text of the retrieved document and the original input when calling
<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>.`,name:"doc_sep"},{anchor:"transformers.RagConfig.n_docs",description:`<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of documents to retrieve.`,name:"n_docs"},{anchor:"transformers.RagConfig.max_combined_length",description:`<strong>max_combined_length</strong> (<code>int</code>, <em>optional</em>, defaults to 300) &#x2014;
Max length of contextualized input returned by <code>__call__()</code>.`,name:"max_combined_length"},{anchor:"transformers.RagConfig.retrieval_vector_size",description:`<strong>retrieval_vector_size</strong> (<code>int</code>, <em>optional</em>, defaults to 768) &#x2014;
Dimensionality of the document embeddings indexed by <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>.`,name:"retrieval_vector_size"},{anchor:"transformers.RagConfig.retrieval_batch_size",description:`<strong>retrieval_batch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 8) &#x2014;
Retrieval batch size, defined as the number of queries issues concurrently to the faiss index encapsulated
<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>.`,name:"retrieval_batch_size"},{anchor:"transformers.RagConfig.dataset",description:`<strong>dataset</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;wiki_dpr&quot;</code>) &#x2014;
A dataset identifier of the indexed dataset in HuggingFace Datasets (list all available datasets and ids
using <code>datasets.list_datasets()</code>).`,name:"dataset"},{anchor:"transformers.RagConfig.dataset_split",description:`<strong>dataset_split</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;train&quot;</code>) &#x2014;
Which split of the <code>dataset</code> to load.`,name:"dataset_split"},{anchor:"transformers.RagConfig.index_name",description:`<strong>index_name</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;compressed&quot;</code>) &#x2014;
The index name of the index associated with the <code>dataset</code>. One can choose between <code>&quot;legacy&quot;</code>, <code>&quot;exact&quot;</code> and
<code>&quot;compressed&quot;</code>.`,name:"index_name"},{anchor:"transformers.RagConfig.index_path",description:`<strong>index_path</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The path to the serialized faiss index on disk.`,name:"index_path"},{anchor:"transformers.RagConfig.passages_path",description:`<strong>passages_path</strong> (<code>str</code>, <em>optional</em>) &#x2014;
A path to text passages compatible with the faiss index. Required if using
<code>LegacyIndex</code>`,name:"passages_path"},{anchor:"transformers.RagConfig.use_dummy_dataset",description:`<strong>use_dummy_dataset</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to load a &#x201C;dummy&#x201D; variant of the dataset specified by <code>dataset</code>.`,name:"use_dummy_dataset"},{anchor:"transformers.RagConfig.label_smoothing",description:`<strong>label_smoothing</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Only relevant if <code>return_loss</code> is set to <code>True</code>. Controls the <code>epsilon</code> parameter value for label smoothing
in the loss calculation. If set to 0, no label smoothing is performed.`,name:"label_smoothing"},{anchor:"transformers.RagConfig.do_marginalize",description:`<strong>do_marginalize</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
If <code>True</code>, the logits are marginalized over all documents by making use of
<code>torch.nn.functional.log_softmax</code>.`,name:"do_marginalize"},{anchor:"transformers.RagConfig.reduce_loss",description:`<strong>reduce_loss</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to reduce the NLL loss using the <code>torch.Tensor.sum</code> operation.`,name:"reduce_loss"},{anchor:"transformers.RagConfig.do_deduplication",description:`<strong>do_deduplication</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to deduplicate the generations from different context documents for a given input. Has to be
set to <code>False</code> if used while training with distributed backend.`,name:"do_deduplication"},{anchor:"transformers.RagConfig.exclude_bos_score",description:`<strong>exclude_bos_score</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to disregard the BOS token when computing the loss.`,name:"exclude_bos_score"},{anchor:"transformers.RagConfig.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>, defaults to <code>False</code>) &#x2014;
If set to <code>True</code>, <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code> are returned. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.RagConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models).`,name:"use_cache"},{anchor:"transformers.RagConfig.forced_eos_token_id",description:`<strong>forced_eos_token_id</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The id of the token to force as the last generated token when <code>max_length</code> is reached. Usually set to
<code>eos_token_id</code>.`,name:"forced_eos_token_id"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/configuration_rag.py#L82"}}),Vt=new A({props:{name:"from_question_encoder_generator_configs",anchor:"transformers.RagConfig.from_question_encoder_generator_configs",parameters:[{name:"question_encoder_config",val:": PretrainedConfig"},{name:"generator_config",val:": PretrainedConfig"},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/configuration_rag.py#L170",returnDescription:`
<p>An instance of a configuration object</p>
`,returnType:`
<p><a
  href="/docs/transformers/v4.27.1/en/model_doc/encoder-decoder#transformers.EncoderDecoderConfig"
>EncoderDecoderConfig</a></p>
`}}),Jt=new A({props:{name:"to_dict",anchor:"transformers.RagConfig.to_dict",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/configuration_rag.py#L183",returnDescription:`
<p>Dictionary of all the attributes that make up this configuration instance,</p>
`,returnType:`
<p><code>Dict[str, any]</code></p>
`}}),Zt=new _e({}),to=new A({props:{name:"class transformers.RagTokenizer",anchor:"transformers.RagTokenizer",parameters:[{name:"question_encoder",val:""},{name:"generator",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/tokenization_rag.py#L28"}}),oo=new _e({}),no=new A({props:{name:"class transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput",anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput",parameters:[{name:"loss",val:": typing.Optional[torch.FloatTensor] = None"},{name:"logits",val:": FloatTensor = None"},{name:"doc_scores",val:": FloatTensor = None"},{name:"past_key_values",val:": typing.Optional[typing.List[torch.FloatTensor]] = None"},{name:"retrieved_doc_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"retrieved_doc_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"question_encoder_last_hidden_state",val:": typing.Optional[torch.FloatTensor] = None"},{name:"question_enc_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"question_enc_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_enc_last_hidden_state",val:": typing.Optional[torch.FloatTensor] = None"},{name:"generator_enc_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_enc_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_dec_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_dec_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_cross_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}],parametersDescription:[{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.loss",description:`<strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) &#x2014;
Language modeling loss.`,name:"loss"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.logits",description:`<strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) &#x2014;
Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.`,name:"logits"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.`,name:"doc_scores"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.past_key_values",description:`<strong>past_key_values</strong> (<code>List[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) &#x2014;
List of <code>torch.FloatTensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.`,name:"past_key_values"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.retrieved_doc_embeds",description:`<strong>retrieved_doc_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.`,name:"retrieved_doc_embeds"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.retrieved_doc_ids",description:`<strong>retrieved_doc_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
The indexes of the embedded documents retrieved by the retriever.`,name:"retrieved_doc_ids"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.`,name:"context_input_ids"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.`,name:"context_attention_mask"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.question_encoder_last_hidden_state",description:`<strong>question_encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.`,name:"question_encoder_last_hidden_state"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.question_enc_hidden_states",description:`<strong>question_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.`,name:"question_enc_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.question_enc_attentions",description:`<strong>question_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"question_enc_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_enc_last_hidden_state",description:`<strong>generator_enc_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden-states at the output of the last layer of the generator encoder of the model.`,name:"generator_enc_last_hidden_state"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_enc_hidden_states",description:`<strong>generator_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.`,name:"generator_enc_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_enc_attentions",description:`<strong>generator_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"generator_enc_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_dec_hidden_states",description:`<strong>generator_dec_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.`,name:"generator_dec_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_dec_attentions",description:`<strong>generator_dec_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"generator_dec_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput.generator_cross_attentions",description:`<strong>generator_cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
weighted average in the cross-attention heads.`,name:"generator_cross_attentions"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L39"}}),so=new A({props:{name:"class transformers.models.rag.modeling_rag.RetrievAugLMOutput",anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput",parameters:[{name:"logits",val:": FloatTensor = None"},{name:"doc_scores",val:": FloatTensor = None"},{name:"past_key_values",val:": typing.Optional[typing.List[torch.FloatTensor]] = None"},{name:"retrieved_doc_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"retrieved_doc_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"question_encoder_last_hidden_state",val:": typing.Optional[torch.FloatTensor] = None"},{name:"question_enc_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"question_enc_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_enc_last_hidden_state",val:": typing.Optional[torch.FloatTensor] = None"},{name:"generator_enc_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_enc_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_dec_hidden_states",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_dec_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"generator_cross_attentions",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"}],parametersDescription:[{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.logits",description:`<strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) &#x2014;
Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.`,name:"logits"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.`,name:"doc_scores"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.past_key_values",description:`<strong>past_key_values</strong> (<code>List[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) &#x2014;
List of <code>torch.FloatTensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.`,name:"past_key_values"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.retrieved_doc_embeds",description:`<strong>retrieved_doc_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.`,name:"retrieved_doc_embeds"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.retrieved_doc_ids",description:`<strong>retrieved_doc_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
The indexes of the embedded documents retrieved by the retriever.`,name:"retrieved_doc_ids"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.`,name:"context_input_ids"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.`,name:"context_attention_mask"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.question_encoder_last_hidden_state",description:`<strong>question_encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.`,name:"question_encoder_last_hidden_state"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.question_enc_hidden_states",description:`<strong>question_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.`,name:"question_enc_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.question_enc_attentions",description:`<strong>question_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"question_enc_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_enc_last_hidden_state",description:`<strong>generator_enc_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Sequence of hidden-states at the output of the last layer of the generator encoder of the model.`,name:"generator_enc_last_hidden_state"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_enc_hidden_states",description:`<strong>generator_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.`,name:"generator_enc_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_enc_attentions",description:`<strong>generator_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"generator_enc_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_dec_hidden_states",description:`<strong>generator_dec_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.`,name:"generator_dec_hidden_states"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_dec_attentions",description:`<strong>generator_dec_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.`,name:"generator_dec_attentions"},{anchor:"transformers.models.rag.modeling_rag.RetrievAugLMOutput.generator_cross_attentions",description:`<strong>generator_cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) &#x2014;
Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
weighted average in the cross-attention heads.`,name:"generator_cross_attentions"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L134"}}),ao=new _e({}),io=new A({props:{name:"class transformers.RagRetriever",anchor:"transformers.RagRetriever",parameters:[{name:"config",val:""},{name:"question_encoder_tokenizer",val:""},{name:"generator_tokenizer",val:""},{name:"index",val:" = None"},{name:"init_retrieval",val:" = True"}],parametersDescription:[{anchor:"transformers.RagRetriever.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
The configuration of the RAG model this Retriever is used with. Contains parameters indicating which
<code>Index</code> to build. You can load your own custom dataset with <code>config.index_name=&quot;custom&quot;</code> or use a canonical
one (default) from the datasets library with <code>config.index_name=&quot;wiki_dpr&quot;</code> for example.`,name:"config"},{anchor:"transformers.RagRetriever.question_encoder_tokenizer",description:`<strong>question_encoder_tokenizer</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>) &#x2014;
The tokenizer that was used to tokenize the question. It is used to decode the question and then use the
generator_tokenizer.`,name:"question_encoder_tokenizer"},{anchor:"transformers.RagRetriever.generator_tokenizer",description:`<strong>generator_tokenizer</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>) &#x2014;
The tokenizer used for the generator part of the RagModel.`,name:"generator_tokenizer"},{anchor:"transformers.RagRetriever.index",description:`<strong>index</strong> (<code>Index</code>, optional, defaults to the one defined by the configuration) &#x2014;
If specified, use this index instead of the one built using the configuration`,name:"index"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/retrieval_rag.py#L323"}}),rt=new sn({props:{anchor:"transformers.RagRetriever.example",$$slots:{default:[Wb]},$$scope:{ctx:F}}}),co=new A({props:{name:"init_retrieval",anchor:"transformers.RagRetriever.init_retrieval",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/retrieval_rag.py#L457"}}),lo=new A({props:{name:"postprocess_docs",anchor:"transformers.RagRetriever.postprocess_docs",parameters:[{name:"docs",val:""},{name:"input_strings",val:""},{name:"prefix",val:""},{name:"n_docs",val:""},{name:"return_tensors",val:" = None"}],parametersDescription:[{anchor:"transformers.RagRetriever.postprocess_docs.docs",description:`<strong>docs</strong>  (<code>dict</code>) &#x2014;
Retrieved documents.`,name:"docs"},{anchor:"transformers.RagRetriever.postprocess_docs.input_strings",description:`<strong>input_strings</strong> (<code>str</code>) &#x2014;
Input strings decoded by <code>preprocess_query</code>.`,name:"input_strings"},{anchor:"transformers.RagRetriever.postprocess_docs.prefix",description:`<strong>prefix</strong> (<code>str</code>) &#x2014;
Prefix added at the beginning of each input, typically used with T5-based models.`,name:"prefix"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/retrieval_rag.py#L465",returnDescription:`
<p>a tuple consisting of two elements: contextualized <code>input_ids</code> and a compatible
<code>attention_mask</code>.</p>
`,returnType:`
<p><code>tuple(tensors)</code></p>
`}}),po=new A({props:{name:"retrieve",anchor:"transformers.RagRetriever.retrieve",parameters:[{name:"question_hidden_states",val:": ndarray"},{name:"n_docs",val:": int"}],parametersDescription:[{anchor:"transformers.RagRetriever.retrieve.question_hidden_states",description:`<strong>question_hidden_states</strong> (<code>np.ndarray</code> of shape <code>(batch_size, vector_size)</code>) &#x2014;
A batch of query vectors to retrieve with.`,name:"question_hidden_states"},{anchor:"transformers.RagRetriever.retrieve.n_docs",description:`<strong>n_docs</strong> (<code>int</code>) &#x2014;
The number of docs retrieved per query.`,name:"n_docs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/retrieval_rag.py#L537",returnDescription:`
<p>A tuple with the following objects:</p>
<ul>
<li><strong>retrieved_doc_embeds</strong> (<code>np.ndarray</code> of shape <code>(batch_size, n_docs, dim)</code>) \u2014 The retrieval embeddings
of the retrieved docs per query.</li>
<li><strong>doc_ids</strong> (<code>np.ndarray</code> of shape <code>(batch_size, n_docs)</code>) \u2014 The ids of the documents in the index</li>
<li><strong>doc_dicts</strong> (<code>List[dict]</code>): The <code>retrieved_doc_embeds</code> examples per query.</li>
</ul>
`,returnType:`
<p><code>Tuple[np.ndarray, np.ndarray, List[dict]]</code></p>
`}}),uo=new _e({}),mo=new A({props:{name:"class transformers.RagModel",anchor:"transformers.RagModel",parameters:[{name:"config",val:": typing.Optional[transformers.configuration_utils.PretrainedConfig] = None"},{name:"question_encoder",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"generator",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"retriever",val:": typing.Optional[transformers.models.rag.retrieval_rag.RagRetriever] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.RagModel.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.RagModel.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.RagModel.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L494"}}),ct=new ge({props:{$$slots:{default:[Bb]},$$scope:{ctx:F}}}),vo=new A({props:{name:"forward",anchor:"transformers.RagModel.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"decoder_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"decoder_attention_mask",val:": typing.Optional[torch.BoolTensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"doc_scores",val:": typing.Optional[torch.FloatTensor] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:" = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"n_docs",val:": typing.Optional[int] = None"}],parametersDescription:[{anchor:"transformers.RagModel.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.RagModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.RagModel.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagModel">RagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.RagModel.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.RagModel.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.RagModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.RagModel.forward.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.RagModel.forward.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>,
returned when <em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the
question encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.RagModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.RagModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.RagModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.RagModel.forward.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.RagModel.forward.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L537",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>torch.FloatTensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),lt=new ge({props:{$$slots:{default:[Qb]},$$scope:{ctx:F}}}),pt=new sn({props:{anchor:"transformers.RagModel.forward.example",$$slots:{default:[Kb]},$$scope:{ctx:F}}}),bo=new _e({}),To=new A({props:{name:"class transformers.RagSequenceForGeneration",anchor:"transformers.RagSequenceForGeneration",parameters:[{name:"config",val:": typing.Optional[transformers.configuration_utils.PretrainedConfig] = None"},{name:"question_encoder",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"generator",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"retriever",val:": typing.Optional[transformers.models.rag.retrieval_rag.RagRetriever] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagSequenceForGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.RagSequenceForGeneration.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.RagSequenceForGeneration.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.RagSequenceForGeneration.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L740"}}),ut=new ge({props:{$$slots:{default:[Vb]},$$scope:{ctx:F}}}),qo=new A({props:{name:"forward",anchor:"transformers.RagSequenceForGeneration.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"decoder_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"decoder_attention_mask",val:": typing.Optional[torch.BoolTensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"doc_scores",val:": typing.Optional[torch.FloatTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"exclude_bos_score",val:": typing.Optional[bool] = None"},{name:"reduce_loss",val:": typing.Optional[bool] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagSequenceForGeneration.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.RagSequenceForGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.RagSequenceForGeneration.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagModel">RagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.RagSequenceForGeneration.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.RagSequenceForGeneration.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.RagSequenceForGeneration.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.RagSequenceForGeneration.forward.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.RagSequenceForGeneration.forward.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>,
returned when <em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the
question encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.RagSequenceForGeneration.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.RagSequenceForGeneration.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.RagSequenceForGeneration.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.RagSequenceForGeneration.forward.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.RagSequenceForGeneration.forward.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"},{anchor:"transformers.RagSequenceForGeneration.forward.exclude_bos_score",description:`<strong>exclude_bos_score</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the score of the BOS token is disregarded when computing
the loss.`,name:"exclude_bos_score"},{anchor:"transformers.RagSequenceForGeneration.forward.reduce_loss",description:`<strong>reduce_loss</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the NLL loss is reduced using the <code>torch.Tensor.sum</code>
operation.`,name:"reduce_loss"},{anchor:"transformers.RagSequenceForGeneration.forward.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, any]</code>, optional, defaults to <em>{}</em>) &#x2014;
Legacy dictionary, which is required so that model can use <em>generate()</em> function.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L769",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>torch.FloatTensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),mt=new ge({props:{$$slots:{default:[Yb]},$$scope:{ctx:F}}}),gt=new sn({props:{anchor:"transformers.RagSequenceForGeneration.forward.example",$$slots:{default:[Jb]},$$scope:{ctx:F}}}),xo=new A({props:{name:"generate",anchor:"transformers.RagSequenceForGeneration.generate",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"doc_scores",val:": typing.Optional[torch.FloatTensor] = None"},{name:"do_deduplication",val:": typing.Optional[bool] = None"},{name:"num_return_sequences",val:": typing.Optional[int] = None"},{name:"num_beams",val:": typing.Optional[int] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"**model_kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagSequenceForGeneration.generate.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
The sequence used as a prompt for the generation. If <code>input_ids</code> is not passed, then
<code>context_input_ids</code> has to be provided.`,name:"input_ids"},{anchor:"transformers.RagSequenceForGeneration.generate.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.RagSequenceForGeneration.generate.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder input_ids by the
retriever.`,name:"context_input_ids"},{anchor:"transformers.RagSequenceForGeneration.generate.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model is not initialized with a <code>retriever</code> or <code>input_ids</code> is not given, <code>context_input_ids</code> and
<code>context_attention_mask</code> have to be provided to the forward pass. They are returned by
<code>__call__()</code>.`,name:"context_attention_mask"},{anchor:"transformers.RagSequenceForGeneration.generate.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
<p>If the model is not initialized with a <code>retriever</code> or <code>input_ids</code> is not given, <code>doc_scores</code> has to be
provided to the forward pass. <code>doc_scores</code> are returned by <code>__call__()</code>.`,name:"doc_scores"},{anchor:"transformers.RagSequenceForGeneration.generate.do_deduplication",description:`<strong>do_deduplication</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to deduplicate the generations from different context documents for a given input. Has
to be set to <code>False</code> if used while training with distributed backend.`,name:"do_deduplication"},{anchor:"transformers.RagSequenceForGeneration.generate.num_return_sequences(int,",description:`<strong>num_return_sequences(<code>int</code>,</strong> <em>optional</em>, defaults to 1) &#x2014;
The number of independently computed returned sequences for each element in the batch. Note that this
is not the value we pass to the <code>generator</code>&#x2019;s <code>[generate()](/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate)</code> function,
where we set <code>num_return_sequences</code> to <code>num_beams</code>.`,name:"num_return_sequences(int,"},{anchor:"transformers.RagSequenceForGeneration.generate.num_beams",description:`<strong>num_beams</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Number of beams for beam search. 1 means no beam search.`,name:"num_beams"},{anchor:"transformers.RagSequenceForGeneration.generate.n_docs",description:`<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to <code>config.n_docs</code>) &#x2014;
Number of documents to retrieve and/or number of documents for which to generate an answer.
kwargs &#x2014;
Additional kwargs will be passed to <a href="/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate">generate()</a>.`,name:"n_docs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L910",returnDescription:`
<p>The generated
sequences. The second dimension (sequence length) is either equal to <code>max_length</code> or shorter if all batches
finished early due to the <code>eos_token_id</code>.</p>
`,returnType:`
<p><code>torch.LongTensor</code> of shape <code>(batch_size * num_return_sequences, sequence_length)</code></p>
`}}),Fo=new _e({}),$o=new A({props:{name:"class transformers.RagTokenForGeneration",anchor:"transformers.RagTokenForGeneration",parameters:[{name:"config",val:": typing.Optional[transformers.configuration_utils.PretrainedConfig] = None"},{name:"question_encoder",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"generator",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"retriever",val:": typing.Optional[transformers.models.rag.retrieval_rag.RagRetriever] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagTokenForGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.RagTokenForGeneration.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.RagTokenForGeneration.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.RagTokenForGeneration.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L1138"}}),vt=new ge({props:{$$slots:{default:[Xb]},$$scope:{ctx:F}}}),Ao=new A({props:{name:"forward",anchor:"transformers.RagTokenForGeneration.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"decoder_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"decoder_attention_mask",val:": typing.Optional[torch.BoolTensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"doc_scores",val:": typing.Optional[torch.FloatTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"do_marginalize",val:": typing.Optional[bool] = None"},{name:"reduce_loss",val:": typing.Optional[bool] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagTokenForGeneration.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.RagTokenForGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.RagTokenForGeneration.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagModel">RagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.RagTokenForGeneration.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.RagTokenForGeneration.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.RagTokenForGeneration.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.RagTokenForGeneration.forward.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.RagTokenForGeneration.forward.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>,
returned when <em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the
question encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.RagTokenForGeneration.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.RagTokenForGeneration.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.RagTokenForGeneration.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.RagTokenForGeneration.forward.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.RagTokenForGeneration.forward.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"},{anchor:"transformers.RagTokenForGeneration.forward.do_marginalize",description:`<strong>do_marginalize</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If <code>True</code>, the logits are marginalized over all documents by making use of
<code>torch.nn.functional.log_softmax</code>.`,name:"do_marginalize"},{anchor:"transformers.RagTokenForGeneration.forward.reduce_loss",description:`<strong>reduce_loss</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the NLL loss is reduced using the <code>torch.Tensor.sum</code>
operation.`,name:"reduce_loss"},{anchor:"transformers.RagTokenForGeneration.forward.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, any]</code>, optional, defaults to <em>{}</em>) &#x2014;
Legacy dictionary, which is required so that model can use <em>generate()</em> function.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L1236",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>torch.FloatTensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings and one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"
>transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),bt=new ge({props:{$$slots:{default:[Zb]},$$scope:{ctx:F}}}),Tt=new sn({props:{anchor:"transformers.RagTokenForGeneration.forward.example",$$slots:{default:[eT]},$$scope:{ctx:F}}}),Mo=new A({props:{name:"generate",anchor:"transformers.RagTokenForGeneration.generate",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"context_attention_mask",val:": typing.Optional[torch.LongTensor] = None"},{name:"doc_scores",val:": typing.Optional[torch.FloatTensor] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"generation_config",val:": typing.Optional[transformers.generation.configuration_utils.GenerationConfig] = None"},{name:"prefix_allowed_tokens_fn",val:": typing.Callable[[int, torch.Tensor], typing.List[int]] = None"},{name:"logits_processor",val:": typing.Optional[transformers.generation.logits_process.LogitsProcessorList] = []"},{name:"stopping_criteria",val:": typing.Optional[transformers.generation.stopping_criteria.StoppingCriteriaList] = []"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.RagTokenForGeneration.generate.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
The sequence used as a prompt for the generation. If <code>input_ids</code> is not passed, then
<code>context_input_ids</code> has to be provided.`,name:"input_ids"},{anchor:"transformers.RagTokenForGeneration.generate.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.RagTokenForGeneration.generate.context_input_ids",description:`<strong>context_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.RagTokenForGeneration.generate.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"context_attention_mask"},{anchor:"transformers.RagTokenForGeneration.generate.doc_scores",description:`<strong>doc_scores</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"doc_scores"},{anchor:"transformers.RagTokenForGeneration.generate.n_docs",description:`<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to <code>config.n_docs</code>) &#x2014;
Number of documents to retrieve and/or number of documents for which to generate an answer.`,name:"n_docs"},{anchor:"transformers.RagTokenForGeneration.generate.generation_config",description:`<strong>generation_config</strong> (<code>~generation.GenerationConfig</code>, <em>optional</em>) &#x2014;
The generation configuration to be used as base parametrization for the generation call. <code>**kwargs</code>
passed to generate matching the attributes of <code>generation_config</code> will override them. If
<code>generation_config</code> is not provided, the default will be used, which has the following loading
priority: 1) from the <code>generation_config.json</code> model file, if it exists; 2) from the model
configuration. Please note that unspecified parameters will inherit <a href="/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationConfig">GenerationConfig</a>&#x2019;s
default values, whose documentation should be checked to parameterize generation.
prefix_allowed_tokens_fn &#x2014; (<code>Callable[[int, torch.Tensor], List[int]]</code>, <em>optional</em>):
If provided, this function constraints the beam search to allowed tokens only at each step. If not
provided no constraint is applied. This function takes 2 arguments <code>inputs_ids</code> and the batch ID
<code>batch_id</code>. It has to return a list with the allowed tokens for the next generation step conditioned on
the previously generated tokens <code>inputs_ids</code> and the batch ID <code>batch_id</code>. This argument is useful for
constrained generation conditioned on the prefix, as described in <a href="https://arxiv.org/abs/2010.00904" rel="nofollow">Autoregressive Entity
Retrieval</a>.`,name:"generation_config"},{anchor:"transformers.RagTokenForGeneration.generate.logits_processor",description:`<strong>logits_processor</strong> (<code>LogitsProcessorList</code>, <em>optional</em>) &#x2014;
Custom logits processors that complement the default logits processors built from arguments and a
model&#x2019;s config. If a logit processor is passed that is already created with the arguments or a model&#x2019;s
config an error is thrown.`,name:"logits_processor"},{anchor:"transformers.RagTokenForGeneration.generate.stopping_criteria",description:`<strong>stopping_criteria</strong> (<code>StoppingCriteriaList</code>, <em>optional</em>) &#x2014;
Custom stopping criteria that complement the default stopping criteria built from arguments and a
model&#x2019;s config. If a stopping criteria is passed that is already created with the arguments or a
model&#x2019;s config an error is thrown.
kwargs &#x2014;
Ad hoc parametrization of <code>generate_config</code> and/or additional model-specific kwargs that will be
forwarded to the <code>forward</code> function of the model.`,name:"stopping_criteria"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_rag.py#L1377",returnDescription:`
<p>The generated
sequences. The second dimension (sequence_length) is either equal to <code>max_length</code> or shorter if all batches
finished early due to the <code>eos_token_id</code>.</p>
`,returnType:`
<p><code>torch.LongTensor</code> of shape <code>(batch_size * num_return_sequences, sequence_length)</code></p>
`}}),Go=new _e({}),Po=new A({props:{name:"class transformers.TFRagModel",anchor:"transformers.TFRagModel",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.TFRagModel.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.TFRagModel.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.TFRagModel.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L493"}}),kt=new ge({props:{$$slots:{default:[tT]},$$scope:{ctx:F}}}),Lo=new A({props:{name:"call",anchor:"transformers.TFRagModel.call",parameters:[{name:"input_ids",val:": typing.Union[typing.List[tensorflow.python.framework.ops.Tensor], typing.List[numpy.ndarray], typing.List[keras.engine.keras_tensor.KerasTensor], typing.Dict[str, tensorflow.python.framework.ops.Tensor], typing.Dict[str, numpy.ndarray], typing.Dict[str, keras.engine.keras_tensor.KerasTensor], tensorflow.python.framework.ops.Tensor, numpy.ndarray, keras.engine.keras_tensor.KerasTensor, NoneType] = None"},{name:"attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"encoder_outputs",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"past_key_values",val:": typing.Union[typing.Tuple[typing.Tuple[typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor]]], NoneType] = None"},{name:"doc_scores",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"training",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagModel.call.input_ids",description:`<strong>input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.`,name:"input_ids"},{anchor:"transformers.TFRagModel.call.attention_mask",description:`<strong>attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TFRagModel.call.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(tf.Tensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagModel">TFRagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.TFRagModel.call.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.TFRagModel.call.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.TFRagModel.call.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(tf.Tensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.TFRagModel.call.doc_scores",description:`<strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.TFRagModel.call.context_input_ids",description:`<strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when
<em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the question
encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.TFRagModel.call.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.TFRagModel.call.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TFRagModel.call.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.TFRagModel.call.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.TFRagModel.call.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <code>TFRetrievAugLMOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.TFRagModel.call.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L543",returnDescription:`
<p>A <code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMOutput</code> or a tuple of <code>tf.Tensor</code> (if
<code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various elements depending on the
configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>logits</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[tf.Tensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>tf.Tensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMOutput</code> or <code>tuple(tf.Tensor)</code></p>
`}}),qt=new ge({props:{$$slots:{default:[oT]},$$scope:{ctx:F}}}),xt=new sn({props:{anchor:"transformers.TFRagModel.call.example",$$slots:{default:[nT]},$$scope:{ctx:F}}}),So=new _e({}),Do=new A({props:{name:"class transformers.TFRagSequenceForGeneration",anchor:"transformers.TFRagSequenceForGeneration",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagSequenceForGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.TFRagSequenceForGeneration.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.TFRagSequenceForGeneration.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.TFRagSequenceForGeneration.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L1298"}}),Ft=new ge({props:{$$slots:{default:[rT]},$$scope:{ctx:F}}}),Wo=new A({props:{name:"call",anchor:"transformers.TFRagSequenceForGeneration.call",parameters:[{name:"input_ids",val:": typing.Union[typing.List[tensorflow.python.framework.ops.Tensor], typing.List[numpy.ndarray], typing.List[keras.engine.keras_tensor.KerasTensor], typing.Dict[str, tensorflow.python.framework.ops.Tensor], typing.Dict[str, numpy.ndarray], typing.Dict[str, keras.engine.keras_tensor.KerasTensor], tensorflow.python.framework.ops.Tensor, numpy.ndarray, keras.engine.keras_tensor.KerasTensor, NoneType] = None"},{name:"attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"encoder_outputs",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"past_key_values",val:": typing.Union[typing.Tuple[typing.Tuple[typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor]]], NoneType] = None"},{name:"doc_scores",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"exclude_bos_score",val:": typing.Optional[bool] = None"},{name:"labels",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"reduce_loss",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"training",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagSequenceForGeneration.call.input_ids",description:`<strong>input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.`,name:"input_ids"},{anchor:"transformers.TFRagSequenceForGeneration.call.attention_mask",description:`<strong>attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TFRagSequenceForGeneration.call.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(tf.Tensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagModel">TFRagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.TFRagSequenceForGeneration.call.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.TFRagSequenceForGeneration.call.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.TFRagSequenceForGeneration.call.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(tf.Tensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.TFRagSequenceForGeneration.call.doc_scores",description:`<strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.TFRagSequenceForGeneration.call.context_input_ids",description:`<strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when
<em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the question
encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.TFRagSequenceForGeneration.call.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.TFRagSequenceForGeneration.call.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TFRagSequenceForGeneration.call.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.TFRagSequenceForGeneration.call.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.TFRagSequenceForGeneration.call.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <code>TFRetrievAugLMOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.TFRagSequenceForGeneration.call.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"},{anchor:"transformers.TFRagSequenceForGeneration.call.exclude_bos_score",description:`<strong>exclude_bos_score</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the score of the BOS token is disregarded when computing
the loss.`,name:"exclude_bos_score"},{anchor:"transformers.TFRagSequenceForGeneration.call.labels",description:`<strong>labels</strong> (<code>tf.Tensor</code> or <code>np.ndarray</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the cross entropy classification loss according to Rag-Sequence model formulation See
<a href="https://arxiv.org/pdf/2005.11401.pdf" rel="nofollow">https://arxiv.org/pdf/2005.11401.pdf</a> Section 2.1 for details about Rag-Sequence formulation. Indices should
be in <code>[0, ..., config.vocab_size - 1]</code>.`,name:"labels"},{anchor:"transformers.TFRagSequenceForGeneration.call.reduce_loss",description:`<strong>reduce_loss</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the NLL loss is reduced using the <code>tf.Tensor.sum</code>
operation.`,name:"reduce_loss"},{anchor:"transformers.TFRagSequenceForGeneration.call.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, any]</code>, optional, defaults to <em>{}</em>) &#x2014;
Legacy dictionary, which is required so that model can use <em>generate()</em> function.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L1345",returnDescription:`
<p>A <code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMMarginOutput</code> or a tuple of <code>tf.Tensor</code> (if
<code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various elements depending on the
configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>tf.Tensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[tf.Tensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>tf.Tensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>tf.Tensor</code> (int32) of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>tf.Tensor</code>(int32) of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>tf.Tensor</code> (int32) of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMMarginOutput</code> or <code>tuple(tf.Tensor)</code></p>
`}}),$t=new ge({props:{$$slots:{default:[sT]},$$scope:{ctx:F}}}),zt=new sn({props:{anchor:"transformers.TFRagSequenceForGeneration.call.example",$$slots:{default:[aT]},$$scope:{ctx:F}}}),Bo=new A({props:{name:"generate",anchor:"transformers.TFRagSequenceForGeneration.generate",parameters:[{name:"input_ids",val:": typing.Union[typing.List[tensorflow.python.framework.ops.Tensor], typing.List[numpy.ndarray], typing.List[keras.engine.keras_tensor.KerasTensor], typing.Dict[str, tensorflow.python.framework.ops.Tensor], typing.Dict[str, numpy.ndarray], typing.Dict[str, keras.engine.keras_tensor.KerasTensor], tensorflow.python.framework.ops.Tensor, numpy.ndarray, keras.engine.keras_tensor.KerasTensor, NoneType] = None"},{name:"attention_mask",val:": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"},{name:"context_input_ids",val:" = None"},{name:"context_attention_mask",val:" = None"},{name:"doc_scores",val:" = None"},{name:"do_deduplication",val:" = None"},{name:"num_return_sequences",val:" = None"},{name:"num_beams",val:" = None"},{name:"n_docs",val:" = None"},{name:"**model_kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagSequenceForGeneration.generate.input_ids",description:`<strong>input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
The sequence used as a prompt for the generation. If <code>input_ids</code> is not passed, then
<code>context_input_ids</code> has to be provided.`,name:"input_ids"},{anchor:"transformers.TFRagSequenceForGeneration.generate.attention_mask",description:`<strong>attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>: - 1 for
tokens that are <strong>not masked</strong>, - 0 for tokens that are <strong>masked</strong>. <a href="../glossary#attention-mask">What are attention
masks?</a>`,name:"attention_mask"},{anchor:"transformers.TFRagSequenceForGeneration.generate.context_input_ids",description:`<strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder input_ids by the
retriever.`,name:"context_input_ids"},{anchor:"transformers.TFRagSequenceForGeneration.generate.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever. If the model has is not initialized with a <code>retriever</code> or <code>input_ids</code> is not given,
<code>context_input_ids</code> and <code>context_attention_mask</code> have to be provided to the forward pass. They are
returned by <code>__call__()</code>.`,name:"context_attention_mask"},{anchor:"transformers.TFRagSequenceForGeneration.generate.doc_scores",description:`<strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> or
<code>input_ids</code> is not given, <code>doc_scores</code> has to be provided to the forward pass. <code>doc_scores</code> are
returned by <code>__call__()</code>.`,name:"doc_scores"},{anchor:"transformers.TFRagSequenceForGeneration.generate.do_deduplication",description:`<strong>do_deduplication</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to deduplicate the generations from different context documents for a given input. Has
to be set to <code>False</code> if used while training with distributed backend.`,name:"do_deduplication"},{anchor:"transformers.TFRagSequenceForGeneration.generate.num_return_sequences(int,",description:`<strong>num_return_sequences(<code>int</code>,</strong> <em>optional</em>, defaults to 1) &#x2014;
The number of independently computed returned sequences for each element in the batch. Note that this
is not the value we pass to the <code>generator</code>&#x2019;s <code>[generate()](/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate)</code> function,
where we set <code>num_return_sequences</code> to <code>num_beams</code>.`,name:"num_return_sequences(int,"},{anchor:"transformers.TFRagSequenceForGeneration.generate.num_beams",description:`<strong>num_beams</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Number of beams for beam search. 1 means no beam search.`,name:"num_beams"},{anchor:"transformers.TFRagSequenceForGeneration.generate.n_docs",description:`<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to <code>config.n_docs</code>) &#x2014;
Number of documents to retrieve and/or number of documents for which to generate an answer.
kwargs &#x2014;
Additional kwargs will be passed to <a href="/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate">generate()</a>`,name:"n_docs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L1580",returnDescription:`
<p>The generated sequences. The
second dimension (sequence length) is either equal to <code>max_length</code> or shorter if all batches finished early
due to the <code>eos_token_id</code>.</p>
`,returnType:`
<p><code>tf.Tensor</code> of shape <code>(batch_size * num_return_sequences, sequence_length)</code></p>
`}}),Ko=new _e({}),Vo=new A({props:{name:"class transformers.TFRagTokenForGeneration",anchor:"transformers.TFRagTokenForGeneration",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagTokenForGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.TFRagTokenForGeneration.question_encoder",description:`<strong>question_encoder</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
An encoder model compatible with the faiss index encapsulated by the <code>retriever</code>.`,name:"question_encoder"},{anchor:"transformers.TFRagTokenForGeneration.generator",description:`<strong>generator</strong> (<a href="/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel">TFPreTrainedModel</a>) &#x2014;
A seq2seq model used as the generator in the RAG architecture.`,name:"generator"},{anchor:"transformers.TFRagTokenForGeneration.retriever",description:`<strong>retriever</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever">RagRetriever</a>) &#x2014;
A retriever class encapsulating a faiss index queried to obtain context documents for current inputs.`,name:"retriever"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L726"}}),At=new ge({props:{$$slots:{default:[dT]},$$scope:{ctx:F}}}),Zo=new A({props:{name:"call",anchor:"transformers.TFRagTokenForGeneration.call",parameters:[{name:"input_ids",val:": typing.Union[typing.List[tensorflow.python.framework.ops.Tensor], typing.List[numpy.ndarray], typing.List[keras.engine.keras_tensor.KerasTensor], typing.Dict[str, tensorflow.python.framework.ops.Tensor], typing.Dict[str, numpy.ndarray], typing.Dict[str, keras.engine.keras_tensor.KerasTensor], tensorflow.python.framework.ops.Tensor, numpy.ndarray, keras.engine.keras_tensor.KerasTensor, NoneType] = None"},{name:"attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"encoder_outputs",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"past_key_values",val:": typing.Union[typing.Tuple[typing.Tuple[typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor]]], NoneType] = None"},{name:"doc_scores",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"context_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_retrieved",val:": typing.Optional[bool] = None"},{name:"n_docs",val:": typing.Optional[int] = None"},{name:"do_marginalize",val:": typing.Optional[bool] = None"},{name:"labels",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"reduce_loss",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"training",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagTokenForGeneration.call.input_ids",description:`<strong>input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. <a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig">RagConfig</a>, used to initialize the model, specifies
which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
obtain the indices.`,name:"input_ids"},{anchor:"transformers.TFRagTokenForGeneration.call.attention_mask",description:`<strong>attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TFRagTokenForGeneration.call.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(tf.Tensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>generator_enc_last_hidden_state</code>, <em>optional</em>: <code>generator_enc_hidden_states</code>,
<em>optional</em>: <code>generator_enc_attentions</code>). <code>generator_enc_last_hidden_state</code> of shape <code>(batch_size, n_docs * sequence_length, hidden_size)</code> is a sequence of hidden-states at the output of the last layer of the
generator&#x2019;s encoder.</p>
<p>Used by the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagModel">TFRagModel</a>) model during decoding.`,name:"encoder_outputs"},{anchor:"transformers.TFRagTokenForGeneration.call.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Provide for generation tasks. <code>None</code> by default, construct as per instructions for the generator model
you&#x2019;re using with your RAG instance.`,name:"decoder_input_ids"},{anchor:"transformers.TFRagTokenForGeneration.call.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.TFRagTokenForGeneration.call.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(tf.Tensor))</code>) &#x2014;
Tuple consists of two elements: <code>encoder_outputs</code> of the RAG model (see <code>encoder_outputs</code>) and
<code>past_key_values</code> of the underlying generator. Can be used to speed up decoding. <code>past_key_values</code> are used
in the (<a href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration">RagTokenForGeneration</a>) model during decoding.`,name:"past_key_values"},{anchor:"transformers.TFRagTokenForGeneration.call.doc_scores",description:`<strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>. If the model has is not initialized with a <code>retriever</code> <code>doc_scores</code>
has to be provided to the forward pass. <code>doc_scores</code> can be computed via
<code>question_encoder_last_hidden_state</code> and <code>retrieved_doc_embeds</code>, see examples for more information.`,name:"doc_scores"},{anchor:"transformers.TFRagTokenForGeneration.call.context_input_ids",description:`<strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> \`<code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>. context_attention_mask
(<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when
<em>output_retrieved=True</em>): Attention mask post-processed from the retrieved documents and the question
encoder <code>input_ids</code> by the retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code> <code>context_attention_mask</code> has to be provided to the
forward pass. <code>context_attention_mask</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.TFRagTokenForGeneration.call.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.TFRagTokenForGeneration.call.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TFRagTokenForGeneration.call.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.TFRagTokenForGeneration.call.output_retrieved(bool,",description:`<strong>output_retrieved(<code>bool</code>,</strong> <em>optional</em>) &#x2014;
Whether or not to return the <code>retrieved_doc_embeds</code>, <code>retrieved_doc_ids</code>, <code>context_input_ids</code> and
<code>context_attention_mask</code>. See returned tensors for more detail.`,name:"output_retrieved(bool,"},{anchor:"transformers.TFRagTokenForGeneration.call.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <code>TFRetrievAugLMOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.TFRagTokenForGeneration.call.n_docs",description:"<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to `config.n_docs&#x201C;) &#x2014;\nNumber of documents to retrieve and/or number of documents for which to generate an answer.",name:"n_docs"},{anchor:"transformers.TFRagTokenForGeneration.call.do_marginalize",description:`<strong>do_marginalize</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If <code>True</code>, the logits are marginalized over all documents by making use of
<code>torch.nn.functional.log_softmax</code>.`,name:"do_marginalize"},{anchor:"transformers.TFRagTokenForGeneration.call.labels",description:`<strong>labels</strong> (<code>tf.Tensor</code> or <code>np.ndarray</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the cross entropy classification loss according to Rag-Token model formulation See
<a href="https://arxiv.org/pdf/2005.11401.pdf" rel="nofollow">https://arxiv.org/pdf/2005.11401.pdf</a> Section 2.1 for details about Rag-Token formulation. Indices should be
in <code>[0, ..., config.vocab_size - 1]</code>.`,name:"labels"},{anchor:"transformers.TFRagTokenForGeneration.call.reduce_loss",description:`<strong>reduce_loss</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Only relevant if <code>labels</code> is passed. If <code>True</code>, the NLL loss is reduced using the <code>tf.Tensor.sum</code>
operation.`,name:"reduce_loss"},{anchor:"transformers.TFRagTokenForGeneration.call.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, any]</code>, optional, defaults to <em>{}</em>) &#x2014;
Legacy dictionary, which is required so that model can use <em>generate()</em> function.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L839",returnDescription:`
<p>A <code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMMarginOutput</code> or a tuple of <code>tf.Tensor</code> (if
<code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various elements depending on the
configuration (<a
  href="/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"
>RagConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>tf.Tensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[tf.Tensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>tf.Tensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
(see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) \u2014 Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_embeds</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs, hidden_size)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Embedded documents retrieved by the retriever. Is used with <code>question_encoder_last_hidden_state</code> to compute
the <code>doc_scores</code>.</p>
</li>
<li>
<p><strong>retrieved_doc_ids</strong> (<code>tf.Tensor</code> (int32) of shape <code>(batch_size, config.n_docs)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 The indexes of the embedded documents retrieved by the retriever.</p>
</li>
<li>
<p><strong>context_input_ids</strong> (<code>tf.Tensor</code>(int32) of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.</p>
</li>
<li>
<p><strong>context_attention_mask</strong> (<code>tf.Tensor</code> (int32) of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) \u2014 Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
</li>
<li>
<p><strong>question_encoder_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
model.</p>
</li>
<li>
<p><strong>question_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>question_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_enc_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the generator encoder of the model.</p>
</li>
<li>
<p><strong>generator_enc_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_enc_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
<li>
<p><strong>generator_dec_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings and one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>generator_dec_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
average in the self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><code>transformers.models.rag.modeling_tf_rag.TFRetrievAugLMMarginOutput</code> or <code>tuple(tf.Tensor)</code></p>
`}}),Mt=new ge({props:{$$slots:{default:[iT]},$$scope:{ctx:F}}}),Gt=new sn({props:{anchor:"transformers.TFRagTokenForGeneration.call.example",$$slots:{default:[cT]},$$scope:{ctx:F}}}),en=new A({props:{name:"generate",anchor:"transformers.TFRagTokenForGeneration.generate",parameters:[{name:"input_ids",val:": typing.Union[typing.List[tensorflow.python.framework.ops.Tensor], typing.List[numpy.ndarray], typing.List[keras.engine.keras_tensor.KerasTensor], typing.Dict[str, tensorflow.python.framework.ops.Tensor], typing.Dict[str, numpy.ndarray], typing.Dict[str, keras.engine.keras_tensor.KerasTensor], tensorflow.python.framework.ops.Tensor, numpy.ndarray, keras.engine.keras_tensor.KerasTensor, NoneType] = None"},{name:"attention_mask",val:": typing.Optional[tensorflow.python.framework.ops.Tensor] = None"},{name:"context_input_ids",val:" = None"},{name:"context_attention_mask",val:" = None"},{name:"doc_scores",val:" = None"},{name:"n_docs",val:" = None"},{name:"generation_config",val:" = None"},{name:"logits_processor",val:" = []"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFRagTokenForGeneration.generate.input_ids",description:`<strong>input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
The sequence used as a prompt for the generation. If <code>input_ids</code> is not passed, then
<code>context_input_ids</code> has to be provided.`,name:"input_ids"},{anchor:"transformers.TFRagTokenForGeneration.generate.attention_mask",description:`<strong>attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TFRagTokenForGeneration.generate.context_input_ids",description:`<strong>context_input_ids</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Input IDs post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"context_input_ids"},{anchor:"transformers.TFRagTokenForGeneration.generate.context_attention_mask",description:`<strong>context_attention_mask</strong> (<code>tf.Tensor</code> of shape <code>(batch_size * config.n_docs, config.max_combined_length)</code>, <em>optional</em>, returned when <em>output_retrieved=True</em>) &#x2014;
Attention mask post-processed from the retrieved documents and the question encoder <code>input_ids</code> by the
retriever.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"context_attention_mask"},{anchor:"transformers.TFRagTokenForGeneration.generate.doc_scores",description:`<strong>doc_scores</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, config.n_docs)</code>) &#x2014;
Score between each retrieved document embeddings (see <code>retrieved_doc_embeds</code>) and
<code>question_encoder_last_hidden_state</code>.</p>
<p>If the model has is not initialized with a <code>retriever</code>, <code>context_input_ids</code> has to be provided to the
forward pass. <code>context_input_ids</code> are returned by <code>__call__()</code>.`,name:"doc_scores"},{anchor:"transformers.TFRagTokenForGeneration.generate.n_docs",description:`<strong>n_docs</strong> (<code>int</code>, <em>optional</em>, defaults to <code>config.n_docs</code>) &#x2014;
Number of documents to retrieve and/or number of documents for which to generate an answer.`,name:"n_docs"},{anchor:"transformers.TFRagTokenForGeneration.generate.generation_config",description:`<strong>generation_config</strong> (<code>~generation.GenerationConfig</code>, <em>optional</em>) &#x2014;
The generation configuration to be used as base parametrization for the generation call. <code>**kwargs</code>
passed to generate matching the attributes of <code>generation_config</code> will override them. If
<code>generation_config</code> is not provided, the default will be used, which had the following loading
priority: 1) from the <code>generation_config.json</code> model file, if it exists; 2) from the model
configuration. Please note that unspecified parameters will inherit <a href="/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationConfig">GenerationConfig</a>&#x2019;s
default values, whose documentation should be checked to parameterize generation.`,name:"generation_config"},{anchor:"transformers.TFRagTokenForGeneration.generate.logits_processor",description:`<strong>logits_processor</strong> (<code>TFLogitsProcessorList</code>, <em>optional</em>) &#x2014;
Custom logits processors that complement the default logits processors built from arguments and a
model&#x2019;s config. If a logit processor is passed that is already created with the arguments or a model&#x2019;s
config an error is thrown.
kwargs &#x2014;
Ad hoc parametrization of <code>generate_config</code> and/or additional model-specific kwargs that will be
forwarded to the <code>forward</code> function of the model.`,name:"logits_processor"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/rag/modeling_tf_rag.py#L994",returnDescription:`
<p>The generated sequences. The
second dimension (sequence_length) is either equal to <code>max_length</code> or shorter if all batches finished early
due to the <code>eos_token_id</code>.</p>
`,returnType:`
<p><code>tf.Tensor</code> of shape <code>(batch_size * num_return_sequences, sequence_length)</code></p>
`}}),{c(){c=s("meta"),b=p(),m=s("h1"),g=s("a"),f=s("span"),T(i.$$.fragment),u=p(),R=s("span"),ai=o("RAG"),Ba=p(),Ut=s("div"),cn=s("a"),ln=s("img"),Qa=p(),ke=s("h2"),Ve=s("a"),Mr=s("span"),T(Ht.$$.fragment),di=p(),Gr=s("span"),ii=o("Overview"),Ka=p(),pn=s("p"),ci=o(`Retrieval-augmented generation (\u201CRAG\u201D) 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.`),Va=p(),Ye=s("p"),li=o("It is based on the paper "),Wt=s("a"),pi=o("Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"),hi=o(` by Patrick Lewis, Ethan Perez, Aleksandara Piktus, Fabio Petroni, Vladimir
Karpukhin, Naman Goyal, Heinrich K\xFCttler, Mike Lewis, Wen-tau Yih, Tim Rockt\xE4schel, Sebastian Riedel, Douwe Kiela.`),Ya=p(),hn=s("p"),ui=o("The abstract from the paper is the following:"),Ja=p(),un=s("p"),Pr=s("em"),mi=o(`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) \u2014 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.`),Xa=p(),Je=s("p"),gi=o("This model was contributed by "),Bt=s("a"),_i=o("ola13"),fi=o("."),Za=p(),mn=s("p"),vi=o("Tips:"),ed=p(),gn=s("ul"),Nr=s("li"),bi=o("Retrieval-augmented generation (\u201CRAG\u201D) 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."),td=p(),qe=s("h2"),Xe=s("a"),Or=s("span"),T(Qt.$$.fragment),Ti=p(),Cr=s("span"),wi=o("RagConfig"),od=p(),ee=s("div"),T(Kt.$$.fragment),yi=p(),de=s("p"),_n=s("a"),ki=o("RagConfig"),qi=o(" stores the configuration of a "),Lr=s("em"),xi=o("RagModel"),Ri=o(". Configuration objects inherit from "),fn=s("a"),Fi=o("PretrainedConfig"),$i=o(` and
can be used to control the model outputs. Read the documentation from `),vn=s("a"),zi=o("PretrainedConfig"),Ei=o(" for more information."),ji=p(),Ze=s("div"),T(Vt.$$.fragment),Ai=p(),Yt=s("p"),Mi=o("Instantiate a "),bn=s("a"),Gi=o("EncoderDecoderConfig"),Pi=o(` (or a derived class) from a pre-trained encoder model configuration and
decoder model configuration.`),Ni=p(),et=s("div"),T(Jt.$$.fragment),Oi=p(),Xt=s("p"),Ci=o("Serializes this instance to a Python dictionary. Override the default "),Tn=s("a"),Li=o("to_dict()"),Si=o("."),nd=p(),xe=s("h2"),tt=s("a"),Sr=s("span"),T(Zt.$$.fragment),Di=p(),Dr=s("span"),Ii=o("RagTokenizer"),rd=p(),eo=s("div"),T(to.$$.fragment),sd=p(),Re=s("h2"),ot=s("a"),Ir=s("span"),T(oo.$$.fragment),Ui=p(),Ur=s("span"),Hi=o("Rag specific outputs"),ad=p(),Fe=s("div"),T(no.$$.fragment),Wi=p(),Hr=s("p"),Bi=o("Base class for retriever augmented marginalized models outputs."),dd=p(),ro=s("div"),T(so.$$.fragment),id=p(),$e=s("h2"),nt=s("a"),Wr=s("span"),T(ao.$$.fragment),Qi=p(),Br=s("span"),Ki=o("RagRetriever"),cd=p(),Z=s("div"),T(io.$$.fragment),Vi=p(),Qr=s("p"),Yi=o(`Retriever used to get documents from vector queries. It retrieves the documents embeddings as well as the documents
contents, and it formats them to be used with a RagModel.`),Ji=p(),T(rt.$$.fragment),Xi=p(),st=s("div"),T(co.$$.fragment),Zi=p(),Kr=s("p"),ec=o("Retriever initialization function. It loads the index into memory."),tc=p(),at=s("div"),T(lo.$$.fragment),oc=p(),ze=s("p"),nc=o("Postprocessing retrieved "),Vr=s("code"),rc=o("docs"),sc=o(" and combining them with "),Yr=s("code"),ac=o("input_strings"),dc=o("."),ic=p(),dt=s("div"),T(po.$$.fragment),cc=p(),ho=s("p"),lc=o("Retrieves documents for specified "),Jr=s("code"),pc=o("question_hidden_states"),hc=o("."),ld=p(),Ee=s("h2"),it=s("a"),Xr=s("span"),T(uo.$$.fragment),uc=p(),Zr=s("span"),mc=o("RagModel"),pd=p(),L=s("div"),T(mo.$$.fragment),gc=p(),je=s("p"),_c=o("The "),wn=s("a"),fc=o("RagModel"),vc=o(" forward method, overrides the "),es=s("code"),bc=o("__call__"),Tc=o(" special method."),wc=p(),T(ct.$$.fragment),yc=p(),ts=s("p"),kc=o(`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),qc=p(),te=s("p"),xc=o("The question encoder can be any "),os=s("em"),Rc=o("autoencoding"),Fc=o(" model, preferably "),yn=s("a"),$c=o("DPRQuestionEncoder"),zc=o(`, and the generator can be
any `),ns=s("em"),Ec=o("seq2seq"),jc=o(" model, preferably "),kn=s("a"),Ac=o("BartForConditionalGeneration"),Mc=o("."),Gc=p(),M=s("p"),Pc=o("The model can be initialized with a "),qn=s("a"),Nc=o("RagRetriever"),Oc=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),rs=s("em"),Cc=o("autoencoding"),Lc=o(" model as the "),ss=s("code"),Sc=o("question_encoder"),Dc=o(" and any "),as=s("em"),Ic=o("seq2seq"),Uc=o(" model with language model head as the "),ds=s("code"),Hc=o("generator"),Wc=o(`.
It has been tested with `),xn=s("a"),Bc=o("DPRQuestionEncoder"),Qc=o(" as the "),is=s("code"),Kc=o("question_encoder"),Vc=o(" and "),Rn=s("a"),Yc=o("BartForConditionalGeneration"),Jc=o(` or
`),Fn=s("a"),Xc=o("T5ForConditionalGeneration"),Zc=o(" as the "),cs=s("code"),el=o("generator"),tl=o("."),ol=p(),go=s("p"),nl=o("This model inherits from "),$n=s("a"),rl=o("PreTrainedModel"),sl=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),al=p(),_o=s("p"),dl=o("This model is also a PyTorch "),fo=s("a"),il=o("torch.nn.Module"),cl=o(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),ll=p(),ie=s("div"),T(vo.$$.fragment),pl=p(),Ae=s("p"),hl=o("The "),zn=s("a"),ul=o("RagModel"),ml=o(" forward method, overrides the "),ls=s("code"),gl=o("__call__"),_l=o(" special method."),fl=p(),T(lt.$$.fragment),vl=p(),T(pt.$$.fragment),hd=p(),Me=s("h2"),ht=s("a"),ps=s("span"),T(bo.$$.fragment),bl=p(),hs=s("span"),Tl=o("RagSequenceForGeneration"),ud=p(),E=s("div"),T(To.$$.fragment),wl=p(),Ge=s("p"),yl=o("The "),En=s("a"),kl=o("RagSequenceForGeneration"),ql=o(" forward method, overrides the "),us=s("code"),xl=o("__call__"),Rl=o(" special method."),Fl=p(),T(ut.$$.fragment),$l=p(),ms=s("p"),zl=o("A RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass."),El=p(),gs=s("p"),jl=o(`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),Al=p(),oe=s("p"),Ml=o("The question encoder can be any "),_s=s("em"),Gl=o("autoencoding"),Pl=o(" model, preferably "),jn=s("a"),Nl=o("DPRQuestionEncoder"),Ol=o(`, and the generator can be
any `),fs=s("em"),Cl=o("seq2seq"),Ll=o(" model, preferably "),An=s("a"),Sl=o("BartForConditionalGeneration"),Dl=o("."),Il=p(),G=s("p"),Ul=o("The model can be initialized with a "),Mn=s("a"),Hl=o("RagRetriever"),Wl=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),vs=s("em"),Bl=o("autoencoding"),Ql=o(" model as the "),bs=s("code"),Kl=o("question_encoder"),Vl=o(" and any "),Ts=s("em"),Yl=o("seq2seq"),Jl=o(" model with language model head as the "),ws=s("code"),Xl=o("generator"),Zl=o(`.
It has been tested with `),Gn=s("a"),ep=o("DPRQuestionEncoder"),tp=o(" as the "),ys=s("code"),op=o("question_encoder"),np=o(" and "),Pn=s("a"),rp=o("BartForConditionalGeneration"),sp=o(` or
`),Nn=s("a"),ap=o("T5ForConditionalGeneration"),dp=o(" as the "),ks=s("code"),ip=o("generator"),cp=o("."),lp=p(),wo=s("p"),pp=o("This model inherits from "),On=s("a"),hp=o("PreTrainedModel"),up=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),mp=p(),yo=s("p"),gp=o("This model is also a PyTorch "),ko=s("a"),_p=o("torch.nn.Module"),fp=o(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),vp=p(),ce=s("div"),T(qo.$$.fragment),bp=p(),Pe=s("p"),Tp=o("The "),Cn=s("a"),wp=o("RagSequenceForGeneration"),yp=o(" forward method, overrides the "),qs=s("code"),kp=o("__call__"),qp=o(" special method."),xp=p(),T(mt.$$.fragment),Rp=p(),T(gt.$$.fragment),Fp=p(),_t=s("div"),T(xo.$$.fragment),$p=p(),Ro=s("p"),zp=o("Implements RAG sequence \u201Cthorough\u201D decoding. Read the "),Ln=s("a"),Ep=o("generate()"),jp=o("` documentation\nfor more information on how to set other generate input parameters."),md=p(),Ne=s("h2"),ft=s("a"),xs=s("span"),T(Fo.$$.fragment),Ap=p(),Rs=s("span"),Mp=o("RagTokenForGeneration"),gd=p(),j=s("div"),T($o.$$.fragment),Gp=p(),Oe=s("p"),Pp=o("The "),Sn=s("a"),Np=o("RagTokenForGeneration"),Op=o(" forward method, overrides the "),Fs=s("code"),Cp=o("__call__"),Lp=o(" special method."),Sp=p(),T(vt.$$.fragment),Dp=p(),$s=s("p"),Ip=o("A RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass."),Up=p(),zs=s("p"),Hp=o(`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),Wp=p(),ne=s("p"),Bp=o("The question encoder can be any "),Es=s("em"),Qp=o("autoencoding"),Kp=o(" model, preferably "),Dn=s("a"),Vp=o("DPRQuestionEncoder"),Yp=o(`, and the generator can be
any `),js=s("em"),Jp=o("seq2seq"),Xp=o(" model, preferably "),In=s("a"),Zp=o("BartForConditionalGeneration"),eh=o("."),th=p(),P=s("p"),oh=o("The model can be initialized with a "),Un=s("a"),nh=o("RagRetriever"),rh=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),As=s("em"),sh=o("autoencoding"),ah=o(" model as the "),Ms=s("code"),dh=o("question_encoder"),ih=o(" and any "),Gs=s("em"),ch=o("seq2seq"),lh=o(" model with language model head as the "),Ps=s("code"),ph=o("generator"),hh=o(`.
It has been tested with `),Hn=s("a"),uh=o("DPRQuestionEncoder"),mh=o(" as the "),Ns=s("code"),gh=o("question_encoder"),_h=o(" and "),Wn=s("a"),fh=o("BartForConditionalGeneration"),vh=o(` or
`),Bn=s("a"),bh=o("T5ForConditionalGeneration"),Th=o(" as the "),Os=s("code"),wh=o("generator"),yh=o("."),kh=p(),zo=s("p"),qh=o("This model inherits from "),Qn=s("a"),xh=o("PreTrainedModel"),Rh=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Fh=p(),Eo=s("p"),$h=o("This model is also a PyTorch "),jo=s("a"),zh=o("torch.nn.Module"),Eh=o(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),jh=p(),le=s("div"),T(Ao.$$.fragment),Ah=p(),Ce=s("p"),Mh=o("The "),Kn=s("a"),Gh=o("RagTokenForGeneration"),Ph=o(" forward method, overrides the "),Cs=s("code"),Nh=o("__call__"),Oh=o(" special method."),Ch=p(),T(bt.$$.fragment),Lh=p(),T(Tt.$$.fragment),Sh=p(),wt=s("div"),T(Mo.$$.fragment),Dh=p(),Ls=s("p"),Ih=o("Implements RAG token decoding."),_d=p(),Le=s("h2"),yt=s("a"),Ss=s("span"),T(Go.$$.fragment),Uh=p(),Ds=s("span"),Hh=o("TFRagModel"),fd=p(),N=s("div"),T(Po.$$.fragment),Wh=p(),Se=s("p"),Bh=o("The "),Vn=s("a"),Qh=o("TFRagModel"),Kh=o(" forward method, overrides the "),Is=s("code"),Vh=o("__call__"),Yh=o(" special method."),Jh=p(),T(kt.$$.fragment),Xh=p(),Us=s("p"),Zh=o(`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),eu=p(),re=s("p"),tu=o("The question encoder can be any "),Hs=s("em"),ou=o("autoencoding"),nu=o(" model, preferably "),Yn=s("a"),ru=o("TFDPRQuestionEncoder"),su=o(`, and the generator can be
any `),Ws=s("em"),au=o("seq2seq"),du=o(" model, preferably "),Jn=s("a"),iu=o("TFBartForConditionalGeneration"),cu=o("."),lu=p(),S=s("p"),pu=o("The model can be initialized with a "),Xn=s("a"),hu=o("RagRetriever"),uu=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),Bs=s("em"),mu=o("autoencoding"),gu=o(" model as the "),Qs=s("code"),_u=o("question_encoder"),fu=o(" and any "),Ks=s("em"),vu=o("seq2seq"),bu=o(" model with language model head as the "),Vs=s("code"),Tu=o("generator"),wu=o(`.
It has been tested with `),Zn=s("a"),yu=o("TFDPRQuestionEncoder"),ku=o(" as the "),Ys=s("code"),qu=o("question_encoder"),xu=o(" and "),er=s("a"),Ru=o("TFBartForConditionalGeneration"),Fu=o(`
as the `),Js=s("code"),$u=o("generator"),zu=o("."),Eu=p(),No=s("p"),ju=o("This model inherits from "),tr=s("a"),Au=o("TFPreTrainedModel"),Mu=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Gu=p(),Oo=s("p"),Pu=o("This model is also a Tensorflow "),Co=s("a"),Nu=o("tf.keras.Model"),Ou=o(`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),Cu=p(),Xs=s("p"),Lu=o(`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),Su=p(),pe=s("div"),T(Lo.$$.fragment),Du=p(),De=s("p"),Iu=o("The "),or=s("a"),Uu=o("TFRagModel"),Hu=o(" forward method, overrides the "),Zs=s("code"),Wu=o("__call__"),Bu=o(" special method."),Qu=p(),T(qt.$$.fragment),Ku=p(),T(xt.$$.fragment),vd=p(),Ie=s("h2"),Rt=s("a"),ea=s("span"),T(So.$$.fragment),Vu=p(),ta=s("span"),Yu=o("TFRagSequenceForGeneration"),bd=p(),$=s("div"),T(Do.$$.fragment),Ju=p(),Ue=s("p"),Xu=o("The "),nr=s("a"),Zu=o("TFRagSequenceForGeneration"),em=o(" forward method, overrides the "),oa=s("code"),tm=o("__call__"),om=o(" special method."),nm=p(),T(Ft.$$.fragment),rm=p(),na=s("p"),sm=o("A TF RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass."),am=p(),ra=s("p"),dm=o(`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),im=p(),se=s("p"),cm=o("The question encoder can be any "),sa=s("em"),lm=o("autoencoding"),pm=o(" model, preferably "),rr=s("a"),hm=o("TFDPRQuestionEncoder"),um=o(`, and the generator can be
any `),aa=s("em"),mm=o("seq2seq"),gm=o(" model, preferably "),sr=s("a"),_m=o("TFBartForConditionalGeneration"),fm=o("."),vm=p(),D=s("p"),bm=o("The model can be initialized with a "),ar=s("a"),Tm=o("RagRetriever"),wm=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),da=s("em"),ym=o("autoencoding"),km=o(" model as the "),ia=s("code"),qm=o("question_encoder"),xm=o(" and any "),ca=s("em"),Rm=o("seq2seq"),Fm=o(" model with language model head as the "),la=s("code"),$m=o("generator"),zm=o(`.
It has been tested with `),dr=s("a"),Em=o("TFDPRQuestionEncoder"),jm=o(" as the "),pa=s("code"),Am=o("question_encoder"),Mm=o(" and "),ir=s("a"),Gm=o("TFBartForConditionalGeneration"),Pm=o(`
as the `),ha=s("code"),Nm=o("generator"),Om=o("."),Cm=p(),Io=s("p"),Lm=o("This model inherits from "),cr=s("a"),Sm=o("TFPreTrainedModel"),Dm=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Im=p(),Uo=s("p"),Um=o("This model is also a Tensorflow "),Ho=s("a"),Hm=o("tf.keras.Model"),Wm=o(`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),Bm=p(),ua=s("p"),Qm=o(`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),Km=p(),he=s("div"),T(Wo.$$.fragment),Vm=p(),He=s("p"),Ym=o("The "),lr=s("a"),Jm=o("TFRagSequenceForGeneration"),Xm=o(" forward method, overrides the "),ma=s("code"),Zm=o("__call__"),eg=o(" special method."),tg=p(),T($t.$$.fragment),og=p(),T(zt.$$.fragment),ng=p(),Et=s("div"),T(Bo.$$.fragment),rg=p(),Qo=s("p"),sg=o("Implements RAG sequence \u201Cthorough\u201D decoding. Read the "),pr=s("a"),ag=o("generate()"),dg=o("` documentation\nfor more information on how to set other generate input parameters"),Td=p(),We=s("h2"),jt=s("a"),ga=s("span"),T(Ko.$$.fragment),ig=p(),_a=s("span"),cg=o("TFRagTokenForGeneration"),wd=p(),z=s("div"),T(Vo.$$.fragment),lg=p(),Be=s("p"),pg=o("The "),hr=s("a"),hg=o("TFRagTokenForGeneration"),ug=o(" forward method, overrides the "),fa=s("code"),mg=o("__call__"),gg=o(" special method."),_g=p(),T(At.$$.fragment),fg=p(),va=s("p"),vg=o("A TF RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass."),bg=p(),ba=s("p"),Tg=o(`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),wg=p(),ae=s("p"),yg=o("The question encoder can be any "),Ta=s("em"),kg=o("autoencoding"),qg=o(" model, preferably "),ur=s("a"),xg=o("TFDPRQuestionEncoder"),Rg=o(`, and the generator can be
any `),wa=s("em"),Fg=o("seq2seq"),$g=o(" model, preferably "),mr=s("a"),zg=o("TFBartForConditionalGeneration"),Eg=o("."),jg=p(),I=s("p"),Ag=o("The model can be initialized with a "),gr=s("a"),Mg=o("RagRetriever"),Gg=o(` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),ya=s("em"),Pg=o("autoencoding"),Ng=o(" model as the "),ka=s("code"),Og=o("question_encoder"),Cg=o(" and any "),qa=s("em"),Lg=o("seq2seq"),Sg=o(" model with language model head as the "),xa=s("code"),Dg=o("generator"),Ig=o(`.
It has been tested with `),_r=s("a"),Ug=o("TFDPRQuestionEncoder"),Hg=o(" as the "),Ra=s("code"),Wg=o("question_encoder"),Bg=o(" and "),fr=s("a"),Qg=o("TFBartForConditionalGeneration"),Kg=o(`
as the `),Fa=s("code"),Vg=o("generator"),Yg=o("."),Jg=p(),Yo=s("p"),Xg=o("This model inherits from "),vr=s("a"),Zg=o("TFPreTrainedModel"),e_=o(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),t_=p(),Jo=s("p"),o_=o("This model is also a Tensorflow "),Xo=s("a"),n_=o("tf.keras.Model"),r_=o(`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),s_=p(),$a=s("p"),a_=o(`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),d_=p(),ue=s("div"),T(Zo.$$.fragment),i_=p(),Qe=s("p"),c_=o("The "),br=s("a"),l_=o("TFRagTokenForGeneration"),p_=o(" forward method, overrides the "),za=s("code"),h_=o("__call__"),u_=o(" special method."),m_=p(),T(Mt.$$.fragment),g_=p(),T(Gt.$$.fragment),__=p(),Pt=s("div"),T(en.$$.fragment),f_=p(),Ea=s("p"),v_=o("Implements TFRAG token decoding."),this.h()},l(r){const _=Ib('[data-svelte="svelte-1phssyn"]',document.head);c=a(_,"META",{name:!0,content:!0}),_.forEach(t),b=h(r),m=a(r,"H1",{class:!0});var tn=d(m);g=a(tn,"A",{id:!0,class:!0,href:!0});var ja=d(g);f=a(ja,"SPAN",{});var Aa=d(f);w(i.$$.fragment,Aa),Aa.forEach(t),ja.forEach(t),u=h(tn),R=a(tn,"SPAN",{});var Ma=d(R);ai=n(Ma,"RAG"),Ma.forEach(t),tn.forEach(t),Ba=h(r),Ut=a(r,"DIV",{class:!0});var Ga=d(Ut);cn=a(Ga,"A",{href:!0});var Pa=d(cn);ln=a(Pa,"IMG",{alt:!0,src:!0}),Pa.forEach(t),Ga.forEach(t),Qa=h(r),ke=a(r,"H2",{class:!0});var on=d(ke);Ve=a(on,"A",{id:!0,class:!0,href:!0});var Na=d(Ve);Mr=a(Na,"SPAN",{});var Oa=d(Mr);w(Ht.$$.fragment,Oa),Oa.forEach(t),Na.forEach(t),di=h(on),Gr=a(on,"SPAN",{});var Ca=d(Gr);ii=n(Ca,"Overview"),Ca.forEach(t),on.forEach(t),Ka=h(r),pn=a(r,"P",{});var La=d(pn);ci=n(La,`Retrieval-augmented generation (\u201CRAG\u201D) 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.`),La.forEach(t),Va=h(r),Ye=a(r,"P",{});var nn=d(Ye);li=n(nn,"It is based on the paper "),Wt=a(nn,"A",{href:!0,rel:!0});var Sa=d(Wt);pi=n(Sa,"Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"),Sa.forEach(t),hi=n(nn,` by Patrick Lewis, Ethan Perez, Aleksandara Piktus, Fabio Petroni, Vladimir
Karpukhin, Naman Goyal, Heinrich K\xFCttler, Mike Lewis, Wen-tau Yih, Tim Rockt\xE4schel, Sebastian Riedel, Douwe Kiela.`),nn.forEach(t),Ya=h(r),hn=a(r,"P",{});var Da=d(hn);ui=n(Da,"The abstract from the paper is the following:"),Da.forEach(t),Ja=h(r),un=a(r,"P",{});var Ia=d(un);Pr=a(Ia,"EM",{});var Ua=d(Pr);mi=n(Ua,`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) \u2014 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.`),Ua.forEach(t),Ia.forEach(t),Xa=h(r),Je=a(r,"P",{});var rn=d(Je);gi=n(rn,"This model was contributed by "),Bt=a(rn,"A",{href:!0,rel:!0});var Ha=d(Bt);_i=n(Ha,"ola13"),Ha.forEach(t),fi=n(rn,"."),rn.forEach(t),Za=h(r),mn=a(r,"P",{});var Wa=d(mn);vi=n(Wa,"Tips:"),Wa.forEach(t),ed=h(r),gn=a(r,"UL",{});var T_=d(gn);Nr=a(T_,"LI",{});var w_=d(Nr);bi=n(w_,"Retrieval-augmented generation (\u201CRAG\u201D) 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."),w_.forEach(t),T_.forEach(t),td=h(r),qe=a(r,"H2",{class:!0});var kd=d(qe);Xe=a(kd,"A",{id:!0,class:!0,href:!0});var y_=d(Xe);Or=a(y_,"SPAN",{});var k_=d(Or);w(Qt.$$.fragment,k_),k_.forEach(t),y_.forEach(t),Ti=h(kd),Cr=a(kd,"SPAN",{});var q_=d(Cr);wi=n(q_,"RagConfig"),q_.forEach(t),kd.forEach(t),od=h(r),ee=a(r,"DIV",{class:!0});var Nt=d(ee);w(Kt.$$.fragment,Nt),yi=h(Nt),de=a(Nt,"P",{});var Ke=d(de);_n=a(Ke,"A",{href:!0});var x_=d(_n);ki=n(x_,"RagConfig"),x_.forEach(t),qi=n(Ke," stores the configuration of a "),Lr=a(Ke,"EM",{});var R_=d(Lr);xi=n(R_,"RagModel"),R_.forEach(t),Ri=n(Ke,". Configuration objects inherit from "),fn=a(Ke,"A",{href:!0});var F_=d(fn);Fi=n(F_,"PretrainedConfig"),F_.forEach(t),$i=n(Ke,` and
can be used to control the model outputs. Read the documentation from `),vn=a(Ke,"A",{href:!0});var $_=d(vn);zi=n($_,"PretrainedConfig"),$_.forEach(t),Ei=n(Ke," for more information."),Ke.forEach(t),ji=h(Nt),Ze=a(Nt,"DIV",{class:!0});var qd=d(Ze);w(Vt.$$.fragment,qd),Ai=h(qd),Yt=a(qd,"P",{});var xd=d(Yt);Mi=n(xd,"Instantiate a "),bn=a(xd,"A",{href:!0});var z_=d(bn);Gi=n(z_,"EncoderDecoderConfig"),z_.forEach(t),Pi=n(xd,` (or a derived class) from a pre-trained encoder model configuration and
decoder model configuration.`),xd.forEach(t),qd.forEach(t),Ni=h(Nt),et=a(Nt,"DIV",{class:!0});var Rd=d(et);w(Jt.$$.fragment,Rd),Oi=h(Rd),Xt=a(Rd,"P",{});var Fd=d(Xt);Ci=n(Fd,"Serializes this instance to a Python dictionary. Override the default "),Tn=a(Fd,"A",{href:!0});var E_=d(Tn);Li=n(E_,"to_dict()"),E_.forEach(t),Si=n(Fd,"."),Fd.forEach(t),Rd.forEach(t),Nt.forEach(t),nd=h(r),xe=a(r,"H2",{class:!0});var $d=d(xe);tt=a($d,"A",{id:!0,class:!0,href:!0});var j_=d(tt);Sr=a(j_,"SPAN",{});var A_=d(Sr);w(Zt.$$.fragment,A_),A_.forEach(t),j_.forEach(t),Di=h($d),Dr=a($d,"SPAN",{});var M_=d(Dr);Ii=n(M_,"RagTokenizer"),M_.forEach(t),$d.forEach(t),rd=h(r),eo=a(r,"DIV",{class:!0});var G_=d(eo);w(to.$$.fragment,G_),G_.forEach(t),sd=h(r),Re=a(r,"H2",{class:!0});var zd=d(Re);ot=a(zd,"A",{id:!0,class:!0,href:!0});var P_=d(ot);Ir=a(P_,"SPAN",{});var N_=d(Ir);w(oo.$$.fragment,N_),N_.forEach(t),P_.forEach(t),Ui=h(zd),Ur=a(zd,"SPAN",{});var O_=d(Ur);Hi=n(O_,"Rag specific outputs"),O_.forEach(t),zd.forEach(t),ad=h(r),Fe=a(r,"DIV",{class:!0});var Ed=d(Fe);w(no.$$.fragment,Ed),Wi=h(Ed),Hr=a(Ed,"P",{});var C_=d(Hr);Bi=n(C_,"Base class for retriever augmented marginalized models outputs."),C_.forEach(t),Ed.forEach(t),dd=h(r),ro=a(r,"DIV",{class:!0});var L_=d(ro);w(so.$$.fragment,L_),L_.forEach(t),id=h(r),$e=a(r,"H2",{class:!0});var jd=d($e);nt=a(jd,"A",{id:!0,class:!0,href:!0});var S_=d(nt);Wr=a(S_,"SPAN",{});var D_=d(Wr);w(ao.$$.fragment,D_),D_.forEach(t),S_.forEach(t),Qi=h(jd),Br=a(jd,"SPAN",{});var I_=d(Br);Ki=n(I_,"RagRetriever"),I_.forEach(t),jd.forEach(t),cd=h(r),Z=a(r,"DIV",{class:!0});var me=d(Z);w(io.$$.fragment,me),Vi=h(me),Qr=a(me,"P",{});var U_=d(Qr);Yi=n(U_,`Retriever used to get documents from vector queries. It retrieves the documents embeddings as well as the documents
contents, and it formats them to be used with a RagModel.`),U_.forEach(t),Ji=h(me),w(rt.$$.fragment,me),Xi=h(me),st=a(me,"DIV",{class:!0});var Ad=d(st);w(co.$$.fragment,Ad),Zi=h(Ad),Kr=a(Ad,"P",{});var H_=d(Kr);ec=n(H_,"Retriever initialization function. It loads the index into memory."),H_.forEach(t),Ad.forEach(t),tc=h(me),at=a(me,"DIV",{class:!0});var Md=d(at);w(lo.$$.fragment,Md),oc=h(Md),ze=a(Md,"P",{});var Tr=d(ze);nc=n(Tr,"Postprocessing retrieved "),Vr=a(Tr,"CODE",{});var W_=d(Vr);rc=n(W_,"docs"),W_.forEach(t),sc=n(Tr," and combining them with "),Yr=a(Tr,"CODE",{});var B_=d(Yr);ac=n(B_,"input_strings"),B_.forEach(t),dc=n(Tr,"."),Tr.forEach(t),Md.forEach(t),ic=h(me),dt=a(me,"DIV",{class:!0});var Gd=d(dt);w(po.$$.fragment,Gd),cc=h(Gd),ho=a(Gd,"P",{});var Pd=d(ho);lc=n(Pd,"Retrieves documents for specified "),Jr=a(Pd,"CODE",{});var Q_=d(Jr);pc=n(Q_,"question_hidden_states"),Q_.forEach(t),hc=n(Pd,"."),Pd.forEach(t),Gd.forEach(t),me.forEach(t),ld=h(r),Ee=a(r,"H2",{class:!0});var Nd=d(Ee);it=a(Nd,"A",{id:!0,class:!0,href:!0});var K_=d(it);Xr=a(K_,"SPAN",{});var V_=d(Xr);w(uo.$$.fragment,V_),V_.forEach(t),K_.forEach(t),uc=h(Nd),Zr=a(Nd,"SPAN",{});var Y_=d(Zr);mc=n(Y_,"RagModel"),Y_.forEach(t),Nd.forEach(t),pd=h(r),L=a(r,"DIV",{class:!0});var X=d(L);w(mo.$$.fragment,X),gc=h(X),je=a(X,"P",{});var wr=d(je);_c=n(wr,"The "),wn=a(wr,"A",{href:!0});var J_=d(wn);fc=n(J_,"RagModel"),J_.forEach(t),vc=n(wr," forward method, overrides the "),es=a(wr,"CODE",{});var X_=d(es);bc=n(X_,"__call__"),X_.forEach(t),Tc=n(wr," special method."),wr.forEach(t),wc=h(X),w(ct.$$.fragment,X),yc=h(X),ts=a(X,"P",{});var Z_=d(ts);kc=n(Z_,`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),Z_.forEach(t),qc=h(X),te=a(X,"P",{});var fe=d(te);xc=n(fe,"The question encoder can be any "),os=a(fe,"EM",{});var ef=d(os);Rc=n(ef,"autoencoding"),ef.forEach(t),Fc=n(fe," model, preferably "),yn=a(fe,"A",{href:!0});var tf=d(yn);$c=n(tf,"DPRQuestionEncoder"),tf.forEach(t),zc=n(fe,`, and the generator can be
any `),ns=a(fe,"EM",{});var of=d(ns);Ec=n(of,"seq2seq"),of.forEach(t),jc=n(fe," model, preferably "),kn=a(fe,"A",{href:!0});var nf=d(kn);Ac=n(nf,"BartForConditionalGeneration"),nf.forEach(t),Mc=n(fe,"."),fe.forEach(t),Gc=h(X),M=a(X,"P",{});var U=d(M);Pc=n(U,"The model can be initialized with a "),qn=a(U,"A",{href:!0});var rf=d(qn);Nc=n(rf,"RagRetriever"),rf.forEach(t),Oc=n(U,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),rs=a(U,"EM",{});var sf=d(rs);Cc=n(sf,"autoencoding"),sf.forEach(t),Lc=n(U," model as the "),ss=a(U,"CODE",{});var af=d(ss);Sc=n(af,"question_encoder"),af.forEach(t),Dc=n(U," and any "),as=a(U,"EM",{});var df=d(as);Ic=n(df,"seq2seq"),df.forEach(t),Uc=n(U," model with language model head as the "),ds=a(U,"CODE",{});var cf=d(ds);Hc=n(cf,"generator"),cf.forEach(t),Wc=n(U,`.
It has been tested with `),xn=a(U,"A",{href:!0});var lf=d(xn);Bc=n(lf,"DPRQuestionEncoder"),lf.forEach(t),Qc=n(U," as the "),is=a(U,"CODE",{});var pf=d(is);Kc=n(pf,"question_encoder"),pf.forEach(t),Vc=n(U," and "),Rn=a(U,"A",{href:!0});var hf=d(Rn);Yc=n(hf,"BartForConditionalGeneration"),hf.forEach(t),Jc=n(U,` or
`),Fn=a(U,"A",{href:!0});var uf=d(Fn);Xc=n(uf,"T5ForConditionalGeneration"),uf.forEach(t),Zc=n(U," as the "),cs=a(U,"CODE",{});var mf=d(cs);el=n(mf,"generator"),mf.forEach(t),tl=n(U,"."),U.forEach(t),ol=h(X),go=a(X,"P",{});var Od=d(go);nl=n(Od,"This model inherits from "),$n=a(Od,"A",{href:!0});var gf=d($n);rl=n(gf,"PreTrainedModel"),gf.forEach(t),sl=n(Od,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Od.forEach(t),al=h(X),_o=a(X,"P",{});var Cd=d(_o);dl=n(Cd,"This model is also a PyTorch "),fo=a(Cd,"A",{href:!0,rel:!0});var _f=d(fo);il=n(_f,"torch.nn.Module"),_f.forEach(t),cl=n(Cd,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Cd.forEach(t),ll=h(X),ie=a(X,"DIV",{class:!0});var Ot=d(ie);w(vo.$$.fragment,Ot),pl=h(Ot),Ae=a(Ot,"P",{});var yr=d(Ae);hl=n(yr,"The "),zn=a(yr,"A",{href:!0});var ff=d(zn);ul=n(ff,"RagModel"),ff.forEach(t),ml=n(yr," forward method, overrides the "),ls=a(yr,"CODE",{});var vf=d(ls);gl=n(vf,"__call__"),vf.forEach(t),_l=n(yr," special method."),yr.forEach(t),fl=h(Ot),w(lt.$$.fragment,Ot),vl=h(Ot),w(pt.$$.fragment,Ot),Ot.forEach(t),X.forEach(t),hd=h(r),Me=a(r,"H2",{class:!0});var Ld=d(Me);ht=a(Ld,"A",{id:!0,class:!0,href:!0});var bf=d(ht);ps=a(bf,"SPAN",{});var Tf=d(ps);w(bo.$$.fragment,Tf),Tf.forEach(t),bf.forEach(t),bl=h(Ld),hs=a(Ld,"SPAN",{});var wf=d(hs);Tl=n(wf,"RagSequenceForGeneration"),wf.forEach(t),Ld.forEach(t),ud=h(r),E=a(r,"DIV",{class:!0});var H=d(E);w(To.$$.fragment,H),wl=h(H),Ge=a(H,"P",{});var kr=d(Ge);yl=n(kr,"The "),En=a(kr,"A",{href:!0});var yf=d(En);kl=n(yf,"RagSequenceForGeneration"),yf.forEach(t),ql=n(kr," forward method, overrides the "),us=a(kr,"CODE",{});var kf=d(us);xl=n(kf,"__call__"),kf.forEach(t),Rl=n(kr," special method."),kr.forEach(t),Fl=h(H),w(ut.$$.fragment,H),$l=h(H),ms=a(H,"P",{});var qf=d(ms);zl=n(qf,"A RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass."),qf.forEach(t),El=h(H),gs=a(H,"P",{});var xf=d(gs);jl=n(xf,`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),xf.forEach(t),Al=h(H),oe=a(H,"P",{});var ve=d(oe);Ml=n(ve,"The question encoder can be any "),_s=a(ve,"EM",{});var Rf=d(_s);Gl=n(Rf,"autoencoding"),Rf.forEach(t),Pl=n(ve," model, preferably "),jn=a(ve,"A",{href:!0});var Ff=d(jn);Nl=n(Ff,"DPRQuestionEncoder"),Ff.forEach(t),Ol=n(ve,`, and the generator can be
any `),fs=a(ve,"EM",{});var $f=d(fs);Cl=n($f,"seq2seq"),$f.forEach(t),Ll=n(ve," model, preferably "),An=a(ve,"A",{href:!0});var zf=d(An);Sl=n(zf,"BartForConditionalGeneration"),zf.forEach(t),Dl=n(ve,"."),ve.forEach(t),Il=h(H),G=a(H,"P",{});var W=d(G);Ul=n(W,"The model can be initialized with a "),Mn=a(W,"A",{href:!0});var Ef=d(Mn);Hl=n(Ef,"RagRetriever"),Ef.forEach(t),Wl=n(W,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),vs=a(W,"EM",{});var jf=d(vs);Bl=n(jf,"autoencoding"),jf.forEach(t),Ql=n(W," model as the "),bs=a(W,"CODE",{});var Af=d(bs);Kl=n(Af,"question_encoder"),Af.forEach(t),Vl=n(W," and any "),Ts=a(W,"EM",{});var Mf=d(Ts);Yl=n(Mf,"seq2seq"),Mf.forEach(t),Jl=n(W," model with language model head as the "),ws=a(W,"CODE",{});var Gf=d(ws);Xl=n(Gf,"generator"),Gf.forEach(t),Zl=n(W,`.
It has been tested with `),Gn=a(W,"A",{href:!0});var Pf=d(Gn);ep=n(Pf,"DPRQuestionEncoder"),Pf.forEach(t),tp=n(W," as the "),ys=a(W,"CODE",{});var Nf=d(ys);op=n(Nf,"question_encoder"),Nf.forEach(t),np=n(W," and "),Pn=a(W,"A",{href:!0});var Of=d(Pn);rp=n(Of,"BartForConditionalGeneration"),Of.forEach(t),sp=n(W,` or
`),Nn=a(W,"A",{href:!0});var Cf=d(Nn);ap=n(Cf,"T5ForConditionalGeneration"),Cf.forEach(t),dp=n(W," as the "),ks=a(W,"CODE",{});var Lf=d(ks);ip=n(Lf,"generator"),Lf.forEach(t),cp=n(W,"."),W.forEach(t),lp=h(H),wo=a(H,"P",{});var Sd=d(wo);pp=n(Sd,"This model inherits from "),On=a(Sd,"A",{href:!0});var Sf=d(On);hp=n(Sf,"PreTrainedModel"),Sf.forEach(t),up=n(Sd,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Sd.forEach(t),mp=h(H),yo=a(H,"P",{});var Dd=d(yo);gp=n(Dd,"This model is also a PyTorch "),ko=a(Dd,"A",{href:!0,rel:!0});var Df=d(ko);_p=n(Df,"torch.nn.Module"),Df.forEach(t),fp=n(Dd,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Dd.forEach(t),vp=h(H),ce=a(H,"DIV",{class:!0});var Ct=d(ce);w(qo.$$.fragment,Ct),bp=h(Ct),Pe=a(Ct,"P",{});var qr=d(Pe);Tp=n(qr,"The "),Cn=a(qr,"A",{href:!0});var If=d(Cn);wp=n(If,"RagSequenceForGeneration"),If.forEach(t),yp=n(qr," forward method, overrides the "),qs=a(qr,"CODE",{});var Uf=d(qs);kp=n(Uf,"__call__"),Uf.forEach(t),qp=n(qr," special method."),qr.forEach(t),xp=h(Ct),w(mt.$$.fragment,Ct),Rp=h(Ct),w(gt.$$.fragment,Ct),Ct.forEach(t),Fp=h(H),_t=a(H,"DIV",{class:!0});var Id=d(_t);w(xo.$$.fragment,Id),$p=h(Id),Ro=a(Id,"P",{});var Ud=d(Ro);zp=n(Ud,"Implements RAG sequence \u201Cthorough\u201D decoding. Read the "),Ln=a(Ud,"A",{href:!0});var Hf=d(Ln);Ep=n(Hf,"generate()"),Hf.forEach(t),jp=n(Ud,"` documentation\nfor more information on how to set other generate input parameters."),Ud.forEach(t),Id.forEach(t),H.forEach(t),md=h(r),Ne=a(r,"H2",{class:!0});var Hd=d(Ne);ft=a(Hd,"A",{id:!0,class:!0,href:!0});var Wf=d(ft);xs=a(Wf,"SPAN",{});var Bf=d(xs);w(Fo.$$.fragment,Bf),Bf.forEach(t),Wf.forEach(t),Ap=h(Hd),Rs=a(Hd,"SPAN",{});var Qf=d(Rs);Mp=n(Qf,"RagTokenForGeneration"),Qf.forEach(t),Hd.forEach(t),gd=h(r),j=a(r,"DIV",{class:!0});var B=d(j);w($o.$$.fragment,B),Gp=h(B),Oe=a(B,"P",{});var xr=d(Oe);Pp=n(xr,"The "),Sn=a(xr,"A",{href:!0});var Kf=d(Sn);Np=n(Kf,"RagTokenForGeneration"),Kf.forEach(t),Op=n(xr," forward method, overrides the "),Fs=a(xr,"CODE",{});var Vf=d(Fs);Cp=n(Vf,"__call__"),Vf.forEach(t),Lp=n(xr," special method."),xr.forEach(t),Sp=h(B),w(vt.$$.fragment,B),Dp=h(B),$s=a(B,"P",{});var Yf=d($s);Ip=n(Yf,"A RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass."),Yf.forEach(t),Up=h(B),zs=a(B,"P",{});var Jf=d(zs);Hp=n(Jf,`RAG is a seq2seq model which encapsulates two core components: a question encoder and a generator. During a forward
pass, we encode the input with the question encoder and pass it to the retriever to extract relevant context
documents. The documents are then prepended to the input. Such contextualized inputs is passed to the generator.`),Jf.forEach(t),Wp=h(B),ne=a(B,"P",{});var be=d(ne);Bp=n(be,"The question encoder can be any "),Es=a(be,"EM",{});var Xf=d(Es);Qp=n(Xf,"autoencoding"),Xf.forEach(t),Kp=n(be," model, preferably "),Dn=a(be,"A",{href:!0});var Zf=d(Dn);Vp=n(Zf,"DPRQuestionEncoder"),Zf.forEach(t),Yp=n(be,`, and the generator can be
any `),js=a(be,"EM",{});var ev=d(js);Jp=n(ev,"seq2seq"),ev.forEach(t),Xp=n(be," model, preferably "),In=a(be,"A",{href:!0});var tv=d(In);Zp=n(tv,"BartForConditionalGeneration"),tv.forEach(t),eh=n(be,"."),be.forEach(t),th=h(B),P=a(B,"P",{});var Q=d(P);oh=n(Q,"The model can be initialized with a "),Un=a(Q,"A",{href:!0});var ov=d(Un);nh=n(ov,"RagRetriever"),ov.forEach(t),rh=n(Q,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),As=a(Q,"EM",{});var nv=d(As);sh=n(nv,"autoencoding"),nv.forEach(t),ah=n(Q," model as the "),Ms=a(Q,"CODE",{});var rv=d(Ms);dh=n(rv,"question_encoder"),rv.forEach(t),ih=n(Q," and any "),Gs=a(Q,"EM",{});var sv=d(Gs);ch=n(sv,"seq2seq"),sv.forEach(t),lh=n(Q," model with language model head as the "),Ps=a(Q,"CODE",{});var av=d(Ps);ph=n(av,"generator"),av.forEach(t),hh=n(Q,`.
It has been tested with `),Hn=a(Q,"A",{href:!0});var dv=d(Hn);uh=n(dv,"DPRQuestionEncoder"),dv.forEach(t),mh=n(Q," as the "),Ns=a(Q,"CODE",{});var iv=d(Ns);gh=n(iv,"question_encoder"),iv.forEach(t),_h=n(Q," and "),Wn=a(Q,"A",{href:!0});var cv=d(Wn);fh=n(cv,"BartForConditionalGeneration"),cv.forEach(t),vh=n(Q,` or
`),Bn=a(Q,"A",{href:!0});var lv=d(Bn);bh=n(lv,"T5ForConditionalGeneration"),lv.forEach(t),Th=n(Q," as the "),Os=a(Q,"CODE",{});var pv=d(Os);wh=n(pv,"generator"),pv.forEach(t),yh=n(Q,"."),Q.forEach(t),kh=h(B),zo=a(B,"P",{});var Wd=d(zo);qh=n(Wd,"This model inherits from "),Qn=a(Wd,"A",{href:!0});var hv=d(Qn);xh=n(hv,"PreTrainedModel"),hv.forEach(t),Rh=n(Wd,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Wd.forEach(t),Fh=h(B),Eo=a(B,"P",{});var Bd=d(Eo);$h=n(Bd,"This model is also a PyTorch "),jo=a(Bd,"A",{href:!0,rel:!0});var uv=d(jo);zh=n(uv,"torch.nn.Module"),uv.forEach(t),Eh=n(Bd,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Bd.forEach(t),jh=h(B),le=a(B,"DIV",{class:!0});var Lt=d(le);w(Ao.$$.fragment,Lt),Ah=h(Lt),Ce=a(Lt,"P",{});var Rr=d(Ce);Mh=n(Rr,"The "),Kn=a(Rr,"A",{href:!0});var mv=d(Kn);Gh=n(mv,"RagTokenForGeneration"),mv.forEach(t),Ph=n(Rr," forward method, overrides the "),Cs=a(Rr,"CODE",{});var gv=d(Cs);Nh=n(gv,"__call__"),gv.forEach(t),Oh=n(Rr," special method."),Rr.forEach(t),Ch=h(Lt),w(bt.$$.fragment,Lt),Lh=h(Lt),w(Tt.$$.fragment,Lt),Lt.forEach(t),Sh=h(B),wt=a(B,"DIV",{class:!0});var Qd=d(wt);w(Mo.$$.fragment,Qd),Dh=h(Qd),Ls=a(Qd,"P",{});var _v=d(Ls);Ih=n(_v,"Implements RAG token decoding."),_v.forEach(t),Qd.forEach(t),B.forEach(t),_d=h(r),Le=a(r,"H2",{class:!0});var Kd=d(Le);yt=a(Kd,"A",{id:!0,class:!0,href:!0});var fv=d(yt);Ss=a(fv,"SPAN",{});var vv=d(Ss);w(Go.$$.fragment,vv),vv.forEach(t),fv.forEach(t),Uh=h(Kd),Ds=a(Kd,"SPAN",{});var bv=d(Ds);Hh=n(bv,"TFRagModel"),bv.forEach(t),Kd.forEach(t),fd=h(r),N=a(r,"DIV",{class:!0});var K=d(N);w(Po.$$.fragment,K),Wh=h(K),Se=a(K,"P",{});var Fr=d(Se);Bh=n(Fr,"The "),Vn=a(Fr,"A",{href:!0});var Tv=d(Vn);Qh=n(Tv,"TFRagModel"),Tv.forEach(t),Kh=n(Fr," forward method, overrides the "),Is=a(Fr,"CODE",{});var wv=d(Is);Vh=n(wv,"__call__"),wv.forEach(t),Yh=n(Fr," special method."),Fr.forEach(t),Jh=h(K),w(kt.$$.fragment,K),Xh=h(K),Us=a(K,"P",{});var yv=d(Us);Zh=n(yv,`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),yv.forEach(t),eu=h(K),re=a(K,"P",{});var Te=d(re);tu=n(Te,"The question encoder can be any "),Hs=a(Te,"EM",{});var kv=d(Hs);ou=n(kv,"autoencoding"),kv.forEach(t),nu=n(Te," model, preferably "),Yn=a(Te,"A",{href:!0});var qv=d(Yn);ru=n(qv,"TFDPRQuestionEncoder"),qv.forEach(t),su=n(Te,`, and the generator can be
any `),Ws=a(Te,"EM",{});var xv=d(Ws);au=n(xv,"seq2seq"),xv.forEach(t),du=n(Te," model, preferably "),Jn=a(Te,"A",{href:!0});var Rv=d(Jn);iu=n(Rv,"TFBartForConditionalGeneration"),Rv.forEach(t),cu=n(Te,"."),Te.forEach(t),lu=h(K),S=a(K,"P",{});var V=d(S);pu=n(V,"The model can be initialized with a "),Xn=a(V,"A",{href:!0});var Fv=d(Xn);hu=n(Fv,"RagRetriever"),Fv.forEach(t),uu=n(V,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),Bs=a(V,"EM",{});var $v=d(Bs);mu=n($v,"autoencoding"),$v.forEach(t),gu=n(V," model as the "),Qs=a(V,"CODE",{});var zv=d(Qs);_u=n(zv,"question_encoder"),zv.forEach(t),fu=n(V," and any "),Ks=a(V,"EM",{});var Ev=d(Ks);vu=n(Ev,"seq2seq"),Ev.forEach(t),bu=n(V," model with language model head as the "),Vs=a(V,"CODE",{});var jv=d(Vs);Tu=n(jv,"generator"),jv.forEach(t),wu=n(V,`.
It has been tested with `),Zn=a(V,"A",{href:!0});var Av=d(Zn);yu=n(Av,"TFDPRQuestionEncoder"),Av.forEach(t),ku=n(V," as the "),Ys=a(V,"CODE",{});var Mv=d(Ys);qu=n(Mv,"question_encoder"),Mv.forEach(t),xu=n(V," and "),er=a(V,"A",{href:!0});var Gv=d(er);Ru=n(Gv,"TFBartForConditionalGeneration"),Gv.forEach(t),Fu=n(V,`
as the `),Js=a(V,"CODE",{});var Pv=d(Js);$u=n(Pv,"generator"),Pv.forEach(t),zu=n(V,"."),V.forEach(t),Eu=h(K),No=a(K,"P",{});var Vd=d(No);ju=n(Vd,"This model inherits from "),tr=a(Vd,"A",{href:!0});var Nv=d(tr);Au=n(Nv,"TFPreTrainedModel"),Nv.forEach(t),Mu=n(Vd,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Vd.forEach(t),Gu=h(K),Oo=a(K,"P",{});var Yd=d(Oo);Pu=n(Yd,"This model is also a Tensorflow "),Co=a(Yd,"A",{href:!0,rel:!0});var Ov=d(Co);Nu=n(Ov,"tf.keras.Model"),Ov.forEach(t),Ou=n(Yd,`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),Yd.forEach(t),Cu=h(K),Xs=a(K,"P",{});var Cv=d(Xs);Lu=n(Cv,`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),Cv.forEach(t),Su=h(K),pe=a(K,"DIV",{class:!0});var St=d(pe);w(Lo.$$.fragment,St),Du=h(St),De=a(St,"P",{});var $r=d(De);Iu=n($r,"The "),or=a($r,"A",{href:!0});var Lv=d(or);Uu=n(Lv,"TFRagModel"),Lv.forEach(t),Hu=n($r," forward method, overrides the "),Zs=a($r,"CODE",{});var Sv=d(Zs);Wu=n(Sv,"__call__"),Sv.forEach(t),Bu=n($r," special method."),$r.forEach(t),Qu=h(St),w(qt.$$.fragment,St),Ku=h(St),w(xt.$$.fragment,St),St.forEach(t),K.forEach(t),vd=h(r),Ie=a(r,"H2",{class:!0});var Jd=d(Ie);Rt=a(Jd,"A",{id:!0,class:!0,href:!0});var Dv=d(Rt);ea=a(Dv,"SPAN",{});var Iv=d(ea);w(So.$$.fragment,Iv),Iv.forEach(t),Dv.forEach(t),Vu=h(Jd),ta=a(Jd,"SPAN",{});var Uv=d(ta);Yu=n(Uv,"TFRagSequenceForGeneration"),Uv.forEach(t),Jd.forEach(t),bd=h(r),$=a(r,"DIV",{class:!0});var O=d($);w(Do.$$.fragment,O),Ju=h(O),Ue=a(O,"P",{});var zr=d(Ue);Xu=n(zr,"The "),nr=a(zr,"A",{href:!0});var Hv=d(nr);Zu=n(Hv,"TFRagSequenceForGeneration"),Hv.forEach(t),em=n(zr," forward method, overrides the "),oa=a(zr,"CODE",{});var Wv=d(oa);tm=n(Wv,"__call__"),Wv.forEach(t),om=n(zr," special method."),zr.forEach(t),nm=h(O),w(Ft.$$.fragment,O),rm=h(O),na=a(O,"P",{});var Bv=d(na);sm=n(Bv,"A TF RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass."),Bv.forEach(t),am=h(O),ra=a(O,"P",{});var Qv=d(ra);dm=n(Qv,`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),Qv.forEach(t),im=h(O),se=a(O,"P",{});var we=d(se);cm=n(we,"The question encoder can be any "),sa=a(we,"EM",{});var Kv=d(sa);lm=n(Kv,"autoencoding"),Kv.forEach(t),pm=n(we," model, preferably "),rr=a(we,"A",{href:!0});var Vv=d(rr);hm=n(Vv,"TFDPRQuestionEncoder"),Vv.forEach(t),um=n(we,`, and the generator can be
any `),aa=a(we,"EM",{});var Yv=d(aa);mm=n(Yv,"seq2seq"),Yv.forEach(t),gm=n(we," model, preferably "),sr=a(we,"A",{href:!0});var Jv=d(sr);_m=n(Jv,"TFBartForConditionalGeneration"),Jv.forEach(t),fm=n(we,"."),we.forEach(t),vm=h(O),D=a(O,"P",{});var Y=d(D);bm=n(Y,"The model can be initialized with a "),ar=a(Y,"A",{href:!0});var Xv=d(ar);Tm=n(Xv,"RagRetriever"),Xv.forEach(t),wm=n(Y,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),da=a(Y,"EM",{});var Zv=d(da);ym=n(Zv,"autoencoding"),Zv.forEach(t),km=n(Y," model as the "),ia=a(Y,"CODE",{});var eb=d(ia);qm=n(eb,"question_encoder"),eb.forEach(t),xm=n(Y," and any "),ca=a(Y,"EM",{});var tb=d(ca);Rm=n(tb,"seq2seq"),tb.forEach(t),Fm=n(Y," model with language model head as the "),la=a(Y,"CODE",{});var ob=d(la);$m=n(ob,"generator"),ob.forEach(t),zm=n(Y,`.
It has been tested with `),dr=a(Y,"A",{href:!0});var nb=d(dr);Em=n(nb,"TFDPRQuestionEncoder"),nb.forEach(t),jm=n(Y," as the "),pa=a(Y,"CODE",{});var rb=d(pa);Am=n(rb,"question_encoder"),rb.forEach(t),Mm=n(Y," and "),ir=a(Y,"A",{href:!0});var sb=d(ir);Gm=n(sb,"TFBartForConditionalGeneration"),sb.forEach(t),Pm=n(Y,`
as the `),ha=a(Y,"CODE",{});var ab=d(ha);Nm=n(ab,"generator"),ab.forEach(t),Om=n(Y,"."),Y.forEach(t),Cm=h(O),Io=a(O,"P",{});var Xd=d(Io);Lm=n(Xd,"This model inherits from "),cr=a(Xd,"A",{href:!0});var db=d(cr);Sm=n(db,"TFPreTrainedModel"),db.forEach(t),Dm=n(Xd,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Xd.forEach(t),Im=h(O),Uo=a(O,"P",{});var Zd=d(Uo);Um=n(Zd,"This model is also a Tensorflow "),Ho=a(Zd,"A",{href:!0,rel:!0});var ib=d(Ho);Hm=n(ib,"tf.keras.Model"),ib.forEach(t),Wm=n(Zd,`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),Zd.forEach(t),Bm=h(O),ua=a(O,"P",{});var cb=d(ua);Qm=n(cb,`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),cb.forEach(t),Km=h(O),he=a(O,"DIV",{class:!0});var Dt=d(he);w(Wo.$$.fragment,Dt),Vm=h(Dt),He=a(Dt,"P",{});var Er=d(He);Ym=n(Er,"The "),lr=a(Er,"A",{href:!0});var lb=d(lr);Jm=n(lb,"TFRagSequenceForGeneration"),lb.forEach(t),Xm=n(Er," forward method, overrides the "),ma=a(Er,"CODE",{});var pb=d(ma);Zm=n(pb,"__call__"),pb.forEach(t),eg=n(Er," special method."),Er.forEach(t),tg=h(Dt),w($t.$$.fragment,Dt),og=h(Dt),w(zt.$$.fragment,Dt),Dt.forEach(t),ng=h(O),Et=a(O,"DIV",{class:!0});var ei=d(Et);w(Bo.$$.fragment,ei),rg=h(ei),Qo=a(ei,"P",{});var ti=d(Qo);sg=n(ti,"Implements RAG sequence \u201Cthorough\u201D decoding. Read the "),pr=a(ti,"A",{href:!0});var hb=d(pr);ag=n(hb,"generate()"),hb.forEach(t),dg=n(ti,"` documentation\nfor more information on how to set other generate input parameters"),ti.forEach(t),ei.forEach(t),O.forEach(t),Td=h(r),We=a(r,"H2",{class:!0});var oi=d(We);jt=a(oi,"A",{id:!0,class:!0,href:!0});var ub=d(jt);ga=a(ub,"SPAN",{});var mb=d(ga);w(Ko.$$.fragment,mb),mb.forEach(t),ub.forEach(t),ig=h(oi),_a=a(oi,"SPAN",{});var gb=d(_a);cg=n(gb,"TFRagTokenForGeneration"),gb.forEach(t),oi.forEach(t),wd=h(r),z=a(r,"DIV",{class:!0});var C=d(z);w(Vo.$$.fragment,C),lg=h(C),Be=a(C,"P",{});var jr=d(Be);pg=n(jr,"The "),hr=a(jr,"A",{href:!0});var _b=d(hr);hg=n(_b,"TFRagTokenForGeneration"),_b.forEach(t),ug=n(jr," forward method, overrides the "),fa=a(jr,"CODE",{});var fb=d(fa);mg=n(fb,"__call__"),fb.forEach(t),gg=n(jr," special method."),jr.forEach(t),_g=h(C),w(At.$$.fragment,C),fg=h(C),va=a(C,"P",{});var vb=d(va);vg=n(vb,"A TF RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass."),vb.forEach(t),bg=h(C),ba=a(C,"P",{});var bb=d(ba);Tg=n(bb,`RAG is a sequence-to-sequence model which encapsulates two core components: a question encoder and a generator.
During a forward pass, we encode the input with the question encoder and pass it to the retriever to extract
relevant context documents. The documents are then prepended to the input. Such contextualized inputs is passed to
the generator.`),bb.forEach(t),wg=h(C),ae=a(C,"P",{});var ye=d(ae);yg=n(ye,"The question encoder can be any "),Ta=a(ye,"EM",{});var Tb=d(Ta);kg=n(Tb,"autoencoding"),Tb.forEach(t),qg=n(ye," model, preferably "),ur=a(ye,"A",{href:!0});var wb=d(ur);xg=n(wb,"TFDPRQuestionEncoder"),wb.forEach(t),Rg=n(ye,`, and the generator can be
any `),wa=a(ye,"EM",{});var yb=d(wa);Fg=n(yb,"seq2seq"),yb.forEach(t),$g=n(ye," model, preferably "),mr=a(ye,"A",{href:!0});var kb=d(mr);zg=n(kb,"TFBartForConditionalGeneration"),kb.forEach(t),Eg=n(ye,"."),ye.forEach(t),jg=h(C),I=a(C,"P",{});var J=d(I);Ag=n(J,"The model can be initialized with a "),gr=a(J,"A",{href:!0});var qb=d(gr);Mg=n(qb,"RagRetriever"),qb.forEach(t),Gg=n(J,` for end-to-end generation or used in combination with the
outputs of a retriever in multiple steps---see examples for more details. The model is compatible any
`),ya=a(J,"EM",{});var xb=d(ya);Pg=n(xb,"autoencoding"),xb.forEach(t),Ng=n(J," model as the "),ka=a(J,"CODE",{});var Rb=d(ka);Og=n(Rb,"question_encoder"),Rb.forEach(t),Cg=n(J," and any "),qa=a(J,"EM",{});var Fb=d(qa);Lg=n(Fb,"seq2seq"),Fb.forEach(t),Sg=n(J," model with language model head as the "),xa=a(J,"CODE",{});var $b=d(xa);Dg=n($b,"generator"),$b.forEach(t),Ig=n(J,`.
It has been tested with `),_r=a(J,"A",{href:!0});var zb=d(_r);Ug=n(zb,"TFDPRQuestionEncoder"),zb.forEach(t),Hg=n(J," as the "),Ra=a(J,"CODE",{});var Eb=d(Ra);Wg=n(Eb,"question_encoder"),Eb.forEach(t),Bg=n(J," and "),fr=a(J,"A",{href:!0});var jb=d(fr);Qg=n(jb,"TFBartForConditionalGeneration"),jb.forEach(t),Kg=n(J,`
as the `),Fa=a(J,"CODE",{});var Ab=d(Fa);Vg=n(Ab,"generator"),Ab.forEach(t),Yg=n(J,"."),J.forEach(t),Jg=h(C),Yo=a(C,"P",{});var ni=d(Yo);Xg=n(ni,"This model inherits from "),vr=a(ni,"A",{href:!0});var Mb=d(vr);Zg=n(Mb,"TFPreTrainedModel"),Mb.forEach(t),e_=n(ni,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),ni.forEach(t),t_=h(C),Jo=a(C,"P",{});var ri=d(Jo);o_=n(ri,"This model is also a Tensorflow "),Xo=a(ri,"A",{href:!0,rel:!0});var Gb=d(Xo);n_=n(Gb,"tf.keras.Model"),Gb.forEach(t),r_=n(ri,`
subclass. Use it as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to
general usage and behavior.`),ri.forEach(t),s_=h(C),$a=a(C,"P",{});var Pb=d($a);a_=n(Pb,`The model is in a developing state as it is now fully supports in eager-mode only, and may not be exported in
SavedModel format.`),Pb.forEach(t),d_=h(C),ue=a(C,"DIV",{class:!0});var It=d(ue);w(Zo.$$.fragment,It),i_=h(It),Qe=a(It,"P",{});var Ar=d(Qe);c_=n(Ar,"The "),br=a(Ar,"A",{href:!0});var Nb=d(br);l_=n(Nb,"TFRagTokenForGeneration"),Nb.forEach(t),p_=n(Ar," forward method, overrides the "),za=a(Ar,"CODE",{});var Ob=d(za);h_=n(Ob,"__call__"),Ob.forEach(t),u_=n(Ar," special method."),Ar.forEach(t),m_=h(It),w(Mt.$$.fragment,It),g_=h(It),w(Gt.$$.fragment,It),It.forEach(t),__=h(C),Pt=a(C,"DIV",{class:!0});var si=d(Pt);w(en.$$.fragment,si),f_=h(si),Ea=a(si,"P",{});var Cb=d(Ea);v_=n(Cb,"Implements TFRAG token decoding."),Cb.forEach(t),si.forEach(t),C.forEach(t),this.h()},h(){l(c,"name","hf:doc:metadata"),l(c,"content",JSON.stringify(pT)),l(g,"id","rag"),l(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(g,"href","#rag"),l(m,"class","relative group"),l(ln,"alt","Models"),Ub(ln.src,b_="https://img.shields.io/badge/All_model_pages-rag-blueviolet")||l(ln,"src",b_),l(cn,"href","https://huggingface.co/models?filter=rag"),l(Ut,"class","flex flex-wrap space-x-1"),l(Ve,"id","overview"),l(Ve,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Ve,"href","#overview"),l(ke,"class","relative group"),l(Wt,"href","https://arxiv.org/abs/2005.11401"),l(Wt,"rel","nofollow"),l(Bt,"href","https://huggingface.co/ola13"),l(Bt,"rel","nofollow"),l(Xe,"id","transformers.RagConfig"),l(Xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Xe,"href","#transformers.RagConfig"),l(qe,"class","relative group"),l(_n,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagConfig"),l(fn,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),l(vn,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),l(bn,"href","/docs/transformers/v4.27.1/en/model_doc/encoder-decoder#transformers.EncoderDecoderConfig"),l(Ze,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Tn,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig.to_dict"),l(et,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ee,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(tt,"id","transformers.RagTokenizer"),l(tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(tt,"href","#transformers.RagTokenizer"),l(xe,"class","relative group"),l(eo,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ot,"id","transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"),l(ot,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ot,"href","#transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput"),l(Re,"class","relative group"),l(Fe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ro,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(nt,"id","transformers.RagRetriever"),l(nt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(nt,"href","#transformers.RagRetriever"),l($e,"class","relative group"),l(st,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(at,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(dt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(it,"id","transformers.RagModel"),l(it,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(it,"href","#transformers.RagModel"),l(Ee,"class","relative group"),l(wn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagModel"),l(yn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(kn,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(qn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(xn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(Rn,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(Fn,"href","/docs/transformers/v4.27.1/en/model_doc/t5#transformers.T5ForConditionalGeneration"),l($n,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),l(fo,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(fo,"rel","nofollow"),l(zn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagModel"),l(ie,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ht,"id","transformers.RagSequenceForGeneration"),l(ht,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ht,"href","#transformers.RagSequenceForGeneration"),l(Me,"class","relative group"),l(En,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagSequenceForGeneration"),l(jn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(An,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(Mn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(Gn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(Pn,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(Nn,"href","/docs/transformers/v4.27.1/en/model_doc/t5#transformers.T5ForConditionalGeneration"),l(On,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),l(ko,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(ko,"rel","nofollow"),l(Cn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagSequenceForGeneration"),l(ce,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Ln,"href","/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate"),l(_t,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ft,"id","transformers.RagTokenForGeneration"),l(ft,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ft,"href","#transformers.RagTokenForGeneration"),l(Ne,"class","relative group"),l(Sn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration"),l(Dn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(In,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(Un,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(Hn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.DPRQuestionEncoder"),l(Wn,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.BartForConditionalGeneration"),l(Bn,"href","/docs/transformers/v4.27.1/en/model_doc/t5#transformers.T5ForConditionalGeneration"),l(Qn,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),l(jo,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(jo,"rel","nofollow"),l(Kn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagTokenForGeneration"),l(le,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(wt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(yt,"id","transformers.TFRagModel"),l(yt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(yt,"href","#transformers.TFRagModel"),l(Le,"class","relative group"),l(Vn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagModel"),l(Yn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(Jn,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(Xn,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(Zn,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(er,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(tr,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel"),l(Co,"href","https://www.tensorflow.org/api_docs/python/tf/keras/Model"),l(Co,"rel","nofollow"),l(or,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagModel"),l(pe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Rt,"id","transformers.TFRagSequenceForGeneration"),l(Rt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Rt,"href","#transformers.TFRagSequenceForGeneration"),l(Ie,"class","relative group"),l(nr,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagSequenceForGeneration"),l(rr,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(sr,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(ar,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(dr,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(ir,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(cr,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel"),l(Ho,"href","https://www.tensorflow.org/api_docs/python/tf/keras/Model"),l(Ho,"rel","nofollow"),l(lr,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagSequenceForGeneration"),l(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(pr,"href","/docs/transformers/v4.27.1/en/main_classes/text_generation#transformers.GenerationMixin.generate"),l(Et,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(jt,"id","transformers.TFRagTokenForGeneration"),l(jt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(jt,"href","#transformers.TFRagTokenForGeneration"),l(We,"class","relative group"),l(hr,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagTokenForGeneration"),l(ur,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(mr,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(gr,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.RagRetriever"),l(_r,"href","/docs/transformers/v4.27.1/en/model_doc/dpr#transformers.TFDPRQuestionEncoder"),l(fr,"href","/docs/transformers/v4.27.1/en/model_doc/bart#transformers.TFBartForConditionalGeneration"),l(vr,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.TFPreTrainedModel"),l(Xo,"href","https://www.tensorflow.org/api_docs/python/tf/keras/Model"),l(Xo,"rel","nofollow"),l(br,"href","/docs/transformers/v4.27.1/en/model_doc/rag#transformers.TFRagTokenForGeneration"),l(ue,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Pt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(r,_){e(document.head,c),v(r,b,_),v(r,m,_),e(m,g),e(g,f),y(i,f,null),e(m,u),e(m,R),e(R,ai),v(r,Ba,_),v(r,Ut,_),e(Ut,cn),e(cn,ln),v(r,Qa,_),v(r,ke,_),e(ke,Ve),e(Ve,Mr),y(Ht,Mr,null),e(ke,di),e(ke,Gr),e(Gr,ii),v(r,Ka,_),v(r,pn,_),e(pn,ci),v(r,Va,_),v(r,Ye,_),e(Ye,li),e(Ye,Wt),e(Wt,pi),e(Ye,hi),v(r,Ya,_),v(r,hn,_),e(hn,ui),v(r,Ja,_),v(r,un,_),e(un,Pr),e(Pr,mi),v(r,Xa,_),v(r,Je,_),e(Je,gi),e(Je,Bt),e(Bt,_i),e(Je,fi),v(r,Za,_),v(r,mn,_),e(mn,vi),v(r,ed,_),v(r,gn,_),e(gn,Nr),e(Nr,bi),v(r,td,_),v(r,qe,_),e(qe,Xe),e(Xe,Or),y(Qt,Or,null),e(qe,Ti),e(qe,Cr),e(Cr,wi),v(r,od,_),v(r,ee,_),y(Kt,ee,null),e(ee,yi),e(ee,de),e(de,_n),e(_n,ki),e(de,qi),e(de,Lr),e(Lr,xi),e(de,Ri),e(de,fn),e(fn,Fi),e(de,$i),e(de,vn),e(vn,zi),e(de,Ei),e(ee,ji),e(ee,Ze),y(Vt,Ze,null),e(Ze,Ai),e(Ze,Yt),e(Yt,Mi),e(Yt,bn),e(bn,Gi),e(Yt,Pi),e(ee,Ni),e(ee,et),y(Jt,et,null),e(et,Oi),e(et,Xt),e(Xt,Ci),e(Xt,Tn),e(Tn,Li),e(Xt,Si),v(r,nd,_),v(r,xe,_),e(xe,tt),e(tt,Sr),y(Zt,Sr,null),e(xe,Di),e(xe,Dr),e(Dr,Ii),v(r,rd,_),v(r,eo,_),y(to,eo,null),v(r,sd,_),v(r,Re,_),e(Re,ot),e(ot,Ir),y(oo,Ir,null),e(Re,Ui),e(Re,Ur),e(Ur,Hi),v(r,ad,_),v(r,Fe,_),y(no,Fe,null),e(Fe,Wi),e(Fe,Hr),e(Hr,Bi),v(r,dd,_),v(r,ro,_),y(so,ro,null),v(r,id,_),v(r,$e,_),e($e,nt),e(nt,Wr),y(ao,Wr,null),e($e,Qi),e($e,Br),e(Br,Ki),v(r,cd,_),v(r,Z,_),y(io,Z,null),e(Z,Vi),e(Z,Qr),e(Qr,Yi),e(Z,Ji),y(rt,Z,null),e(Z,Xi),e(Z,st),y(co,st,null),e(st,Zi),e(st,Kr),e(Kr,ec),e(Z,tc),e(Z,at),y(lo,at,null),e(at,oc),e(at,ze),e(ze,nc),e(ze,Vr),e(Vr,rc),e(ze,sc),e(ze,Yr),e(Yr,ac),e(ze,dc),e(Z,ic),e(Z,dt),y(po,dt,null),e(dt,cc),e(dt,ho),e(ho,lc),e(ho,Jr),e(Jr,pc),e(ho,hc),v(r,ld,_),v(r,Ee,_),e(Ee,it),e(it,Xr),y(uo,Xr,null),e(Ee,uc),e(Ee,Zr),e(Zr,mc),v(r,pd,_),v(r,L,_),y(mo,L,null),e(L,gc),e(L,je),e(je,_c),e(je,wn),e(wn,fc),e(je,vc),e(je,es),e(es,bc),e(je,Tc),e(L,wc),y(ct,L,null),e(L,yc),e(L,ts),e(ts,kc),e(L,qc),e(L,te),e(te,xc),e(te,os),e(os,Rc),e(te,Fc),e(te,yn),e(yn,$c),e(te,zc),e(te,ns),e(ns,Ec),e(te,jc),e(te,kn),e(kn,Ac),e(te,Mc),e(L,Gc),e(L,M),e(M,Pc),e(M,qn),e(qn,Nc),e(M,Oc),e(M,rs),e(rs,Cc),e(M,Lc),e(M,ss),e(ss,Sc),e(M,Dc),e(M,as),e(as,Ic),e(M,Uc),e(M,ds),e(ds,Hc),e(M,Wc),e(M,xn),e(xn,Bc),e(M,Qc),e(M,is),e(is,Kc),e(M,Vc),e(M,Rn),e(Rn,Yc),e(M,Jc),e(M,Fn),e(Fn,Xc),e(M,Zc),e(M,cs),e(cs,el),e(M,tl),e(L,ol),e(L,go),e(go,nl),e(go,$n),e($n,rl),e(go,sl),e(L,al),e(L,_o),e(_o,dl),e(_o,fo),e(fo,il),e(_o,cl),e(L,ll),e(L,ie),y(vo,ie,null),e(ie,pl),e(ie,Ae),e(Ae,hl),e(Ae,zn),e(zn,ul),e(Ae,ml),e(Ae,ls),e(ls,gl),e(Ae,_l),e(ie,fl),y(lt,ie,null),e(ie,vl),y(pt,ie,null),v(r,hd,_),v(r,Me,_),e(Me,ht),e(ht,ps),y(bo,ps,null),e(Me,bl),e(Me,hs),e(hs,Tl),v(r,ud,_),v(r,E,_),y(To,E,null),e(E,wl),e(E,Ge),e(Ge,yl),e(Ge,En),e(En,kl),e(Ge,ql),e(Ge,us),e(us,xl),e(Ge,Rl),e(E,Fl),y(ut,E,null),e(E,$l),e(E,ms),e(ms,zl),e(E,El),e(E,gs),e(gs,jl),e(E,Al),e(E,oe),e(oe,Ml),e(oe,_s),e(_s,Gl),e(oe,Pl),e(oe,jn),e(jn,Nl),e(oe,Ol),e(oe,fs),e(fs,Cl),e(oe,Ll),e(oe,An),e(An,Sl),e(oe,Dl),e(E,Il),e(E,G),e(G,Ul),e(G,Mn),e(Mn,Hl),e(G,Wl),e(G,vs),e(vs,Bl),e(G,Ql),e(G,bs),e(bs,Kl),e(G,Vl),e(G,Ts),e(Ts,Yl),e(G,Jl),e(G,ws),e(ws,Xl),e(G,Zl),e(G,Gn),e(Gn,ep),e(G,tp),e(G,ys),e(ys,op),e(G,np),e(G,Pn),e(Pn,rp),e(G,sp),e(G,Nn),e(Nn,ap),e(G,dp),e(G,ks),e(ks,ip),e(G,cp),e(E,lp),e(E,wo),e(wo,pp),e(wo,On),e(On,hp),e(wo,up),e(E,mp),e(E,yo),e(yo,gp),e(yo,ko),e(ko,_p),e(yo,fp),e(E,vp),e(E,ce),y(qo,ce,null),e(ce,bp),e(ce,Pe),e(Pe,Tp),e(Pe,Cn),e(Cn,wp),e(Pe,yp),e(Pe,qs),e(qs,kp),e(Pe,qp),e(ce,xp),y(mt,ce,null),e(ce,Rp),y(gt,ce,null),e(E,Fp),e(E,_t),y(xo,_t,null),e(_t,$p),e(_t,Ro),e(Ro,zp),e(Ro,Ln),e(Ln,Ep),e(Ro,jp),v(r,md,_),v(r,Ne,_),e(Ne,ft),e(ft,xs),y(Fo,xs,null),e(Ne,Ap),e(Ne,Rs),e(Rs,Mp),v(r,gd,_),v(r,j,_),y($o,j,null),e(j,Gp),e(j,Oe),e(Oe,Pp),e(Oe,Sn),e(Sn,Np),e(Oe,Op),e(Oe,Fs),e(Fs,Cp),e(Oe,Lp),e(j,Sp),y(vt,j,null),e(j,Dp),e(j,$s),e($s,Ip),e(j,Up),e(j,zs),e(zs,Hp),e(j,Wp),e(j,ne),e(ne,Bp),e(ne,Es),e(Es,Qp),e(ne,Kp),e(ne,Dn),e(Dn,Vp),e(ne,Yp),e(ne,js),e(js,Jp),e(ne,Xp),e(ne,In),e(In,Zp),e(ne,eh),e(j,th),e(j,P),e(P,oh),e(P,Un),e(Un,nh),e(P,rh),e(P,As),e(As,sh),e(P,ah),e(P,Ms),e(Ms,dh),e(P,ih),e(P,Gs),e(Gs,ch),e(P,lh),e(P,Ps),e(Ps,ph),e(P,hh),e(P,Hn),e(Hn,uh),e(P,mh),e(P,Ns),e(Ns,gh),e(P,_h),e(P,Wn),e(Wn,fh),e(P,vh),e(P,Bn),e(Bn,bh),e(P,Th),e(P,Os),e(Os,wh),e(P,yh),e(j,kh),e(j,zo),e(zo,qh),e(zo,Qn),e(Qn,xh),e(zo,Rh),e(j,Fh),e(j,Eo),e(Eo,$h),e(Eo,jo),e(jo,zh),e(Eo,Eh),e(j,jh),e(j,le),y(Ao,le,null),e(le,Ah),e(le,Ce),e(Ce,Mh),e(Ce,Kn),e(Kn,Gh),e(Ce,Ph),e(Ce,Cs),e(Cs,Nh),e(Ce,Oh),e(le,Ch),y(bt,le,null),e(le,Lh),y(Tt,le,null),e(j,Sh),e(j,wt),y(Mo,wt,null),e(wt,Dh),e(wt,Ls),e(Ls,Ih),v(r,_d,_),v(r,Le,_),e(Le,yt),e(yt,Ss),y(Go,Ss,null),e(Le,Uh),e(Le,Ds),e(Ds,Hh),v(r,fd,_),v(r,N,_),y(Po,N,null),e(N,Wh),e(N,Se),e(Se,Bh),e(Se,Vn),e(Vn,Qh),e(Se,Kh),e(Se,Is),e(Is,Vh),e(Se,Yh),e(N,Jh),y(kt,N,null),e(N,Xh),e(N,Us),e(Us,Zh),e(N,eu),e(N,re),e(re,tu),e(re,Hs),e(Hs,ou),e(re,nu),e(re,Yn),e(Yn,ru),e(re,su),e(re,Ws),e(Ws,au),e(re,du),e(re,Jn),e(Jn,iu),e(re,cu),e(N,lu),e(N,S),e(S,pu),e(S,Xn),e(Xn,hu),e(S,uu),e(S,Bs),e(Bs,mu),e(S,gu),e(S,Qs),e(Qs,_u),e(S,fu),e(S,Ks),e(Ks,vu),e(S,bu),e(S,Vs),e(Vs,Tu),e(S,wu),e(S,Zn),e(Zn,yu),e(S,ku),e(S,Ys),e(Ys,qu),e(S,xu),e(S,er),e(er,Ru),e(S,Fu),e(S,Js),e(Js,$u),e(S,zu),e(N,Eu),e(N,No),e(No,ju),e(No,tr),e(tr,Au),e(No,Mu),e(N,Gu),e(N,Oo),e(Oo,Pu),e(Oo,Co),e(Co,Nu),e(Oo,Ou),e(N,Cu),e(N,Xs),e(Xs,Lu),e(N,Su),e(N,pe),y(Lo,pe,null),e(pe,Du),e(pe,De),e(De,Iu),e(De,or),e(or,Uu),e(De,Hu),e(De,Zs),e(Zs,Wu),e(De,Bu),e(pe,Qu),y(qt,pe,null),e(pe,Ku),y(xt,pe,null),v(r,vd,_),v(r,Ie,_),e(Ie,Rt),e(Rt,ea),y(So,ea,null),e(Ie,Vu),e(Ie,ta),e(ta,Yu),v(r,bd,_),v(r,$,_),y(Do,$,null),e($,Ju),e($,Ue),e(Ue,Xu),e(Ue,nr),e(nr,Zu),e(Ue,em),e(Ue,oa),e(oa,tm),e(Ue,om),e($,nm),y(Ft,$,null),e($,rm),e($,na),e(na,sm),e($,am),e($,ra),e(ra,dm),e($,im),e($,se),e(se,cm),e(se,sa),e(sa,lm),e(se,pm),e(se,rr),e(rr,hm),e(se,um),e(se,aa),e(aa,mm),e(se,gm),e(se,sr),e(sr,_m),e(se,fm),e($,vm),e($,D),e(D,bm),e(D,ar),e(ar,Tm),e(D,wm),e(D,da),e(da,ym),e(D,km),e(D,ia),e(ia,qm),e(D,xm),e(D,ca),e(ca,Rm),e(D,Fm),e(D,la),e(la,$m),e(D,zm),e(D,dr),e(dr,Em),e(D,jm),e(D,pa),e(pa,Am),e(D,Mm),e(D,ir),e(ir,Gm),e(D,Pm),e(D,ha),e(ha,Nm),e(D,Om),e($,Cm),e($,Io),e(Io,Lm),e(Io,cr),e(cr,Sm),e(Io,Dm),e($,Im),e($,Uo),e(Uo,Um),e(Uo,Ho),e(Ho,Hm),e(Uo,Wm),e($,Bm),e($,ua),e(ua,Qm),e($,Km),e($,he),y(Wo,he,null),e(he,Vm),e(he,He),e(He,Ym),e(He,lr),e(lr,Jm),e(He,Xm),e(He,ma),e(ma,Zm),e(He,eg),e(he,tg),y($t,he,null),e(he,og),y(zt,he,null),e($,ng),e($,Et),y(Bo,Et,null),e(Et,rg),e(Et,Qo),e(Qo,sg),e(Qo,pr),e(pr,ag),e(Qo,dg),v(r,Td,_),v(r,We,_),e(We,jt),e(jt,ga),y(Ko,ga,null),e(We,ig),e(We,_a),e(_a,cg),v(r,wd,_),v(r,z,_),y(Vo,z,null),e(z,lg),e(z,Be),e(Be,pg),e(Be,hr),e(hr,hg),e(Be,ug),e(Be,fa),e(fa,mg),e(Be,gg),e(z,_g),y(At,z,null),e(z,fg),e(z,va),e(va,vg),e(z,bg),e(z,ba),e(ba,Tg),e(z,wg),e(z,ae),e(ae,yg),e(ae,Ta),e(Ta,kg),e(ae,qg),e(ae,ur),e(ur,xg),e(ae,Rg),e(ae,wa),e(wa,Fg),e(ae,$g),e(ae,mr),e(mr,zg),e(ae,Eg),e(z,jg),e(z,I),e(I,Ag),e(I,gr),e(gr,Mg),e(I,Gg),e(I,ya),e(ya,Pg),e(I,Ng),e(I,ka),e(ka,Og),e(I,Cg),e(I,qa),e(qa,Lg),e(I,Sg),e(I,xa),e(xa,Dg),e(I,Ig),e(I,_r),e(_r,Ug),e(I,Hg),e(I,Ra),e(Ra,Wg),e(I,Bg),e(I,fr),e(fr,Qg),e(I,Kg),e(I,Fa),e(Fa,Vg),e(I,Yg),e(z,Jg),e(z,Yo),e(Yo,Xg),e(Yo,vr),e(vr,Zg),e(Yo,e_),e(z,t_),e(z,Jo),e(Jo,o_),e(Jo,Xo),e(Xo,n_),e(Jo,r_),e(z,s_),e(z,$a),e($a,a_),e(z,d_),e(z,ue),y(Zo,ue,null),e(ue,i_),e(ue,Qe),e(Qe,c_),e(Qe,br),e(br,l_),e(Qe,p_),e(Qe,za),e(za,h_),e(Qe,u_),e(ue,m_),y(Mt,ue,null),e(ue,g_),y(Gt,ue,null),e(z,__),e(z,Pt),y(en,Pt,null),e(Pt,f_),e(Pt,Ea),e(Ea,v_),yd=!0},p(r,[_]){const tn={};_&2&&(tn.$$scope={dirty:_,ctx:r}),rt.$set(tn);const ja={};_&2&&(ja.$$scope={dirty:_,ctx:r}),ct.$set(ja);const Aa={};_&2&&(Aa.$$scope={dirty:_,ctx:r}),lt.$set(Aa);const Ma={};_&2&&(Ma.$$scope={dirty:_,ctx:r}),pt.$set(Ma);const Ga={};_&2&&(Ga.$$scope={dirty:_,ctx:r}),ut.$set(Ga);const Pa={};_&2&&(Pa.$$scope={dirty:_,ctx:r}),mt.$set(Pa);const on={};_&2&&(on.$$scope={dirty:_,ctx:r}),gt.$set(on);const Na={};_&2&&(Na.$$scope={dirty:_,ctx:r}),vt.$set(Na);const Oa={};_&2&&(Oa.$$scope={dirty:_,ctx:r}),bt.$set(Oa);const Ca={};_&2&&(Ca.$$scope={dirty:_,ctx:r}),Tt.$set(Ca);const La={};_&2&&(La.$$scope={dirty:_,ctx:r}),kt.$set(La);const nn={};_&2&&(nn.$$scope={dirty:_,ctx:r}),qt.$set(nn);const Sa={};_&2&&(Sa.$$scope={dirty:_,ctx:r}),xt.$set(Sa);const Da={};_&2&&(Da.$$scope={dirty:_,ctx:r}),Ft.$set(Da);const Ia={};_&2&&(Ia.$$scope={dirty:_,ctx:r}),$t.$set(Ia);const Ua={};_&2&&(Ua.$$scope={dirty:_,ctx:r}),zt.$set(Ua);const rn={};_&2&&(rn.$$scope={dirty:_,ctx:r}),At.$set(rn);const Ha={};_&2&&(Ha.$$scope={dirty:_,ctx:r}),Mt.$set(Ha);const Wa={};_&2&&(Wa.$$scope={dirty:_,ctx:r}),Gt.$set(Wa)},i(r){yd||(k(i.$$.fragment,r),k(Ht.$$.fragment,r),k(Qt.$$.fragment,r),k(Kt.$$.fragment,r),k(Vt.$$.fragment,r),k(Jt.$$.fragment,r),k(Zt.$$.fragment,r),k(to.$$.fragment,r),k(oo.$$.fragment,r),k(no.$$.fragment,r),k(so.$$.fragment,r),k(ao.$$.fragment,r),k(io.$$.fragment,r),k(rt.$$.fragment,r),k(co.$$.fragment,r),k(lo.$$.fragment,r),k(po.$$.fragment,r),k(uo.$$.fragment,r),k(mo.$$.fragment,r),k(ct.$$.fragment,r),k(vo.$$.fragment,r),k(lt.$$.fragment,r),k(pt.$$.fragment,r),k(bo.$$.fragment,r),k(To.$$.fragment,r),k(ut.$$.fragment,r),k(qo.$$.fragment,r),k(mt.$$.fragment,r),k(gt.$$.fragment,r),k(xo.$$.fragment,r),k(Fo.$$.fragment,r),k($o.$$.fragment,r),k(vt.$$.fragment,r),k(Ao.$$.fragment,r),k(bt.$$.fragment,r),k(Tt.$$.fragment,r),k(Mo.$$.fragment,r),k(Go.$$.fragment,r),k(Po.$$.fragment,r),k(kt.$$.fragment,r),k(Lo.$$.fragment,r),k(qt.$$.fragment,r),k(xt.$$.fragment,r),k(So.$$.fragment,r),k(Do.$$.fragment,r),k(Ft.$$.fragment,r),k(Wo.$$.fragment,r),k($t.$$.fragment,r),k(zt.$$.fragment,r),k(Bo.$$.fragment,r),k(Ko.$$.fragment,r),k(Vo.$$.fragment,r),k(At.$$.fragment,r),k(Zo.$$.fragment,r),k(Mt.$$.fragment,r),k(Gt.$$.fragment,r),k(en.$$.fragment,r),yd=!0)},o(r){q(i.$$.fragment,r),q(Ht.$$.fragment,r),q(Qt.$$.fragment,r),q(Kt.$$.fragment,r),q(Vt.$$.fragment,r),q(Jt.$$.fragment,r),q(Zt.$$.fragment,r),q(to.$$.fragment,r),q(oo.$$.fragment,r),q(no.$$.fragment,r),q(so.$$.fragment,r),q(ao.$$.fragment,r),q(io.$$.fragment,r),q(rt.$$.fragment,r),q(co.$$.fragment,r),q(lo.$$.fragment,r),q(po.$$.fragment,r),q(uo.$$.fragment,r),q(mo.$$.fragment,r),q(ct.$$.fragment,r),q(vo.$$.fragment,r),q(lt.$$.fragment,r),q(pt.$$.fragment,r),q(bo.$$.fragment,r),q(To.$$.fragment,r),q(ut.$$.fragment,r),q(qo.$$.fragment,r),q(mt.$$.fragment,r),q(gt.$$.fragment,r),q(xo.$$.fragment,r),q(Fo.$$.fragment,r),q($o.$$.fragment,r),q(vt.$$.fragment,r),q(Ao.$$.fragment,r),q(bt.$$.fragment,r),q(Tt.$$.fragment,r),q(Mo.$$.fragment,r),q(Go.$$.fragment,r),q(Po.$$.fragment,r),q(kt.$$.fragment,r),q(Lo.$$.fragment,r),q(qt.$$.fragment,r),q(xt.$$.fragment,r),q(So.$$.fragment,r),q(Do.$$.fragment,r),q(Ft.$$.fragment,r),q(Wo.$$.fragment,r),q($t.$$.fragment,r),q(zt.$$.fragment,r),q(Bo.$$.fragment,r),q(Ko.$$.fragment,r),q(Vo.$$.fragment,r),q(At.$$.fragment,r),q(Zo.$$.fragment,r),q(Mt.$$.fragment,r),q(Gt.$$.fragment,r),q(en.$$.fragment,r),yd=!1},d(r){t(c),r&&t(b),r&&t(m),x(i),r&&t(Ba),r&&t(Ut),r&&t(Qa),r&&t(ke),x(Ht),r&&t(Ka),r&&t(pn),r&&t(Va),r&&t(Ye),r&&t(Ya),r&&t(hn),r&&t(Ja),r&&t(un),r&&t(Xa),r&&t(Je),r&&t(Za),r&&t(mn),r&&t(ed),r&&t(gn),r&&t(td),r&&t(qe),x(Qt),r&&t(od),r&&t(ee),x(Kt),x(Vt),x(Jt),r&&t(nd),r&&t(xe),x(Zt),r&&t(rd),r&&t(eo),x(to),r&&t(sd),r&&t(Re),x(oo),r&&t(ad),r&&t(Fe),x(no),r&&t(dd),r&&t(ro),x(so),r&&t(id),r&&t($e),x(ao),r&&t(cd),r&&t(Z),x(io),x(rt),x(co),x(lo),x(po),r&&t(ld),r&&t(Ee),x(uo),r&&t(pd),r&&t(L),x(mo),x(ct),x(vo),x(lt),x(pt),r&&t(hd),r&&t(Me),x(bo),r&&t(ud),r&&t(E),x(To),x(ut),x(qo),x(mt),x(gt),x(xo),r&&t(md),r&&t(Ne),x(Fo),r&&t(gd),r&&t(j),x($o),x(vt),x(Ao),x(bt),x(Tt),x(Mo),r&&t(_d),r&&t(Le),x(Go),r&&t(fd),r&&t(N),x(Po),x(kt),x(Lo),x(qt),x(xt),r&&t(vd),r&&t(Ie),x(So),r&&t(bd),r&&t($),x(Do),x(Ft),x(Wo),x($t),x(zt),x(Bo),r&&t(Td),r&&t(We),x(Ko),r&&t(wd),r&&t(z),x(Vo),x(At),x(Zo),x(Mt),x(Gt),x(en)}}}const pT={local:"rag",sections:[{local:"overview",title:"Overview"},{local:"transformers.RagConfig",title:"RagConfig"},{local:"transformers.RagTokenizer",title:"RagTokenizer"},{local:"transformers.models.rag.modeling_rag.RetrievAugLMMarginOutput",title:"Rag specific outputs"},{local:"transformers.RagRetriever",title:"RagRetriever"},{local:"transformers.RagModel",title:"RagModel"},{local:"transformers.RagSequenceForGeneration",title:"RagSequenceForGeneration"},{local:"transformers.RagTokenForGeneration",title:"RagTokenForGeneration"},{local:"transformers.TFRagModel",title:"TFRagModel"},{local:"transformers.TFRagSequenceForGeneration",title:"TFRagSequenceForGeneration"},{local:"transformers.TFRagTokenForGeneration",title:"TFRagTokenForGeneration"}],title:"RAG"};function hT(F){return Hb(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class bT extends Lb{constructor(c){super();Sb(this,c,hT,lT,Db,{})}}export{bT as default,pT as metadata};
