⚡️ Saturday AI Sparks 🤖 - 🔎 Named Entity Recognition (NER) with Transformers
Posted On: September 20, 2025
Description:
Named Entity Recognition (NER) is a core task in Natural Language Processing (NLP). It automatically identifies and classifies parts of text into categories like persons, organizations, locations, and dates.
With Hugging Face Transformers, we can run state-of-the-art NER models in just a few lines of code — no training required.
Why NER?
- Information extraction → convert unstructured text into structured insights.
- Search & retrieval → improve indexing by tagging entities.
- Business use cases → extract names, places, and dates from contracts, emails, or support tickets.
Installing Requirements
pip install transformers torch
Loading a Pretrained NER Pipeline
We use Hugging Face’s dslim/bert-base-NER model, which is fine-tuned for entity recognition.
from transformers import pipeline
ner = pipeline("ner", model="dslim/bert-base-NER", aggregation_strategy="simple")
Here, aggregation_strategy="simple" groups together tokens that belong to the same entity.
Running NER on Text
Pass in a sample sentence containing organizations, people, and dates.
text = "Apple is looking to hire AI engineers in San Francisco starting in 2025. Tim Cook announced the plan."
entities = ner(text)
The output contains each entity, its predicted category, and a confidence score.
Sample Output
Apple → ORG (score: 1.00)
AI → MISC (score: 0.77)
San Francisco → LOC (score: 1.00)
Tim Cook → PER (score: 1.00)
Key Takeaways
- NER helps transform raw text into structured knowledge.
- Hugging Face makes it simple to apply pretrained models without training.
- This technique is widely used in chatbots, document parsing, compliance, and analytics pipelines.
Code Snippet:
from transformers import pipeline
# Load NER pipeline with pretrained BERT model
ner = pipeline("ner", model="dslim/bert-base-NER", aggregation_strategy="simple")
text = "Apple is looking to hire AI engineers in San Francisco starting in 2025. Tim Cook announced the plan."
# Run NER
entities = ner(text)
# Display results
for ent in entities:
print(f"{ent['word']} → {ent['entity_group']} (score: {ent['score']:.2f})")
Link copied!
Comments
Add Your Comment
Comment Added!
No comments yet. Be the first to comment!