LocalMode
Transformers

Named Entity Recognition

Extract people, organizations, locations, and other entities from text.

Extract named entities — people, organizations, locations, and miscellaneous entities — from text using token classification models.

For full API reference (extractEntities(), extractEntitiesMany(), options, result types, and custom providers), see the Core Classification guide.

See it in action

Try the PII Redactor block — it extracts named entities to redact PII from documents, on-device.

ModelSizeEntity TypesUse Case
Xenova/bert-base-NER~110MBPER, ORG, LOC, MISCGeneral-purpose NER

Entity Types

TypeDescriptionExamples
PERPerson namesTim Cook, Marie Curie
ORGOrganizationsApple, United Nations
LOCLocationsCupertino, France
MISCMiscellaneousEnglish, Nobel Prize

Document Redaction Example

Based on the PII Redactor block:

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

const model = transformers.ner('Xenova/bert-base-NER');

const { entities } = await extractEntities({
  model,
  text: document,
  abortSignal: controller.signal,
});

// Strip BIO prefix from entity types (B-PER → PER, I-ORG → ORG)
const cleaned = entities.map((e) => ({
  ...e,
  type: e.type.replace(/^[BI]-/, ''),
}));

// Redact entities by replacing with placeholder
let redacted = document;
for (const entity of cleaned.reverse()) {
  redacted =
    redacted.slice(0, entity.start) +
    `[${entity.type}]` +
    redacted.slice(entity.end);
}

Best Practices

NER Tips

  1. Handle BIO prefixes — Raw output uses B-/I- prefixes (B-PER, I-PER); strip them for display
  2. Use offsets for redactionstart/end give exact character positions for replacement
  3. Process in reverse — When redacting, work from end to start to preserve offsets
  4. Filter by score — Low-confidence entities may be false positives

Composed Block

BlockDescriptionLinks
PII RedactorOn-device NER PII detection and redactionLive · Install: npx shadcn add @localmode/ui/blocks/privacy/pii-redactor

Next Steps

On this page