Visualizing the dependency parse
In this recipe, we will learn how to use the displaCy
library and visualize the dependency parse. It shows us the grammatical relations between words in a piece of text, usually a sentence.
Details about how to create a dependency parse can be found in Chapter 2, in the Getting the dependency parse recipe. We will create two visualizations, one for a short text and another for a long multi-sentence text.
After working through this recipe, you will be able to create visualizations of grammatical structures with different options for formatting.
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
is 3.6.1.
The notebook is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/Chapter07/7.1_dependency_parse.ipynb.