programmer290399 / pyqna

A simple python package for question answering.
https://programmer290399.github.io/pyqna/
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link
attention-mechanisms deep-learning hacktoberfest machine-learning-algorithms machine-reading machine-reading-comprehension natural-language-processing open-domain-question-answering python question-answering transformer-models

img


TESTS pypi PyPI - Downloads last-commit GitHub issues license PyPI - Python Version


PyQnA is a simple package that aims to provide a consistent and unified API for all Question Answering related tasks in Python.

Installation

Example:

# Import a specific model
from pyqna.models.reading_comprehension.transformer_models import TransformerQnAModel

# Instantiate the model
model = TransformerQnAModel(
    {"model_name": "distilbert-base-uncased-distilled-squad", "pre_trained": True}
)

# Take a context 
context = """ 
New Zealand (Māori: Aotearoa) is a sovereign island country in the southwestern Pacific Ocean.
It has a total land area of 268,000 square kilometres (103,500 sq mi), and a population of
4.9 million. New Zealand's capital city is Wellington, and its most populous city is Auckland.
"""

# Make a list of your queries
questions = ["How many people live in New Zealand?", "What's the largest city?"]

# Run inference using the instantiated models
answers = model.get_answer(context, questions)

# Print the output
print(answers)

Output:

[{'score': 0.9889324307441711, 'start': 55, 'end': 58, 'answer': '4. 9 million'}, {'score': 0.31774288415908813, 'start': 74, 'end': 74, 'answer': 'auckland'}]

License

PyQnA is distributed under the BSD 3-Clause License.