Question-Answering

Beginner Explanation

Imagine you have a super smart friend who knows a lot about everything. When you ask them a question, they think for a moment and then give you a clear answer. Question-answering is like that, but instead of a person, it’s a computer program that can read and understand questions in everyday language. It looks for the right information in its ‘brain’ (which is filled with data) and then gives you the answer. So, if you ask, ‘What is the capital of France?’, it quickly finds ‘Paris’ and tells you!

Technical Explanation

Question-answering (QA) systems can be categorized into two main types: extractive and generative. Extractive QA systems identify and extract answers from a given context, while generative systems create answers based on learned knowledge. A common framework for building a QA system is using transformer models like BERT or T5. For example, with BERT, you can fine-tune it on a QA dataset. Here’s a simple code snippet using Hugging Face’s Transformers library: “`python from transformers import BertForQuestionAnswering, BertTokenizer import torch tokenizer = BertTokenizer.from_pretrained(‘bert-base-uncased’) model = BertForQuestionAnswering.from_pretrained(‘bert-base-uncased’) question = “What is the capital of France?” context = “France is a country in Europe. Its capital is Paris.” inputs = tokenizer.encode_plus(question, context, return_tensors=’pt’) start_scores, end_scores = model(**inputs) start_index = torch.argmax(start_scores) end_index = torch.argmax(end_scores) answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs[‘input_ids’][0][start_index:end_index + 1])) print(answer) # Output: Paris “`

Academic Context

Question-answering (QA) has been a significant area of research in Natural Language Processing (NLP). Key approaches include rule-based systems, information retrieval, and deep learning techniques. The advent of transformer architectures, such as BERT (Bidirectional Encoder Representations from Transformers) and T5 (Text-to-Text Transfer Transformer), has revolutionized the field. BERT, introduced by Devlin et al. (2018), utilizes a bidirectional training approach that improves context understanding. T5, proposed by Raffel et al. (2019), frames every NLP task as a text-to-text problem, enhancing flexibility. These models are often trained on large datasets like SQuAD (Stanford Question Answering Dataset), which has become a benchmark for evaluating QA systems.

Code Examples

Example 1:

from transformers import BertForQuestionAnswering, BertTokenizer
import torch

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForQuestionAnswering.from_pretrained('bert-base-uncased')

question = "What is the capital of France?"
context = "France is a country in Europe. Its capital is Paris."
inputs = tokenizer.encode_plus(question, context, return_tensors='pt')
start_scores, end_scores = model(**inputs)
start_index = torch.argmax(start_scores)
end_index = torch.argmax(end_scores)
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs['input_ids'][0][start_index:end_index + 1]))
print(answer)  # Output: Paris

Example 2:

from transformers import BertForQuestionAnswering, BertTokenizer
import torch

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForQuestionAnswering.from_pretrained('bert-base-uncased')

Example 3:

import torch

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForQuestionAnswering.from_pretrained('bert-base-uncased')

View Source: https://arxiv.org/abs/2511.16654v1

Pre-trained Models

Relevant Datasets

External References

Hf dataset: 10 Hf model: 10 Implementations: 0