为什么 pyLDAvis graph 不在条形图上显示主题关键字?

Why pyLDAvis graph does not display topic keywords on the bar chart?

我正在尝试使用 PyLDAvis 可视化 LDA 模型的结果。我已经设法让图表显示在 jupyter notebook 中,但是,描述主题的关键字标签(在条形图上)丢失了。

下面是使用虚拟数据的代码示例。

import numpy as np
import pandas as pd
import gensim
import gensim.corpora as corpora
import matplotlib.pyplot as plt
import pyLDAvis
import pyLDAvis.gensim 

texts = [['today', 'cold', 'winter', 'lot', 'snow', 'everywhere'],
       ['winter', 'snow', 'snowman'],
       ['summer', 'day', 'sunny', 'lake'],
       ['sunny', 'garden', 'today'],
       ['winter', 'snowing', 'today'],
       ['picnic', 'garden', 'sunny', 'weekend']]

# Create Dictionary
dictionary = corpora.Dictionary(texts)

# Create Corpus
corpus = [dictionary.doc2bow(text) for text in texts]

# Train model
lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
                                           id2word=dictionary,
                                           num_topics=3, 
                                           random_state=100,
                                           update_every=1,
                                           chunksize=100,
                                           passes=10,
                                           alpha='auto',
                                           per_word_topics=True)

# Visualise topics
pyLDAvis.enable_notebook()
plot = pyLDAvis.gensim.prepare(lda_model, corpus, dictionary)
plot

Here is a screenshot of the plot that is displayed

这是它应该是什么样子的一个例子 https://nbviewer.jupyter.org/github/bmabey/hacker_news_topic_modelling/blob/master/HN%20Topic%20Model%20Talk.ipynb

我尝试将本地参数设置为 True,但没有任何区别。 pyLDAvis.enable_notebook(local = True)

我尝试将输出保存为 html,但它生成了一个空文件。 pyLDAvis.save_html(plot, 'lda.html')

我正在使用 python 3.7.1

有什么建议吗?

!pip install pyLDAvis==2.1.2

我也遇到了这个问题,这对我有帮助。 pyLDAvis 的旧版本无法与 Jupyter 或 Colab 一起正常工作。

我遇到了同样的问题,我就用这个:

pyLDAvis.save_html(情节,'vis.html')

因此完整的可视化将作为 html 文件保存在 wd 中。