Question Answering

Hugging Face 🤗 Pipeline

Jan Kirenz

Prerequisites

Python setup

from transformers import pipeline

Intuition

  • Question answering tasks return an answer given a question.

Use Cases

  • Automate the response to Frequently Asked Questions

  • Chat Bots

Common types

  • Extractive QA: The model extracts the answer from the original context.

    • The context could be a provided text, a table or even HTML! This is usually solved with BERT-like models.
  • Open Generative QA: The model generates free text directly based on the context.

  • Closed Generative QA: In this case, no context is provided. The answer is completely generated by a model.

Closed-domain vs open-domain

  • Closed-domain models are restricted to a specific domain (e.g. legal, medical documents).

  • Open-domain models are not restricted to a specific domain.

Simple Pipeline Model

Define pipeline

  • Define the Pipeline1
qa_model = pipeline("question-answering")

Provide question and context

question = "Where do I live?"

context = "My name is Jan and I live in Stuttgart."

Return the answer

qa_model(question=question, context=context)
{'score': 0.9671180844306946, 'start': 29, 'end': 38, 'answer': 'Stuttgart'}