|
from transformers import pipeline |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model='Jahanzeb1/BERT_QA_model', tokenizer='Jahanzeb1/BERT_QA_model') |
|
|
|
|
|
question = "How did he die?" |
|
context = "Ernest Shackleton (15 February 1874 – 5 January 1922) led three British expeditions to the Antarctic during the Heroic Age of Antarctic Exploration. He and three companions established a new record Farthest South latitude, 112 miles (180 km) from the South Pole, as part of the Nimrod Expedition of 1907–1909, and Shackleton was knighted on his return home. He planned the Imperial Trans-Antarctic Expedition of 1914–1917 but his ship, Endurance, became trapped in pack ice and then sank on 21 November 1915. The crew escaped and used the lifeboats to reach Elephant Island and ultimately the island of South Georgia in a stormy ocean voyage of more than 700 nautical miles (800 mi; 1,300 km), Shackleton's most famous exploit. He returned to the Antarctic in 1921 with the Shackleton–Rowett Expedition, but died of a heart attack on South Georgia; at his wife's request, he was buried there. In the latter part of the 20th century, Shackleton became a role model for leadership in extreme circumstance. Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span, from the corresponding reading passage, or the question might be unanswerable." |
|
answer = qa_pipeline(question=question, context=context) |
|
|
|
print("Question:", question) |
|
print("Answer:", answer["answer"]) |
|
|
|
import gradio as gr |
|
|
|
def answer_question(context, question): |
|
|
|
answer = qa_pipeline(question=question, context=context) |
|
return answer['answer'] |
|
|
|
|
|
interface = gr.Interface(fn=answer_question, |
|
inputs=["text", "text"], |
|
outputs="text", |
|
title="Question Answering with BERT", |
|
description="Enter a context and a question to get the answer.", |
|
) |
|
interface.launch() |
|
|