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

问题描述

import pyLDAvis.gensim
# Visualize the topics
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(lda_model,corpus,id2word)
vis

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

当我设置

pyLDAvis.enable_notebook(local=True)

enter image description here 它确实显示结果但不显示标签.. 任何帮助将不胜感激!

解决方法

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

!pip install pyLDAvis==2.1.2

新版本似乎不能很好地与 colab 配合使用。

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