Named Entity Recognition with Span-Level Evaluation

MetaCyberGuru Academy

IntermediateEstimated learning effort: 70 minutesFree, no sign-up requiredPublished by Muhammad AzharCourse version: August 2026

Back to Linguistic Analysis and Information Extraction

Named entity recognition turns mentions into labelled spans, but useful systems also resolve boundary errors and domain-specific labels.

A model can identify people, organisations, locations, dates and other categories. Your application may instead need invoice IDs, products or regulations, so evaluation must use the target label set.

Entity correctness has two parts: label and boundary. Calling New York an entity but omitting City can break linking even when the category is right.

Evaluate Entity Spans Instead of Counting Easy Matches

  • Extract entity text, character offsets and labels from a document.
  • Measure exact-span matches and review partial overlaps separately.
  • Define labels with examples and counterexamples before collecting annotations.
  • Review exact and partial span errors separately before changing labels or model rules.

Spans are the product interface

Offsets connect a prediction to evidence and make corrections possible. Normalised values belong in separate fields.

Overlapping entities require an explicit policy because many sequence labelling models return non-overlapping spans.

Precision and recall tell different stories

High recall suits candidate generation followed by human review. High precision may matter for automatic redaction, where false positives remove legitimate text.

Annotation quality sets the ceiling

Two annotators can disagree about subsidiaries, titles or nested names. A written guideline makes those disagreements visible.

Split documents, not sentences, when adjacent text from one source would leak into both train and test sets.

Review confusion by label

Inspect missed entities, wrong labels and boundary-only errors separately. Each category suggests a different fix.

A larger model will not repair an inconsistent label definition.

Build the Named Entity Recognition with Span-Level Evaluation example

This single sentence is a sanity check, not an evaluation. Replace expected with reviewed spans across representative documents.

Character offsets are measured against the original Python string. Any cleanup before inference can shift them.

Install:

python -m pip install spacy
python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load('en_core_web_sm')
text = 'Ada Lovelace worked with Charles Babbage in London.'
doc = nlp(text)
for ent in doc.ents:
    print(ent.text, ent.start_char, ent.end_char, ent.label_)
expected = {('Ada Lovelace', 'PERSON'), ('Charles Babbage', 'PERSON'), ('London', 'GPE')}
predicted = {(e.text, e.label_) for e in doc.ents}
print('exact correct:', len(expected & predicted), 'of', len(expected))

Expected Spans and Evaluation Counts

Ada Lovelace 0 12 PERSON
Charles Babbage 25 40 PERSON
London 44 50 GPE
exact correct: 3 of 3

Exact matching is intentionally strict. Maintain a separate overlap report to diagnose near misses without inflating the production metric.

Never use a general entity model as an automatic personal-data detector without testing the relevant data types and languages.

Diagnose failures in Named Entity Recognition with Span-Level Evaluation

Compare predicted and gold spans by offsets, then inspect the surrounding sentence.

Checks for the Named Entity Recognition with Span-Level Evaluation example
SymptomLikely causeUseful check
Entity text is right but offsets are wrongText was normalised before prediction or offsets were reconstructedRun on preserved source text and keep native model spans
Company IDs are always missedThe general model has no such label or training examplesAdd a deterministic pattern or annotate domain data
Recall looks perfect on random sentencesSentences from the same document leaked across splitsSplit by document, customer or time according to deployment

Create an entity evaluation sheet

Annotate thirty short domain examples with offsets and labels, including negative examples and ambiguous boundaries.

  1. Write a one-page label guide
  2. Run the model and export exact predictions
  3. Calculate exact precision and recall by label
  4. List five boundary-only errors
  5. Choose one rule or data improvement

Definition of done: Every score traces back to visible spans, and the label guide explains ambiguous cases.

Stretch task: Add a high-precision EntityRuler pattern and show whether it helps without harming existing entities.

Check your Named Entity Recognition with Span-Level Evaluation reasoning

Check your span-evaluation judgement before opening the explanations. Look for boundary errors, label disagreement and partial matches.

1. What makes an exact entity match?
Check the answer

Answer: Matching both the intended label and exact source span.

2. Why split by document?
Check the answer

Answer: To prevent closely related content from appearing in both training and evaluation.

3. When can high recall be appropriate?
Check the answer

Answer: Candidate generation followed by a reliable review step.

Primary references for Named Entity Recognition with Span-Level Evaluation

Revalidate this lesson when the spaCy pipeline or annotation guidelines change. Record the model package and reviewed span set used for comparison.

Save your place

Completion is stored only in this browser on this device.

Share this page

Share this page with the people who will use it next.

X Facebook LinkedIn WhatsApp Email

Discussion

No comments yet. Add the first useful question or observation.