0
0
Prompt Engineering / GenAIml~10 mins

RAG architecture overview in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main components of a RAG model.

Prompt Engineering / GenAI
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration

tokenizer = RagTokenizer.from_pretrained('facebook/rag-token-nq')
retriever = RagRetriever.from_pretrained('facebook/rag-token-nq')
model = RagSequenceForGeneration.from_pretrained('facebook/rag-token-nq', retriever=[1])
Drag options to blanks, or click blank then click option'
Aretriever
BNone
Cmodel
Dtokenizer
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the tokenizer instead of the retriever to the model.
Passing None or forgetting to pass the retriever.
2fill in blank
medium

Complete the code to tokenize the input question for the RAG model.

Prompt Engineering / GenAI
question = "What is RAG architecture?"
inputs = tokenizer(question, return_tensors=[1])
Drag options to blanks, or click blank then click option'
Anp
Btf
Cpt
Dpd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tf' which returns TensorFlow tensors instead of PyTorch tensors.
Using unsupported return_tensors values like 'np' or 'pd'.
3fill in blank
hard

Fix the error in generating answers with the RAG model.

Prompt Engineering / GenAI
outputs = model.generate(input_ids=inputs['input_ids'], [1]=inputs['attention_mask'])
Drag options to blanks, or click blank then click option'
Ainput_mask
Battention_mask
Cmask
Dattn_mask
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect argument names like 'mask' or 'input_mask' causes errors.
Omitting the attention mask leads to wrong model behavior.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps retrieved document titles to their scores.

Prompt Engineering / GenAI
doc_scores = {doc['title']: doc[1] for doc in retrieved_docs if doc[1] [2] 0.5}
Drag options to blanks, or click blank then click option'
A['score']
B>
C<
D['id']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'id' instead of 'score'.
Using incorrect comparison operators like '<' instead of '>'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps document IDs to their text if the text length is greater than 100.

Prompt Engineering / GenAI
filtered_docs = {doc[1]: doc[2] for doc in docs if len(doc[3]) > 100}
Drag options to blanks, or click blank then click option'
A['id']
B['text']
D['title']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'title' instead of 'text' or 'id'.
Not using len() to check text length.