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

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

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.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.