Part 4 · 6 min read v1.5 · Published 8 June 2026 · Updated 22 June 2026
Three teal backend stacks on a benchmark grid with latency and F1 markers — picking a NER backend with evidence.

Benchmarking NER: Latency, Doc F1, and Cache Bugs

text-compressor needed NER to evaluate summaries. ArticleRecommender needed it to extract technologies from articles so it could autonomously investigate them.

I could have hardcoded an API call to OpenRouter and asked an LLM to extract the entities. Instead I built a harness to measure the trade-offs between quality and latency, because I did not want to pick a model based on vibes.

That is why I built ner-detector.

Context

Named Entity Recognition (NER) finds names and labels in text — people, organizations, product names, dates, and so on. For ArticleRecommender, the question is narrower: did the system spot “Pinecone” or “GraphRAG” in this document?

To grade NER models you need gold data — documents where a human (or a trusted process) has marked the correct entities. You run each model against that gold and compare.

F1 is a standard score combining precision and recall. What matters is what you are scoring:

The Pluggable Harness

ner-detector is a pluggable NER runtime and benchmark runner. I implemented four distinct backends:

  1. Pattern — Regex and heuristics. Latency: milliseconds. Quality: poor on complex text.
  2. Transformers — BERT-family NER. Latency: tens of ms per doc when the model stays cached. Quality: fixed PER/ORG/LOC types.
  3. GLiNER / NuNER — Zero-shot models; you provide the label schema at runtime. Latency: hundreds of ms to seconds. Quality: useful for domain-specific labels without retraining.
  4. LLM — OpenRouter extraction. Latency: ~7–9 s per doc. Quality: strong on news gold, weaker on sparse scientific abstracts.

I built a CLI, a Python API, and a YAML-driven configuration system. I mocked the heavy ML paths in CI so I could maintain my ≥95% test coverage gate without downloading 500MB of weights on every pull request.

Then I built the benchmark runner to pit them against each other.

The Metric That Matters: Doc F1

If you read academic NLP papers, you will see a lot of focus on Strict Span F1. This metric requires the model to identify the exact character start and end offsets of an entity.

My use case is different. I am doing salient-entity extraction. I only care about the important entities (e.g., “Pinecone”), not every single noun. If a model finds “Pinecone” but misses the exact character offset by one space, Strict Span F1 punishes it as a false positive.

For this system, that is the wrong headline metric. I still validate spans where the dataset requires them, but the product question is simpler: did the system find the entity that should drive downstream investigation?

NER benchmark papers and shared tasks typically report exact span F1 because annotation quality and leaderboard ranking depend on precise boundaries. Product extraction often cares about a narrower question — did the salient handle appear anywhere in the document? — which is closer to typed mention detection than CoNLL-style span matching. I captured that product question in ADR 001 and made Document-Level F1 (Doc F1) the primary metric: Did the model extract the normalized text of the entity somewhere in this document?

The Latency Bug

When I ran the first full benchmark, the pipeline was crawling. I looked at the logs, expecting network latency from the LLM.

Instead, I saw the Hugging Face transformers backend taking seconds per document. It was not downloading weights from the internet; it was re-loading the model from disk into memory for every single document. The code was optimizing for strict process isolation over iteration speed.

This is why you must measure wall-clock time. A model that claims to be “fast” in a paper is useless if your implementation reloads weights on every document. I fixed the transformers backend cache policy; BERT inference settled at ~80 ms/example on the published run (down from multi-second per-doc behavior before the fix).

The Results

I ran the backends against shared gold in ner-dataset — primarily synthetic_news_100 (standard entity types) and arxiv_gold (ten manual scientific abstracts with domain labels). Doc F1 is the headline metric (ADR 001). Numbers below are from the published benchmark report (run-20260606T131135Z):

BackendDatasetDoc F1LatencyRoute when…
LLM (gpt-oss-120b:free)synthetic_news_10083.9%~6.9 sOffline enrichment; quality over speed
NuNER Zerosynthetic_news_10078.0%~1.9 sBest non-LLM quality on news without 7s calls
BERT (dslim/bert-base-NER)synthetic_news_10072.5%~80 msInteractive ingest; fixed PER/ORG/LOC schema
GLiNER mediumarxiv_gold36.2%~364 msCustom scientific labels without retraining
LLM (gpt-oss-120b:free)arxiv_gold47.2%~9.1 sHigh cost, modest gain on sparse scientific gold

There is no universal winner. BERT is not benchmarked on arxiv_gold — its CoNLL labels do not match scientific gold types. GLiNER/NuNER matter when the label schema is domain-specific. The LLM leads on synthetic news but does not justify a blanket default on scientific abstracts.

That gave me routing logic. But the benchmark revealed a deeper problem.

To run a benchmark, you need gold data — documents with correctly annotated entities to test against. And the way I was generating that gold data was fundamentally broken.

Takeaways

The Evidence

Previous: ModernBERT and the Overlap Trap · Next: Fixing LLM Offset Hallucinations


← All posts