AI Notes
Master NER. Entity tagging, BIO, CRF models. NLP 2024.
What is Named Entity Recognition?
Named Entity Recognition (NER) is the NLP task of identifying and classifying named entities in text into predefined categories such as persons, organizations, locations, dates, quantities, and other domain-specific types. NER transforms unstructured text into structured information by finding the "who, what, where, when" of text.
NER is a foundational component in information extraction pipelines, powering applications like search engines (understanding queries), question answering (finding answer entities), content recommendation (extracting topics), knowledge graph construction (populating nodes), and financial analysis (identifying companies and events in news).
Entity Categories
Standard Entity Types (CoNLL, OntoNotes)
| PERSON | "Albert Einstein", "Dr. Smith", "Mary" |
| ORGANIZATION | "Google", "United Nations", "MIT" |
| LOCATION | "Paris", "Mount Everest", "the Nile" |
| DATE | "January 2024", "last Tuesday", "the 90s" |
| TIME | "3:00 PM", "noon", "midnight" |
| MONEY | "$50 million", "€100", "500 rupees" |
| PERCENT | "25%", "a third", "half" |
Domain-Specific Entities
| Biomedical NER | Gene, Protein, Disease, Drug, Chemical |
| Legal NER | Court, Judge, Statute, Case |
| Financial NER | Ticker, Index, Currency, Metric |
NER Approaches
Rule-Based NER
| - Capitalized word sequences | potential entity |
| - "Mr./Mrs./Dr." + Name | PERSON |
| - Lookup in city/country dictionary | LOCATION |
| - Regex: \$[0-9,]+ | MONEY |
| Pros | High precision for known patterns |
| Cons | Low recall (misses variations), maintenance burden |
Sequence Labeling with BIO Tags
Most NER systems frame it as sequence labeling using BIO encoding:
| B-TAG | Beginning of an entity |
| I-TAG | Inside (continuation) of an entity |
| O | Outside any entity |
| Barack | B-PER |
| Obama | I-PER |
| visited | O |
| New | B-LOC |
| York | I-LOC |
| City | I-LOC |
| yesterday | O |
CRF-Based NER (Traditional ML)
| P(B-PER | I-PER) = high |
| P(B-PER | I-LOC) = 0 (illegal transition!) |
| P(O | I-PER) = 0 (must start with B) |
Deep Learning NER (BiLSTM-CRF)
Transformer-Based NER (BERT + Token Classification)
Modern state-of-the-art
Input: "[CLS] Barack Obama visited New York [SEP]"
BERT: Contextual embeddings for each token
Linear: Each token embedding → entity logits
Output: B-PER I-PER O B-LOC I-LOC
Fine-tuning BERT for NER
- Add linear classification head
- Train on labeled NER data (CoNLL-2003)
- 2-4 epochs, lr=2e-5
- F1 score: ~93% (English)
Worked Example: NER Processing
| Input | "Apple Inc. CEO Tim Cook announced new products in Cupertino on March 15, 2024" |
| Step 1 | Tokenization |
| Step 2 | Model prediction (BIO tags) |
| Apple | B-ORG |
| Inc | I-ORG |
| . | I-ORG |
| CEO | O |
| Tim | B-PER |
| Cook | I-PER |
| announced | O |
| new | O |
| products | O |
| in | O |
| Cupertino | B-LOC |
| on | O |
| March | B-DATE |
| 15 | I-DATE |
| , | I-DATE |
| 2024 | I-DATE |
| Step 3 | Entity extraction |
| ORG | "Apple Inc." |
| PER | "Tim Cook" |
| LOC | "Cupertino" |
| DATE | "March 15, 2024" |
Challenges in NER
Entity Boundary Detection
| "New York City" | one entity or "New York" + "City"? |
| "Bank of America" | one ORG or "Bank" + LOC("America")? |
| "The Lord of the Rings" | where does the title start/end? |
Nested Entities
| ORG | "University of California, Berkeley" |
| LOC | "California" |
| LOC | "Berkeley" |
| Solutions | Flat NER (longest span), layered NER, span-based models |
Ambiguity
| "Apple" | Company (ORG) or fruit (not an entity)? |
| "Jordan" | Person (Michael Jordan) or Country? |
| "Washington" | Person, State, or City? |
| Context resolves: "Apple stock rose" | ORG |
| "Apple pie recipe" | not an entity |
Evaluation Metrics
| Predicted | [Tim Cook]_PER [Cupertino CA]_LOC |
| Gold | [Tim Cook]_PER [Cupertino]_LOC |
| Tim Cook | Exact match ✓ (correct entity + correct type) |
| Cupertino CA | Wrong boundary (predicted too much) ✗ |
| State-of-the-art (CoNLL-2003 English) | F1 ≈ 93-94% |
Applications
| Application | Entity Types | Example |
|---|---|---|
| Search engines | All | Query understanding, knowledge panels |
| Healthcare | Disease, Drug, Gene | Clinical note processing |
| Finance | Company, Amount, Date | News analysis, compliance |
| Legal | Person, Org, Statute | Document review, case analysis |
| Social media | Person, Org, Product | Brand monitoring, trending |
Interview Questions
Q: Why use BIO encoding instead of just labeling entities? A: BIO (or BIOES) encoding solves the boundary problem. Without B/I distinction, adjacent entities of the same type merge: "[John][Smith]" both labeled PER would become one entity "John Smith." B-PER, B-PER correctly identifies two separate person entities.
Q: How does NER handle unseen entities? A: Modern NER models generalize through contextual features (not memorization). BERT-based NER recognizes that "Zyloth Corp announced..." likely contains an ORG at "Zyloth Corp" even if never seen before—because the context pattern (X + announced) matches learned ORG patterns.
Q: What is the difference between NER and entity linking? A: NER identifies entity mentions and their types ("Obama" = PER). Entity linking disambiguates and connects to a knowledge base ("Obama" → Barack_Obama in Wikipedia, not Michelle_Obama). Entity linking requires NER first, then adds disambiguation.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for NER - Information Extraction.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, natural, language, processing, named
Related Artificial Intelligence Topics