7
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!!

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
Ravi Prajapati
  • 71
  • 1
  • 1
  • 4

2 Answers2

7

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.

Joshi Chan
  • 71
  • 1
5

they changed the package name. use it like:

import pyLDAvis.gensim_models
vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, id2word)
vis
  • 2
    Code-only answers are not particularly helpful. Please add some descriptions of how this code solves the problem. – 4b0 Aug 01 '21 at 12:38
  • @Shree kidding?! It's obvious! they changed the package name! – Hamidreza Hosseinkhani Aug 02 '21 at 14:08
  • 1
    If they just mislabeled the package, then maybe it should be closed as a typo. But that's not obvious from your answer without any explanation. Take a look again at [answer] – camille Aug 03 '21 at 01:33