Answering questions from a short text passage
To get started with question answering, we will start with a simple recipe that can answer a question from a short passage.
Getting ready
As part of this chapter, we will use the libraries from Hugging Face (huggingface.co). For this recipe, we will use the BertForQuestionAnswering
and BertTokenizer
modules from the Transformers package. The BertForQuestionAnswering
model uses the base BERT large uncased model that was trained on the SQuAD
dataset and fine-tuned for the question-answering task. This pre-trained model can be used to load a text passage and answer questions based on the contents of the passage. You can use the 9.1_question_answering.ipynb
notebook from the code site if you need to work from an existing notebook.
How to do it...
In this recipe, we will load a pretrained model that has been trained on the SQuAD dataset (https://huggingface.co/datasets/squad).
The recipe does the following things:
- It initializes...