← All models

question-answering · text · WASM · ~295 MB

Multilingual QA — find the answer inside a passage, in any language

This is extractive question answering with one twist: the model is XLM-RoBERTa, pretrained on 100 languages. Give it a passage and a question — in French, German, Spanish, Japanese, Arabic, English… — and instead of writing a new sentence it points at the exact span of the passage that answers you. No translation step, no per-language model. Pick a sample below and watch it highlight the answer, then look inside at the real start/end token probabilities it used. Nothing leaves your device.

At a glance

Modelonnx-community/xlm-roberta-base-finetuned-squad2-ONNX
Task / pipelinequestion-answering (extractive span prediction)
How it workspredicts two distributions over the passage tokens — where the answer starts and where it ends
ArchitectureXLM-RoBERTa base (multilingual, 100 languages) fine-tuned on SQuAD 2.0
Languagesone model, ~100 languages — question and context can be non-English
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~295 MB (weights + a large multilingual tokenizer), cached after first load
LicenseMIT (weights) · Apache-2.0 (runtime)
Web APIsWebAssembly, Web Workers — all Baseline widely available

Heads-up: XLM-R has a 250k-token multilingual vocabulary, so this is the largest of the QA demos (~295 MB). It runs fine on desktop and modern phones, but it's a heavier first download than the English DistilBERT SQuAD demo (~65 MB).

Run it

Load a sample in any language, or paste your own passage and question. The model highlights the answer span in the passage; the candidate list shows its next-best guesses.

Try a sample (question + passage)

See inside — the start/end token probabilities

The model never "reads" an answer out — it outputs two numbers per passage token: how likely that token is the first word of the answer, and how likely it is the last. The answer is the span from the best start to the best end. Because XLM-R uses a SentencePiece tokenizer, a "word" is often several subword pieces (the ▁ marks word boundaries) — the strip shows the real softmaxed distribution over the passage tokens for your last question, with the chosen start/end tokens outlined.

Answer a question above to inspect the token probabilities.

Why it matters

Most "answer from my documents" tooling is English-first. A single multilingual extractive model collapses that: one 295 MB download answers questions over passages in dozens of languages, and because it returns a span of the source rather than inventing text, the answer is always grounded — it can't hallucinate a fact that isn't in the passage. It runs in a tab, so multilingual documents, contracts, or support tickets can be queried without any of it leaving the device.

Use cases

Basics

Ask a question in several languages and watch the exact answer span light up.

Practical

A multilingual FAQ box: paste help-centre text in any language and query it.

Wild

Cross-lingual: ask in English over a non-English passage and see the shared representation work.

Multi-model

A multilingual embedder retrieves the right paragraph, then this model extracts the answer.

How the API works

The pipeline takes a question and a context and returns the best span; we read the raw logits from the same model instance to get clean, highlightable multilingual spans:

import { pipeline } from "@huggingface/transformers";

const qa = await pipeline(
  "question-answering",
  "onnx-community/xlm-roberta-base-finetuned-squad2-ONNX",
  { dtype: "q8" },
); // downloads + caches ~295 MB once

// The stock pipeline drops inter-word spaces for SentencePiece models, so we read the raw
// start_logits / end_logits off qa.model, pick the best span, and re-locate it in the ORIGINAL
// passage (whitespace-insensitive) to get a correctly-spaced, highlightable answer.
const enc = qa.tokenizer(question, { text_pair: context, padding: true, truncation: true });
const { start_logits, end_logits } = await qa.model(enc);

All of it runs in a Web Worker so the UI never janks. See worker.js for the span picker and the whitespace-insensitive re-location.

References