pyLDAvis visualization from gensim not displaying the result in google colab

12.4k views Asked by At
import pyLDAvis.gensim
# Visualize the topics
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(lda_model, corpus, id2word)
vis

The above code displayed the visualization of LDA model in google colab but then after reopening the notebook it stopped displaying. I even tried pyLDAvis.display(vis, template_type='notebook') still not working

When I set

pyLDAvis.enable_notebook(local=True)

enter image description here

it does display the result but not the labels.. Any help would be appreciated!!

2

There are 2 answers

1
Joshi Chan On

when you install LDAvis make sure to specify the version to be 2.1.2 with:

!pip install pyLDAvis==2.1.2

the new versions don't seem to play well with colab.

3
Hamidreza Hosseinkhani On

they changed the package name. use it like:

import pyLDAvis.gensim_models
vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, id2word)
vis