Visualizing NER
Named entity recognition, or NER, is a very useful tool for quickly finding people, organizations, locations, and other entities in texts. In order to visualize them better, we can use the displacy package to create compelling and easy-to-read images.
After working through this recipe, you will be able to create visualizations of named entities in a text using different formatting options and save the results in a file.
Getting ready
The displaCy library is part of the spacy package. You need at least version 2.0.12 of the spacy package for displaCy to work. The version in the poetry environment and requirements.txt file is 3.6.1.
The notebook is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/Chapter07/7.3_ner.ipynb.
How to do it...
We will use spacy to parse the sentence and then the displacy engine to visualize the named entities:
- Import both
spacyanddisplacy:import spacy...