0
0
NLPml~10 mins

QA with Hugging Face pipeline 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 create a question answering pipeline using Hugging Face.

NLP
from transformers import pipeline
qa_pipeline = pipeline([1])
Drag options to blanks, or click blank then click option'
A"question-answering"
B"translation"
C"sentiment-analysis"
D"text-generation"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pipeline type like "text-generation" or "sentiment-analysis".
2fill in blank
medium

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

NLP
result = qa_pipeline({"question": [1], "context": "Hugging Face makes machine learning easy."})
Drag options to blanks, or click blank then click option'
A'Where is the moon?'
B'How to train a model?'
C'What is Python?'
D'What is Hugging Face?'
Attempts:
3 left
💡 Hint
Common Mistakes
Asking questions unrelated to the context, which leads to wrong answers.
3fill in blank
hard

Fix the error in accessing the answer from the result dictionary.

NLP
print(result[[1]])
Drag options to blanks, or click blank then click option'
A"text"
B"answer"
C"output"
D"result"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys like "result" or "text" which do not exist in the output.
4fill in blank
hard

Fill both blanks to create a QA pipeline with a specific model and tokenizer.

NLP
qa_pipeline = pipeline("question-answering", model=[1], tokenizer=[2])
Drag options to blanks, or click blank then click option'
A"distilbert-base-uncased-distilled-squad"
B"bert-base-uncased"
C"gpt2"
D"roberta-base"
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for model and tokenizer causing errors.
Choosing models not trained for QA like "gpt2".
5fill in blank
hard

Fill all three blanks to extract the answer, score, and start position from the QA result.

NLP
answer = result[[1]]
score = result[[2]]
start = result[[3]]
Drag options to blanks, or click blank then click option'
A"answer"
B"score"
C"start"
D"end"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like "end" instead of "start" for the start position.