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.
Recommended Models
| Model | Size | Entity Types | Use Case |
|---|---|---|---|
Xenova/bert-base-NER | ~110MB | PER, ORG, LOC, MISC | General-purpose NER |
Entity Types
| Type | Description | Examples |
|---|---|---|
PER | Person names | Tim Cook, Marie Curie |
ORG | Organizations | Apple, United Nations |
LOC | Locations | Cupertino, France |
MISC | Miscellaneous | English, 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
- Handle BIO prefixes — Raw output uses B-/I- prefixes (B-PER, I-PER); strip them for display
- Use offsets for redaction —
start/endgive exact character positions for replacement - Process in reverse — When redacting, work from end to start to preserve offsets
- Filter by score — Low-confidence entities may be false positives