The Question Answering module within AdaptNLP

class QACallback[source]

QACallback(xmodel_instances, features) :: Callback

Basic Question Answering Data Callback

class TransformersQuestionAnswering[source]

TransformersQuestionAnswering(tokenizer:PreTrainedTokenizer, model:PreTrainedModel) :: AdaptiveModel

Adaptive Model for Transformers Question Answering Model


  • tokenizer - A tokenizer object from Huggingface's transformers (TODO)and tokenizers *
  • model - A transformer Question Answering model

class EasyQuestionAnswering[source]


Question Answering Module


>>> qa = adaptnlp.EasyQuestionAnswering()
>>> qa.predict_qa(query='What is life?', context='Life is NLP.', n_best_size=5, mini_batch_size=1)

Usage Examples:

Sample code from: 10_question_answering.ipynb (View Notebook for more context)

qa_model = EasyQuestionAnswering()
text = """, Inc.[6] (/ˈæməzɒn/), is an American multinational technology company based in Seattle, 
Washington that focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. 
It is considered one of the Big Four technology companies along with Google, Apple, and Facebook.[7][8][9] 
Amazon is known for its disruption of well-established industries through technological innovation and mass 
scale.[10][11][12] It is the world's largest e-commerce marketplace, AI assistant provider, and cloud computing 
platform[13] as measured by revenue and market capitalization.[14] Amazon is the largest Internet company by 
revenue in the world.[15] It is the second largest private employer in the United States[16] and one of the world's 
most valuable companies. Amazon is the second largest technology company by revenue. Amazon was founded by Jeff Bezos 
on July 5, 1994, in Bellevue, Washington. The company initially started as an online marketplace for books but later 
expanded to sell electronics, software, video games, apparel, furniture, food, toys, and jewelry. In 2015, Amazon 
surpassed Walmart as the most valuable retailer in the United States by market capitalization.[17] In 2017, Amazon 
acquired Whole Foods Market for $13.4 billion, which vastly increased Amazon's presence as a brick-and-mortar 
retailer.[18] In 2018, Bezos announced that its two-day delivery service, Amazon Prime, had surpassed 100 million 
subscribers worldwide

top_prediction, all_nbest_json = qa_model.predict_qa(query="What does Amazon do?", context=text, n_best_size=10, mini_batch_size=1, model_name_or_path="distilbert-base-uncased-distilled-squad")
test_eq(top_prediction, 'disruption of well-established industries')