Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pipeline type like "text-generation" or "sentiment-analysis".
✗ Incorrect
The pipeline type for question answering is "question-answering".
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Asking questions unrelated to the context, which leads to wrong answers.
✗ Incorrect
The question should relate to the context. "What is Hugging Face?" fits the context about Hugging Face.
3fill in blank
hardFix the error in accessing the answer from the result dictionary.
NLP
print(result[[1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys like "result" or "text" which do not exist in the output.
✗ Incorrect
The QA pipeline returns a dictionary with the key "answer" containing the predicted answer.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for model and tokenizer causing errors.
Choosing models not trained for QA like "gpt2".
✗ Incorrect
The model and tokenizer names must match. "distilbert-base-uncased-distilled-squad" is a common QA model and tokenizer.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like "end" instead of "start" for the start position.
✗ Incorrect
The result dictionary keys are "answer" for the text, "score" for confidence, and "start" for the answer start index.