Lensa ML

Named Entity Recognition

Step 1 of 6: Entity Types

PER, ORG, LOC, and more

Cursor position0
SarahPERworksOatOGoogleORGinOLondonLOC"Sarah" → Person (PER)Named person: a first name, last name, or full nameEntity types:PER = PersonORG = OrganizationLOC = Location
Token
"Sarah"
Entity type
PER
Entities found
3

"Sarah" is a Person entity (PER). "Sarah" sits in a position and context typical of person names, which is what the model learns to recognize.

Drag Cursor position from 0 to 5 to move through "Sarah works at Google in London". PER, ORG, and LOC are three of the four types in the CoNLL-2003 benchmark; the fourth, MISC, covers things like nationalities and events. OntoNotes 5.0 uses 18 types, adding dates, times, money, percentages, and products. Domain systems define their own sets: biomedical NER tags genes, proteins, and diseases, and legal NER tags courts and statutes. The type set is a design choice, set by what the downstream application needs to extract.

Step 2 of 6: BIO Tagging

Begin, Inside, Outside

Reveal tags (token position)0
B = Begin entity | I = Inside entity | O = OutsideTimB-PERCook?leads?Apple?from?Cupertino?Why BIO, not just entity type?"Tim Cook" → B-PER I-PER (one 2-token person entity)Without B/I: "Tim" PER "Cook" PER — is that 1 person or 2?
Revealed
1/6
B tags
1
I tags
0
O tags
0

"Tim" gets tag B-PER. B (Begin) marks the start of a new entity.

Drag Reveal tags (token position) from 0 to 5 to tag "Tim Cook leads Apple from Cupertino" one token at a time. BIO turns span finding into per-token classification with 2K + 1 labels for K entity types, which is 7 labels for PER, ORG, and LOC. Some tag sequences are invalid, such as I-ORG right after O or after B-PER. Variants add more structure. BIOES, also called BILOU, gives single-token entities and entity endings their own tags, which often improves accuracy slightly.

Step 3 of 6: Context Windows

How much context helps?

Context window size1
TimCookleadsApplefromCupertinowindow ±1Prediction confidence for "Apple" → ORG:50%Context clues:✓ "leads" → what someone leads is often an ORG
Focus
"Apple"
Window
±1
Context
3 tokens
Confidence
50%

With ±1 context: "leads Apple from". The verb "leads" suggests an organization, since people lead companies, not fruit. Confidence: 50%. (The confidence numbers are illustrative, not from a trained model.)

Drag Context window size from 0 to 5 and watch the confidence for "Apple" rise. Early neural NER worked this way: Collobert et al. (2011) fed a fixed window of word vectors around each token into a feed-forward network. Capitalization is a strong extra clue, which is why many systems add a casing input and why accuracy drops on all-lowercase text such as tweets. A fixed window has a hard limit. A clue five words away is invisible to a ±2 window, however informative it is.

Step 4 of 6: Sequence Labeling

RNN hidden states → entity tags

Sequence position0
Timh0B-PERCookh1leadsh2Appleh3fromh4Cupertinoh5Hidden state h0 activation:0.830.410.630.590.530.54RNN reads left-to-right, accumulating context in the hidden state vector.Each position outputs a tag prediction based on all prior tokens.
Position
Tim
Hidden dim
6
Predicted
B-PER

Position 0: "Tim". The RNN has no prior context, so it predicts B-PER from the embedding of "Tim" alone. Common first names are strong signals. This left-to-right RNN is a simplification with illustrative hidden values. Real NER taggers read both directions (a BiLSTM, or a transformer like BERT), so right context such as "from Cupertino" also informs the tag for "Apple".

Drag Sequence position from 0 to 5 to move the hidden state along the sentence. A left-to-right RNN cannot see later words, so bidirectional LSTMs run a second pass from the right and join both states at every token. Lample et al. (2016) added a CRF layer on top, which scores whole tag sequences and learns that I-PER can follow B-PER but not O. Most current NER systems fine-tune a Transformer such as BERT instead and predict one BIO tag per subword token.

Step 5 of 6: Confidence Thresholds

When to label, when to skip

Confidence threshold0.50
Tim72%Cook45%leads34%Apple79%from7%Cupertino60%Threshold: 50% — entities below this are rejectedPrecision vs Recall trade-off:Precision:100%Recall:75%F1 Score:86%
Threshold
50%
Precision
100%
Recall
75%
F1
86%

