|
|
|
dataset = load_dataset("hotpot_qa", "distractor") |
|
|
|
|
|
dataset = load_dataset("nq") |
|
|
|
|
|
dataset = load_dataset("quoref") |
|
|
|
from datasets import load_dataset |
|
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline |
|
|
|
|
|
dataset = load_dataset("hotpot_qa", "distractor") |
|
|
|
|
|
example = dataset['train'][0] |
|
context = example['context'] |
|
question = example['question'] |
|
answer = example['answer'] |
|
|
|
|
|
print(f"Question: {question}") |
|
print(f"Context: {context}") |
|
print(f"Answer: {answer}") |
|
|
|
|
|
model_name = "google/mT5-small" |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForQuestionAnswering.from_pretrained(model_name) |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer) |
|
|
|
|
|
result = qa_pipeline(question=question, context=context) |
|
|
|
|
|
print(f"Predicted Answer: {result['answer']}") |
|
|
|
|
|
|
|
examples = [ |
|
{ |
|
"context": "The capital of France is Paris.", |
|
"question": "What is the capital of France?", |
|
"answer": "Paris" |
|
}, |
|
{ |
|
"context": "The tallest mountain in the world is Mount Everest.", |
|
"question": "What is the tallest mountain in the world?", |
|
"answer": "Mount Everest" |
|
}, |
|
{ |
|
"context": "Python is a programming language that lets you work quickly and integrate systems more effectively.", |
|
"question": "What is Python?", |
|
"answer": "A programming language" |
|
}, |
|
{ |
|
"context": "Reader PocketBook", |
|
"question": "How on PocketBook?", |
|
} |
|
] |
|
|
|
|
|
for example in examples: |
|
result = qa_pipeline(question=example["question"], context=example["context"]) |
|
print(f"Question: {example['question']}") |
|
print(f"Context: {example['context']}") |
|
print(f"Answer: {example['answer']}") |
|
print(f"Predicted Answer: {result['answer']}") |
|
print() |
|
|
|
|