![]() |
VOOZH | about |
Using models from Hugging Face for question answering allows developers to build systems that can automatically extract answers from a given context. These pre-trained transformer models make it easy to implement NLP applications such as chatbots, document search and knowledge‑based QA systems..
pip install transformers torch
Import the pipeline from Transformers, as it provides a high-level interface that automatically manages tokenisation, model loading, inference and output formatting in a single streamlined workflow.
Initialise the question answering pipeline by specifying the task and loading a pre-trained model (distilbert-base-cased-distilled-squad), which is already fine-tuned on the SQuAD dataset for answering questions from text.
Output:
Create a context and a question. The model searches the context to find the answer. Before answering, it performs tokenization:
Pass the question and context into the pipeline to generate the answer. Internally, the model:
Output:
{'score': 0.2661724090576172, 'start': 42, 'end': 114, 'answer': 'a wealth of resources for computer science enthusiasts and professionals'}
You can download the full code from here