← All models

token-classification · text · WASM · ~278 MB

XLM-RoBERTa NER — name the entities, even in languages it never trained on

Named-entity recognition labels each span: who (PersonPER), what organization (OrgORG), where (LocationLOC), and when (DateDATE). This model runs on an XLM-RoBERTa backbone — pretrained on 2.5 TB of web text in 100 languages with a SentencePiece vocabulary. It's fine-tuned for NER on ten high-resource languages, but XLM-R's cross-lingual alignment is strong enough that it also tags entities in languages it never saw labelled — Turkish, Swedish, Japanese and more. Try the dashed "transfer" samples below. All on your device.

At a glance

Modeltjruesch/xlm-roberta-base-ner-hrl-onnx — a Transformers.js ONNX export of the canonical Davlan/xlm-roberta-base-ner-hrl
Task / pipelinetoken-classification
LabelsBIO tags over 4 classes: PER, ORG, LOC, DATE (9-way head incl. O)
Fine-tuned languages10 HRL: Arabic, German, English, Spanish, French, Italian, Latvian, Dutch, Portuguese, Chinese
Cross-lingual transferthe XLM-R backbone covers ~100 languages, so entities are tagged in many untrained languages too (Turkish, Swedish, Japanese, Indonesian, Polish…)
ArchitectureXLM-RoBERTa-base (RoBERTa encoder, 12 layers, 250k SentencePiece BPE vocab, ~278M params) fine-tuned for NER
Quantizationq8 (8-bit) ONNX — spans/labels verified correct across scripts
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~278 MB (the 250k-token vocab is large), cached after first load
LicenseWeights: AFL-3.0 per the canonical Davlan card (the ONNX export repo lists MIT); Transformers.js runtime: Apache-2.0
Web APIsWebAssembly, Web Workers — all Baseline widely available

Run it

Pick a language sample or paste your own text. Solid chips are the ten fine-tuning languages; the dashed chips are untrained transfer languages. Entities highlight a moment after you stop typing; hover a highlight for its confidence. RTL scripts (Arabic) lay out correctly.

See inside — SentencePiece tokens & BIO tags

Where multilingual BERT splits into WordPiece (##-marked) fragments, XLM-RoBERTa uses SentencePiece: it segments text into sub-word pieces with no continuation marker (a rare name like "Schäuble" becomes Schä · u · ble). Each piece is tagged with a BIO label — B-PER (begin person), I-PER (inside person) — and we stitch the B-/I- runs into whole entities. Below are the raw pieces and confidences straight from the model — the same machinery whether the input is French, Chinese, Arabic or Turkish.

Why it matters

A single NER model that structures text in ten languages — and degrades gracefully into dozens more it was never trained on — means you can index, redact, or link entities across a genuinely global corpus without a per-language pipeline and without a translation step. XLM-RoBERTa is the go-to backbone for cross-lingual transfer, and here it runs entirely in the browser, so not a byte of the source text leaves the device.

Use cases

Basics

Switch across ten languages and watch the same model tag people, orgs, places and dates.

Practical

Redact PII across languages, and extract entities into a structured, grouped list.

Wild

Zero-shot cross-lingual transfer: tag entities in Turkish, Swedish, Japanese — languages it never trained on.

Multi-model

NER → zero-shot: pull entities, then classify the whole passage's topic, both on-device.

How the API works

Token classification is one pipeline call:

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

const ner = await pipeline(
  "token-classification",
  "tjruesch/xlm-roberta-base-ner-hrl-onnx", // ONNX export of Davlan/xlm-roberta-base-ner-hrl
);
const out = await ner("Stefan Löfven träffade Angela Merkel i Stockholm."); // Swedish — untrained
// → [{ entity: "B-PER", word: "Stefan",  score: 1.0, index: 1 },
//    { entity: "I-PER", word: "Lö",      score: 1.0, index: 2 },   // SentencePiece pieces
//    { entity: "I-PER", word: "f",        score: 1.0, index: 3 },
//    { entity: "I-PER", word: "ven",      score: 1.0, index: 4 },
//    { entity: "B-PER", word: "Angela",   score: 1.0, index: 6 },
//    { entity: "I-PER", word: "Merkel",   score: 1.0, index: 7 },
//    { entity: "B-LOC", word: "Stockholm",score: 0.99,index: 9 }]

The pipeline returns one BIO-tagged row per SentencePiece token, but no character offsets. We map each piece back to its span in the original text (a cursor-walk) so highlights land exactly — across Latin, CJK and RTL scripts — then merge B-/I- runs into whole entities with a pooled confidence. It all runs in a Web Worker so typing stays smooth.

References