What is Named Entity Recognition in transformers?

This recipe explains what is Named Entity Recognition in transformers.

Recipe Objective - What is Named Entity Recognition in transformers?

Named Entity Recognition (NER) is the task of classifying tokens based on categories, for example, identifying tokens as individuals, organizations, or locations. An example of a named entity recognition data set is the CoNLL2003 data set, which is completely dependent on the task. If you want to fit the model in the NER task, you can use the run_ner.py script. Tokens in Named Entity Recognition:

Explore the BERT Variants - ALBERT vs DistilBERT 


* O, Outside of a named entity
* B-MIS, Beginning of a miscellaneous entity right after another miscellaneous entity
* I-MIS, Miscellaneous entity
* B-PER, Beginning of a person’s name right after another person’s name
* I-PER, Person’s name
* B-ORG, Beginning of an organization right after another organization
* I-ORG, Organisation
* B-LOC, Beginning of a location right after another location
* I-LOC, Location

For more related projects -

/projects/data-science-projects/tensorflow-projects
/projects/data-science-projects/neural-network-projects

Example of using pipelines to do named entity recognition, trying to identify tokens:

# Importing libraries
from transformers import pipeline

# Creating pipeline for named entity recognition
model_named_entity = pipeline("ner")

# Creating sequence
sequence = """Delhi, city and national capital territory, north-central India.
... The city of Delhi actually consists of two components: Old Delhi, in the north,
... the historic city; and New Delhi, in the south, since 1947 the capital of India,
... built in the first part of the 20th century as the capital of British India."""

# Passing sequence to model
output_tokens = model_named_entity(sequence)

# Printing tokens
for token in output_tokens:
 print(token)

Output -
{'entity': 'I-LOC', 'score': 0.999414, 'index': 1, 'word': 'Delhi', 'start': 0, 'end': 5}
{'entity': 'I-LOC', 'score': 0.9977246, 'index': 12, 'word': 'India', 'start': 58, 'end': 63}
{'entity': 'I-LOC', 'score': 0.99927324, 'index': 20, 'word': 'Delhi', 'start': 82, 'end': 87}
{'entity': 'I-LOC', 'score': 0.9942513, 'index': 27, 'word': 'Old', 'start': 125, 'end': 128}
{'entity': 'I-LOC', 'score': 0.99857974, 'index': 28, 'word': 'Delhi', 'start': 129, 'end': 134}
{'entity': 'I-LOC', 'score': 0.99860877, 'index': 42, 'word': 'New', 'start': 178, 'end': 181}
{'entity': 'I-LOC', 'score': 0.9993835, 'index': 43, 'word': 'Delhi', 'start': 182, 'end': 187}
{'entity': 'I-LOC', 'score': 0.99865437, 'index': 54, 'word': 'India', 'start': 229, 'end': 234}
{'entity': 'I-LOC', 'score': 0.52388036, 'index': 72, 'word': 'British', 'start': 303, 'end': 310}
{'entity': 'I-LOC', 'score': 0.9926432, 'index': 73, 'word': 'India', 'start': 311, 'end': 316}

In this way, we can perform named entity recognition in transformers.

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

A/B Testing Approach for Comparing Performance of ML Models
The objective of this project is to compare the performance of BERT and DistilBERT models for building an efficient Question and Answering system. Using A/B testing approach, we explore the effectiveness and efficiency of both models and determine which one is better suited for Q&A tasks.

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Build a Multi Class Image Classification Model Python using CNN
This project explains How to build a Sequential Model that can perform Multi Class Image Classification in Python using CNN

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Build a Text Classification Model with Attention Mechanism NLP
In this NLP Project, you will learn to build a multi class text classification model with attention mechanism.

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.