0
0
Prompt Engineering / GenAIml~10 mins

Question answering 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 load a pre-trained question answering model using Hugging Face Transformers.

Prompt Engineering / GenAI
from transformers import pipeline
qa_pipeline = pipeline('[1]')
Drag options to blanks, or click blank then click option'
Atext-generation
Bsentiment-analysis
Cquestion-answering
Dtranslation
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text-generation' instead of 'question-answering'.
Forgetting to import the pipeline function.
2fill in blank
medium

Complete the code to get the answer from the question answering pipeline.

Prompt Engineering / GenAI
context = "The Eiffel Tower is in Paris."
question = "Where is the Eiffel Tower located?"
result = qa_pipeline({'question': question, 'context': [1])
Drag options to blanks, or click blank then click option'
Aanswer
Bquestion
Cresult
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the question as context.
Passing the result variable instead of context.
3fill in blank
hard

Fix the error in extracting the answer text from the result dictionary.

Prompt Engineering / GenAI
answer_text = result[[1]]
Drag options to blanks, or click blank then click option'
A'answer'
B'text'
C'output'
D'result'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' or 'output' instead of 'answer'.
Using a variable name instead of a string key.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters answers longer than 5 characters.

Prompt Engineering / GenAI
filtered_answers = {q: a for q, a in answers.items() if len(a) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B5
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'.
Using '==' which filters only answers of length exactly 5.
5fill in blank
hard

Fill all three blanks to create a function that returns the answer from the QA pipeline given question and context.

Prompt Engineering / GenAI
def get_answer([1], [2]):
    result = qa_pipeline({'question': [1], 'context': [2])
    return result[[3]]
Drag options to blanks, or click blank then click option'
Aquestion
Bcontext
C'answer'
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up parameter names.
Returning the whole result instead of the answer string.