来自gensim的pyLDAvis可视化未在google colab中显示结果

Rav*_*ati 3 visualization lda gensim pyldavis

import pyLDAvis.gensim
# Visualize the topics
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(lda_model, corpus, id2word)
vis
Run Code Online (Sandbox Code Playgroud)

上面的代码在 google colab 中显示了 LDA 模型的可视化,但在重新打开笔记本后它停止显示。我什至试过 pyLDAvis.display(vis, template_type='notebook') 还是不行

当我设置

pyLDAvis.enable_notebook(local=True)

在此处输入图像描述 它确实显示结果但不显示标签.. 任何帮助将不胜感激!

小智 7

安装 LDAvis 时,请确保将版本指定为 2.1.2:

!pip install pyLDAvis==2.1.2
Run Code Online (Sandbox Code Playgroud)

新版本似乎不太适合 colab。


Ham*_*ani 5

他们更改了包名称。像这样使用它:

import pyLDAvis.gensim_models
vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, id2word)
vis
Run Code Online (Sandbox Code Playgroud)

  • 仅代码答案并不是特别有帮助。请添加一些有关此代码如何解决问题的描述。 (2认同)