Adwait Dathan R — November 3, 2021
Advanced NLP Python Text

This article was published as a part of the Data Science Blogathon.


This article will give you a brief idea about Named Entity recognition, a popular method that is used for recognizing entities that are present in a text document. This article is targeted at beginners in the field of NLP. By the end of the article, pre-trained NER models have been implemented for showcasing the practical use case. Happy learning!

Why NER?



Image 1

By observing the above image you might have got some ideas on what a NER model is doing. The model can find different entities that are present in the text such as persons, dates, organizations, and locations. Thus NER helps in adding more meaning to the text document. In simple words, you can say that it is doing information extraction.  The use cases of Named entity recognition are many, some of them are :

1. Customer support

Customer Support

Image 2

Every company has its customer support systems available. Each day, they have to deal with a huge number of customer requests which may range from installation, maintenance, complaint, and troubleshoot of a particular product. NER helps in identifying and understanding the type of request that the customer makes. Further, this helps the company to build an automated system that will identify the incoming request using NER and send it to the respective support desk.

2.  Filtering out resumes for finding  apt candidates for a job role


Filtering out resumes for finding  apt candidates for a job role

Image 3:

Do you think that all the resumes that are sent while applying for a particular job role are read by the recruiting team? Well, the fact is that only 25 per cent of the resumes are read by people. The rest are filtered out by an automated system. If you had previously attended a resume-building workshop, the mentor might have emphasized keeping the key skills as a separate section in the resume. Also, they might have advised you to add only the key skills that are related to the required job position. This is because the NER model in the automated system might have been custom trained to identify specific skill-sets as the entities. If a given resume has a required number of entities present, then it qualifies for the next stage. So, if you were not aware of this process, try to customize your resume accordingly while applying for the respective job.

3. Entity recognition from  electronic healthcare data

 Entity recognition from  electronic healthcare data

Image 4:

NER models can be used to build strong medical systems that are properly able to identify the symptoms present in the electronic healthcare data of patients and diagnose their disease depending on the symptoms. If you go through the above image, you can understand how perfectly the NER model was able to identify the symptoms, diseases, and chemicals that were present in the healthcare data of a particular person.

Those were some of the applications where NER was used in real-world scenarios. Next, we will check upon different types of  NER systems.

Different NER systems

1. Dictionary-based systems

This is the simplest NER approach. Here we will be having a dictionary that contains a collection of vocabulary. In this approach, basic string matching algorithms are used to check whether the entity is occurring in the given text to the items in vocabulary. The method has limitations as it is required to update and maintain the dictionary used for the system.

2.  Rule-based systems

Here, the model uses a pre-defined set of rules for information extraction. Mainly two types of rules are used, Pattern-based rules, which depend upon the morphological pattern of the words used, and context-based rules, which depend upon the context of the word used in the given text document. A simple example for a context-based rule is “If a person’s title is followed by a proper noun, then that proper noun is the name of a person”.

3. Machine learning-based systems

The ML-based systems use statistical-based models for detecting the entity names. These models try to make a feature-based representation of the observed data. By this approach, a lot of limitations of dictionary and rule-based approaches are solved by recognizing an existing entity name even with small spelling variations.

There are mainly two phases while we use an ML-based solution for NER. The first phase involves training the ML model on the annotated documents. The time taken for the model to train will vary depending upon the complexity of the model that we are building. In the next phase, the trained model can be used to annotate the raw documents.


Two Phases for NER

Image 5:


4. Deep Learning approaches



Deep Learning models for NER

Image 6:

In recent years, deep learning-based models are being used for building state-of-the-art systems for NER. There are many advantages of using DL techniques over the previously discussed approaches. Using the DL approach, the input data is mapped to a non-linear representation. This approach helps to learn complex relations that are present in the input data. Another advantage is that we can avoid a lot of time and resources spent on feature engineering which is required for the other traditional approaches.

Next, we will try out some tools for  NER extraction.

Standford NER Tagger

It is one of the standard tools that is used for Named  Entity Recognition. Mainly there are three types of models for identifying the named entities. They are:

1. Three class model which recognizes the organizations, persons, and locations.

2. Four class model which recognizes persons, organizations, locations, and miscellaneous entities.

3. Seven class model which recognizes persons, organizations, locations, money, time, percents, and dates.

We will be using the four-class model.

1.  Downloading the StanfordNER zip file using the following commands

!pip3 install nltk==3.2.4

2. Loading the model

from nltk.tag.stanford import StanfordNERTagger
jar = "stanford-ner-2015-04-20/stanford-ner-3.5.2.jar"
model = "stanford-ner-2015-04-20/classifiers/"
st_4class = StanfordNERTagger(model + "english.conll.4class.distsim.crf.ser.gz", jar, encoding='utf8')

3. While testing the model, I had taken a news extract from the Indian Express newspaper

example_document = '''Deepak Jasani, Head of retail research, HDFC Securities, said: “Investors will look to the European Central Bank later Thursday for reassurance that surging prices are just transitory, and not about to spiral out of control. In addition to the ECB policy meeting, investors are awaiting a report later Thursday on US economic growth, which is likely to show a cooling recovery, as well as weekly jobs data.”.'''

4. Providing the news article to the model

Example Document for NER

Spacy Pipelines for NER

Spacy has mainly three English pipelines that are optimized for CPU for Named Entity Recognition. They are

a) en_core_web_sm

b) en_core_web_md

c) en_core_web_lg

The above models are listed in ascending order according to their size where SM, MD, and LG denote small, medium, and large models respectively. Let us try out NER using the small model.

1. First let us download the model

import spacy
 import spacy.cli"en_core_web_sm")

2. Loading the model

sp_sm = spacy.load('en_core_web_sm')

3. Creating a function to output the recognized entities by the model.

def spacy_large_ner(document):
  return {(ent.text.strip(), ent.label_) for ent in sp_lg(document).ents}
recognized entities

Here GPE means Geopolitical Entity.


Briefly, the article has covered the basics of Named Entity Recognition and its use cases. You can also try out the above implemented pre-trained model with different examples. Further, as a next learning step, you can try to build custom NER models for your specific domain purposes.  Many pre-trained state-of-the-art NER models are available, you can fine-tune them for your usage. Spacy is a good library for building and using custom NER models. Please check out the documentation of spacy that I have provided in the reference. Also, remember that NER is not limited to the English language. The BERT-based multilingual models can be used for NER tasks in different languages.


1. A Survey on Deep Learning for
Named Entity Recognition by Jing Li, Aixin Sun, Jianglei Han, and Chenliang Li.

2. Biomedical Named Entity Recognition: A Survey of Machine-Learning Tools by David Campos,Sérgio Matos and José Luís Oliveira


4. Spacy Documentation –

Cover image source:

About The Author

Hi Guys, Myself Adwait Dathan. Currently, I am doing my MTech in Artificial Intelligence and Data Science. Please let me know your suggestions and feedbacks in the comment section. Happy Learning!!

Image Sources

  1. Image 1:
  2. Image 2:


About the Author

Our Top Authors

Download Analytics Vidhya App for the Latest blog/Article

Leave a Reply Your email address will not be published. Required fields are marked *