Complete the code to import the RAG model class from transformers.
from transformers import [1]
The RagModel class is the core RAG model that combines retrieval and generation.
Complete the code to initialize the retriever for RAG using a dataset.
retriever = RagRetriever.from_pretrained('facebook/rag-token-base', index_name=[1])
The exact index_name tells the retriever to use exact matching for retrieval.
Fix the error in the code to generate an answer grounded on retrieved documents.
outputs = model.generate(input_ids, context_doc_ids=[1])The context_doc_ids argument expects the IDs of retrieved documents, not the raw documents or embeddings.
Fill both blanks to create a RAG model with retriever and generate output.
model = RagSequenceForGeneration.from_pretrained('facebook/rag-token-base', retriever=[1]) outputs = model.generate([2])
The model needs the retriever object to fetch documents, and input_ids to generate answers.
Fill all three blanks to tokenize input, retrieve docs, and generate grounded output.
inputs = tokenizer([1], return_tensors='pt') retrieved_docs = retriever.retrieve([2]) outputs = model.generate(input_ids=inputs['input_ids'], context_doc_ids=[3])
First, we tokenize the question string. Then we retrieve documents using the token IDs. Finally, we generate output using input IDs and retrieved document IDs.