Named entity recognition helps computers find important names like people, places, or dates in text. It makes reading and understanding text easier for machines.
0
0
Named entity recognition in NLP
Introduction
To find names of people in news articles automatically.
To extract locations from travel blogs for mapping.
To identify dates and events in emails for scheduling.
To spot company names in financial reports.
To highlight product names in customer reviews.
Syntax
NLP
from transformers import pipeline ner = pipeline('ner') results = ner('Apple is looking at buying U.K. startup for $1 billion')
This example uses a ready-made tool called a pipeline to do named entity recognition.
The input is a text string, and the output shows detected names and their types.
Examples
This finds the person name and location in a simple sentence.
NLP
from transformers import pipeline ner = pipeline('ner') text = 'Barack Obama was born in Hawaii.' results = ner(text) print(results)
Using aggregation groups tokens into full names like 'Amazon' or 'Seattle'.
NLP
from transformers import pipeline ner = pipeline('ner', aggregation_strategy='simple') text = 'Amazon is hiring in Seattle.' results = ner(text) print(results)
Sample Model
This program finds names of companies, people, places, and dates in the text. It prints each found entity with its type and confidence score.
NLP
from transformers import pipeline # Create a named entity recognition pipeline ner = pipeline('ner', aggregation_strategy='simple') # Sample text text = 'Google was founded by Larry Page and Sergey Brin in California in 1998.' # Run NER results = ner(text) # Print results for entity in results: print(f"Entity: {entity['entity_group']}, Text: {entity['word']}, Score: {entity['score']:.2f}")
OutputSuccess
Important Notes
NER models work best on clear, well-written text.
Aggregation helps combine words that belong to the same name.
Confidence scores show how sure the model is about each entity.
Summary
Named entity recognition finds important names in text like people, places, and dates.
It helps computers understand text better by highlighting key information.
Using ready tools like pipelines makes it easy to try NER on any text.