Visualizing topics from Gensim
In this recipe, we will visualize the Latent Dirichlet Allocation (LDA) topic model that we created in Chapter 6. The visualization will allow us to quickly see words that are most relevant to a topic and the distances between topics.
After working through this recipe, you will be able to load an existing LDA model and create a visualization for its topics, both in Jupyter and saved as an HTML file.
Getting ready
We will use the pyLDAvis
package to create the visualization. It is available in the poetry
environment and the requirements.txt
file.
We will load the model we created in Chapter 6 and then use the pyLDAvis
package to create the topic model visualization.
The notebook is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/Chapter07/7.6_topics_gensim.ipynb.
How to do it...
- Import the necessary packages and functions:
import gensim import pyLDAvis.gensim
...