LocalMode
Transformers

Question Answering

Extractive question answering from a given context.

Extract answers directly from a context passage. The model finds the span of text that best answers the question — no generation needed.

For full API reference (answerQuestion(), answerQuestionMany(), options, result types, and custom providers), see the Core Question Answering guide.

See it in action

Try QA Bot for a working demo.

ModelSizeSpeedUse Case
Xenova/distilbert-base-cased-distilled-squad~100MB⚡⚡⚡Fast extractive QA
Xenova/distilbert-base-uncased-distilled-squad~100MB⚡⚡⚡Case-insensitive QA

QA Bot Example

Based on the QA Bot showcase app:

import { transformers } from '@localmode/transformers';
import { answerQuestion } from '@localmode/core';

const model = transformers.questionAnswering(
  'Xenova/distilbert-base-cased-distilled-squad'
);

async function askQuestion(question: string, context: string) {
  const { answer, score } = await answerQuestion({
    model,
    question,
    context,
    abortSignal: controller.signal,
  });

  return {
    answer,
    confidence: score,
    isReliable: score > 0.5,
  };
}

Best Practices

QA Tips

  1. Provide focused context — Shorter, relevant context gives better answers
  2. Check the score — Low scores mean the model is uncertain
  3. Extractive only — Answers are always spans from the context, not generated text
  4. Combine with search — Use semantic search to find relevant context first

Showcase Apps

AppDescriptionLinks
QA BotAnswer questions from provided context passagesDemo · Source

Next Steps

On this page