Named Entity Recognition
Extracting structured labels from flowing text
NER finds people, places, organizations, dates and numbers in text. Span-level annotation and BIO tagging make it evaluation-wise different from text classification — and it's the extraction workhorse of information systems.
What you will learn
- Explain BIO/IOB span tagging and why entities are spans
- Run a pretrained NER pipeline and read its output
- Evaluate NER at entity level, not token level
What is this?
Named entity recognition labels spans of text as entities — 'Ashley Williams' → PERSON, 'Zurich' → GPE, '2026-01-15' → DATE. Sequences are annotated with BIO tags (B = begin, I = inside, O = outside) per token so that multi-token spans are reconstructed. Modern NER is a sequence-labeling model (CRF or transformer head) over token embeddings, and it is evaluated by exact-span matching — a token-level accuracy that misses a half-matched span is the wrong metric.
Why do you need it?
- Extraction converts unstructured text into structured facts for knowledge bases, search and compliance.
- Span semantics ('New York' is one entity, not two tokens 'New' + 'York') demand sequence labeling.
- Entity accuracy gates downstream joins (match a SSN, a vendor name, a product code).
- Almost every procurement, healthcare and legal pipeline starts with NER.
Mental model
A highlighter on a report
NER
You highlight 'Acme Corp' as ONE unit — company — across two words, just as NER tags Bill-I + Gates-I as one PERSON span rather than two unrelated tokens.
How it works
- Annotate: every token gets B/I/O per class; spans = consecutive B..I runs.
- Tokenize and embed; a CRF or transformer-token head assigns tags conditioned on neighbors.
- Decode the tag sequence; merge B-Its into entity spans with labels.
- Evaluate by comparing predicted spans vs gold spans exactly (token-span matching with optional type check).
- Handle nested/overlapping entities (biomedical) with extended schemes when needed.
BIO-tagging tokens then merging spans.
In production
- A legal platform extracts party names, dates and amounts from contracts into a structured docket.
- A support CRM auto-tags product names and region entities to route tickets with context.
- A compliance scanner flags PHI-like entities in free text before ingestion.
Best practices
- Use pretrained pipelines (spaCy, stanza) first; fine-tune only when distribution differs (legal/bio jargon).
- Evaluate span-level precision/recall/F1 with type-checked exact spans.
- Add a post-filter: entity type + confidence threshold before writing downstream rows.
- Log the tokenizer, model version and tag scheme for every NER run.
Common mistakes
- Judging NER by token accuracy — half-matched spans inflate it.
- Ignoring case: many pipeline models rely on casing ('Apple' company vs fruit).
- Fine-tuning on clean prose, serving on machine-garbled text (OCR) — same tokens, different world.
- Overlapping entities collapsed because the tag scheme can't express them.
Common issues
The pipeline never finds rare entity typesTraining data has few examples of that type
Stratify annotation per type, add dictionary/context boosts, and report per-type recall.
Spans jump across the sentence boundarySequence model allowed cross-sentence tagging if not segmented
Keep sentence segmentation at inference identical to training (or use an ID-based constraint).
Debugging tips
- Print 20 raw span predictions next to gold spans — errors are usually consistent (miss boundaries, type swaps).
- If a 'PERSON' span always starts one token early, the BIO scheme mis-seeded — retag boundaries.
- Low precision on GPE names? Check the gazetteer + casing rules before retraining.
- Entity type confusion (ORG vs GPE) is common — add type consistency features (postpositions, titles).
Interview checkpoint
Quick quiz
The span 'UN member states' with BIO tags would tag 'UN' as:
NER is best evaluated by exact span matching per type.