How to Extract Named Entities using Spacy in Python

share link

by vigneshchennai74 dot icon Updated: Feb 27, 2023

technology logo
technology logo

Solution Kit Solution Kit ย 

This code helps extract named entities from a text document using Spacy, a powerful open-source library for natural language processing in Python. Named Entity Recognition (NER) is a common task in natural language processing that involves identifying and classifying named entities in text, such as people, organizations, locations, and other entities. 

Using Spacy's pre-trained model and NER pipeline, this code can quickly and accurately identify the named entities in a given text document and classify them into predefined categories. This can be useful for various applications, such as information extraction, text classification, and entity linking. 

Named Entity Recognition (NER) using Spacy has real-world applications in various industries. Some of the common use cases of NER include: 

  • Information Extraction: NER can extract key information from unstructured text data, such as customer reviews, social media posts, and news articles. We can use this information to gain insights into customer sentiment, market trends, and competitor activity. 
  • Content Recommendation: NER can be used to analyze the content of news articles, blogs, and other online publications to identify the topics and themes discussed. We can use this information to recommend relevant content to users based on their interests and preferences. 
  • Sentiment Analysis: NER can identify the entities mentioned in customer reviews and social media posts and classify them as positive, negative, or neutral. We can use this information to analyze customer sentiment and make data-driven decisions to improve customer satisfaction. 
  • Chatbots and Virtual Assistants: NER can extract key information from user queries and provide relevant responses. This can help improve the accuracy and effectiveness of chatbots and virtual assistants. 

NER using Spacy can help organizations extract meaningful insights from unstructured text data and improve decision-making across various industries, including healthcare, finance, e-commerce, and media. 

Preview of the output that you will get on running this code from your IDE


In this solution we use the SpaCy library.

  1. Copy the code using the "Copy" button above, and paste it in a Python file in your IDE.
  2. Run the file to Get the output

I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.

I found this code snippet by searching for " Named entity recognition in Spacy" in kandi. You can try any such use case!



In this snippet we are using a Language model (en_core_web_sm)

  1. Download the model using the command python -m spacy download en_core_web_sm .
  2. paste it in your terminal and download it.

Check the user's spacy version using pip show spacy command in users terminal.

  1. if its version 3.0, you will need to load it using nlp = spacy.load("en_core_web_sm")
  2. if its version is less than 3.0 you will need to load it using nlp = spacy.load("en")

Dependent Library

spaCyby explosion

Python doticonstar image 26383 doticonVersion:v3.2.6doticon
License: Permissive (MIT)

๐Ÿ’ซ Industrial-strength Natural Language Processing (NLP) in Python


            spaCyby explosion

            Python doticon star image 26383 doticonVersion:v3.2.6doticon License: Permissive (MIT)

            ๐Ÿ’ซ Industrial-strength Natural Language Processing (NLP) in Python

                      If you do not have SpaCy that is required to run this code, you can install it by clicking on the above link and copying the pip Install command from the Spacy page in kandi.

                      You can search for any dependent library on kandi like Spacy

                      Environment Tested

                      tested this solution in the following versions. Be mindful of changes when working with other versions.

                      1. The solution is created and tested in Vscode version 1.75.1
                      2. The solution is created in Python 3.7.15. Version
                      3. The solution is tested on Spacy 3.4.3 Version

                      Using this solution, we can able to find Named entities for a sentence using python with the help of Spacy library. This process also facilities an easy to use, hassle free method to create a hands-on working version of code which would help us Named entities in python.


                      1. For any support on kandi solution kits, please use the chat
                      2. For further learning resources, visit the Open Weaver Community learning page.

                      See similar Kits and Libraries