NLP
Intermediate 14 min read NLP

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.

NERnamed entityBIO taggingspansspaCyentity extraction
Prerequisites: Text Preprocessing
Before we start

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
Introduction

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.

Motivation

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.
Think about it

Mental model

Imagine

A highlighter on a report

Think of

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.

Mechanics

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.

Tokens
Tags
Spans
Evaluate
Serve
Real world

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.
Guidelines

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.
Watch out

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.
Root cause analysis

Common issues

Error
The pipeline never finds rare entity types
Root cause

Training data has few examples of that type

Fix

Stratify annotation per type, add dictionary/context boosts, and report per-type recall.

Error
Spans jump across the sentence boundary
Root cause

Sequence model allowed cross-sentence tagging if not segmented

Fix

Keep sentence segmentation at inference identical to training (or use an ID-based constraint).

When things break

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).
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

The span 'UN member states' with BIO tags would tag 'UN' as:

2

NER is best evaluated by exact span matching per type.

Go deeper

Official documentation