Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Neuml Txtai Extractive QA

From Leeroopedia


Knowledge Sources
Domains Machine Learning, NLP, Question Answering, Transformers
Last Updated 2026-02-10 01:00 GMT

Overview

Concrete tool for running extractive question answering over question-context pairs provided by txtai.

Description

Questions extends HFPipeline and wraps the Hugging Face question-answering pipeline to perform extractive QA. For each question-context pair, the pipeline extracts the best answer span from the context. Answers with a confidence score below 0.05 are filtered out and returned as None. The pipeline handles null or empty questions/contexts gracefully by returning None for those entries.

Usage

Use Questions when you need to extract specific answers from text passages given a set of questions. This is the standard extractive QA approach where answers are spans of text directly from the provided context, not generated text.

Code Reference

Source Location

  • Repository: Neuml_Txtai
  • File: src/python/txtai/pipeline/text/questions.py

Signature

class Questions(HFPipeline):
    def __init__(self, path=None, quantize=False, gpu=True, model=None, **kwargs)
    def __call__(self, questions, contexts, workers=0)

Import

from txtai.pipeline.text.questions import Questions

I/O Contract

Inputs

Name Type Required Description
questions list Yes List of question strings. Entries can be None or empty.
contexts list Yes List of context strings corresponding to each question. Must be the same length as questions.
workers int No Number of concurrent workers for data processing. Defaults to 0.

Outputs

Name Type Description
answers list List of answer strings extracted from contexts. Returns None for entries where the question or context is empty, or where the confidence score is below 0.05.

Usage Examples

from txtai.pipeline.text.questions import Questions

# Create a question answering pipeline
qa = Questions("distilbert-base-cased-distilled-squad", gpu=True)

# Answer questions from contexts
questions = [
    "What is the capital of France?",
    "Who founded Microsoft?"
]
contexts = [
    "Paris is the capital and largest city of France.",
    "Microsoft was founded by Bill Gates and Paul Allen in 1975."
]

answers = qa(questions, contexts)
# Returns: ["Paris", "Bill Gates and Paul Allen"]

# Handles empty inputs gracefully
answers = qa(["What is AI?", None], ["AI is artificial intelligence", "Some context"])
# Returns: ["artificial intelligence", None]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment