In [ ]:
!pip install simpletransformers
In [ ]:
from simpletransformers.question_answering import QuestionAnsweringModel, QuestionAnsweringArgs
model = QuestionAnsweringModel(model_name="bert-large-uncased-whole-word-masking-finetuned-squad",model_type="bert")
In [ ]:
context_text = "After being relatively inactive since 2014, the Hunga Tonga volcano erupted on 20 December 2021, sending particulates into the stratosphere.
A large plume of ash was visible from Nukuʻalofa, the capital city of Tonga, about 70 km (45 mi) from the volcano. The Volcanic Ash Advisory Center (VAAC) in Wellington, New Zealand, issued an advisory notice to airlines.
The eruption was heard more than 2,000 kilometres (1,200 mi) away in New Zealand, where the sound arrived two hours later.
This initial eruption ended at 02:00 on 21 December 2021. Volcanic activity continued, and on 25 December 2021, the island had increased in size on satellite imagery.
As activity on the island decreased, it was declared dormant on 11 January 2022."
predictions, raw_outputs = model.predict(
[
{
"context": context_text,
"qas": [
{
"question": "When did the initial eruption end?",
"id": "0",
}
],
}
]
)
In [6]:
predictions[0]
Out[6]:
In [9]:
predictions[0]["answer"][0]
Out[9]: