Visualizing parts of speech
In this recipe, we visualize part of speech counts. Specifically, we count the number of infinitives and past or present verbs in the book The Adventures of Sherlock Holmes. This can give us an idea about whether the text mostly talks about past or present events. We could imagine that similar tools could be used to evaluate the quality of a text; for example, a book with very few adjectives but many nouns would not work very well as a fiction book.
After working through this recipe, you will be able to use the matplotlib
package to create bar plots of different verb types, which are tagged using the spacy
package.
Getting ready
We will use the spacy
package for text analysis and the matplotlib
package to create the graph. They are part of the poetry
environment and the requirements.txt
file.
The notebook is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/Chapter07/7.2_parts_of_speech...