Visualizing NER
To visualize named entities, we will again use displacy, the same visualization engine that we used for the visualization of dependency parses.
Getting ready
For this recipe, you will need spacy. If you don't have it installed, install it using the following command:
pip install spacy
How to do it…
We will use spacy to parse the sentence and then the displacy engine to visualize the named entities. The steps are as follows:
- Import both
spacyanddisplacy:import spacy from spacy import displacy
- Load the
spacyengine:nlp = spacy.load('en_core_web_sm') - Define the
visualizefunction, which will create the dependency parse visualization:def visualize(doc): colors = {"ORG":"green", "PERSON":"yellow"} options = {"colors": colors} displacy.serve(doc, style='ent', options=options) - Define a...