Visualizing topics
In this recipe, we will visualize the LDA topic model that we created in Chapter 6, Topic Modeling. The visualization will allow us to quickly see words that are most relevant to a topic and the distances between topics.
Important note
Please see Chapter 6, Topic Modeling, for how to create the LDA model that we will visualize here.
Getting ready
We will use the pyLDAvis
package to create the visualization. To install it, use the following command:
pip install pyldavis
How to do it…
We will load the model we created in Chapter 6, Topic Modeling and then use the pyLDAvis
package to create the topic model visualization. The visualization is created using a web server:
- Import the necessary packages and functions:
import gensim import pyLDAvis.gensim
- Load the dictionary, corpus, and LDA model created in Chapter 6, Topic Modeling:
dictionary = \ gensim.corpora.Dictionary.load('Chapter06/gensim/id2word.dict') corpus = gensim...