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 Document Redactor for a working demo.

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 Document Redactor showcase app:

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

Showcase Apps

AppDescriptionLinks
Document RedactorExtract and redact named entities from documentsDemo · Source

Next Steps

On this page