0
0
NLPml~10 mins

Extractive QA concept in NLP - 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 extractive QA model from Hugging Face.

NLP
from transformers import pipeline
qa_pipeline = pipeline('question-answering', model=[1])
Drag options to blanks, or click blank then click option'
A'distilbert-base-uncased-distilled-squad'
B'roberta-base'
C'gpt2'
D'bert-base-uncased'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a language model not fine-tuned for QA like 'gpt2'.
Using a base model without QA fine-tuning.
2fill in blank
medium

Complete the code to provide context and question to the QA pipeline and get the answer.

NLP
result = qa_pipeline({'question': [1], 'context': context_text})
Drag options to blanks, or click blank then click option'
A'answer'
Bcontext_text
C'context'
D'What is extractive QA?'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the context as the question.
Using incorrect keys in the input dictionary.
3fill in blank
hard

Fix the error in accessing the answer text from the QA pipeline output.

NLP
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 'result' keys which do not exist in the output.
Trying to access the answer as an attribute instead of a dictionary key.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each question to its answer using the QA pipeline.

NLP
answers = {q: qa_pipeline({'question': q, 'context': [1])[2] for q in questions}
Drag options to blanks, or click blank then click option'
Acontext_text
B['answer']
C['text']
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for context.
Accessing the answer with incorrect keys like ['text'].
5fill in blank
hard

Fill all three blanks to define a function that takes a question and context, runs the QA pipeline, and returns the answer text.

NLP
def answer_question([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
Mismatching parameter names and dictionary keys.
Returning the whole result dictionary instead of just the answer.