Categories
Uncategorized

Question Answering using BERT

Final
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]:
{'answer': ['initial eruption ended at 02:00 on 21 December 2021.',
  '02:00 on 21 December 2021.',
  'initial eruption ended at 02:00',
  '02:00',
  '21 December 2021.',
  'at 02:00 on 21 December 2021.',
  'at 02:00',
  'ended at 02:00 on 21 December 2021.',
  'eruption ended at 02:00 on 21 December 2021.',
  'ended at 02:00',
  'eruption ended at 02:00',
  'later.This initial eruption ended at 02:00 on 21 December 2021.',
  'later.This initial eruption ended at 02:00',
  '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',
  'initial eruption ended',
  '2021.',
  'on 21 December 2021.',
  '2021',
  '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',
  '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.'],
 'id': '0'}
In [9]:
predictions[0]["answer"][0]
Out[9]:
'initial eruption ended at 02:00 on 21 December 2021.'

By amankabra4

Researcher in Organizational Behavior | Pennsylvania State University - Smeal College of Business | Indian School of Business

Leave a Reply

Your email address will not be published.