Threshold 50%: balanced precision (100%) and recall (75%). F1 = 86%. Raising the threshold keeps fewer, more confident predictions.

Drag Confidence threshold from 0.10 to 0.95 and watch precision, recall, and F1 change. F1 is the harmonic mean, 2PR / (P + R), so it stays low unless both precision and recall are high. The demo scores each token separately. Below 0.35 the verb "leads" clears the bar as a false positive and precision falls to 80%, while from 0.50 up the entity "Cook" is missed and recall falls to 75%. The right threshold depends on the cost of each error: redacting personal data needs high recall, while filling a database from news needs high precision.

Step 6 of 6: Entity-Level Evaluation

Exact span matching vs. partial credit

Match strictness0.00
Gold (ground truth):TimCookleadsApplefromCupertinoPredicted:TimCookleadsApplefromCupertinoMatch results (Exact span):Tim Cook [PER]✗ MissApple [ORG]✓ MatchCupertino [LOC]✓ MatchPrecision: 67%Recall: 67%F1: 67%Mode: Exact span — spans must match exactly
Strictness
Exact span
Precision
67%
Recall
67%
F1
67%

Exact span matching: "Tim" ≠ "Tim Cook". The predicted span is too short, so it counts as a miss, and only "Apple" and "Cupertino" match. CoNLL benchmarks use this rule.

Drag Match strictness from 0 to 1 to move between exact, partial, and type-only matching. Under exact matching the predicted "Tim" is both a false positive and a false negative, so one boundary error costs twice and precision and recall are both 2/3. The CoNLL-2003 evaluation counts an entity as correct only when span and type both match, and strong systems score around 93 to 94 F1 on its English test set. The SemEval-2013 scheme adds partial-credit categories for boundary errors.

What is named entity recognition (NER)?

Named entity recognition (NER) is the task of finding the names of things in text and labeling each with a type, such as person, organization, or location. In "Tim Cook leads Apple from Cupertino", an NER system marks "Tim Cook" as a person, "Apple" as an organization, and "Cupertino" as a location. It is usually framed as sequence labeling: the model assigns one tag to every token.

NER turns unstructured text into structured records. Search engines use it to link queries to knowledge bases, news and finance tools use it to track which companies and people a story mentions, hospitals use it to pull drugs and diagnoses from clinical notes, and privacy tools use it to find and redact personal data. It is also a standard first step for relation extraction and question answering.

Key ideas

  • NER finds spans of text that name specific entities and labels each span with a type.
  • BIO tags turn span detection into one classification per token.
  • Context decides ambiguous cases, such as Apple the company versus apple the fruit.
  • Bidirectional models with a CRF layer, and later fine-tuned Transformers, became the standard approach.
  • A confidence threshold trades precision against recall.
  • Benchmarks score whole entities, so a boundary error counts as both a miss and a false alarm.

Common questions

What is the difference between NER and part-of-speech tagging?

Both assign a label to every token. Part-of-speech tagging labels grammatical roles such as noun and verb for every word, while NER labels only the tokens inside entity names and gives everything else O. A proper noun is often, but not always, part of an entity.

How do you do named entity recognition in Python?

spaCy ships pretrained pipelines that return entities with one call, and Hugging Face Transformers offers a token-classification pipeline with fine-tuned BERT-style models. For a custom entity set, both can be fine-tuned on a few hundred to a few thousand labeled sentences.

Can large language models do NER?

Yes. A prompt that lists the entity types and asks for the spans works reasonably well with no training data, which helps for new domains. Fine-tuned encoder models are still usually more accurate on a fixed type set, faster, and far cheaper to run on large volumes of text.

What is nested NER?

Some entities contain other entities. "Bank of China" is an organization that contains a location, and "University of California, Berkeley" contains two. Flat BIO tagging can only give each token one tag, so nested NER needs span-based or layered models.

Related explainers

References

  1. Tjong Kim Sang & De Meulder (2003), "Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"
  2. Collobert et al. (2011), "Natural Language Processing (Almost) from Scratch", JMLR
  3. Huang, Xu & Yu (2015), "Bidirectional LSTM-CRF Models for Sequence Tagging"
  4. Lample et al. (2016), "Neural Architectures for Named Entity Recognition", NAACL
  5. Devlin et al. (2019), "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding", NAACL

Last updated