简体   繁体   English

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

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

I am trying to visualise results of an LDA Model using PyLDAvis.我正在尝试使用 PyLDAvis 可视化 LDA Model 的结果。 I have managed to get the graphs to display in jupyter notebook, however, the labels of the keywords describing the topics (on the bar chart) are missing.我设法让图表显示在 jupyter notebook 中,但是,描述主题的关键字标签(在条形图上)丢失了。

Below is an example of the code using dummy data.下面是使用虚拟数据的代码示例。

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这是显示的 plot 的屏幕截图

Here is an example of what it should look like https://nbviewer.jupyter.org/github/bmabey/hacker_news_topic_modelling/blob/master/HN%20Topic%20Model%20Talk.ipynb这是一个应该是什么样子的示例https://nbviewer.jupyter.org/github/bmabey/hacker_news_topic_modelling/blob/master/HN%20Topic%20Model%20Talk.ipynb

I have tried setting local parameter to True but it made no difference.我尝试将本地参数设置为 True 但没有任何区别。 pyLDAvis.enable_notebook(local = True)

I tried saving the output as an html but it produced an empty file.我尝试将 output 保存为 html 但它产生了一个空文件。 pyLDAvis.save_html(plot, 'lda.html')

I'm using python 3.7.1我正在使用 python 3.7.1

Any suggestions?有什么建议么?

.pip install pyLDAvis==2.1.2

I got this problem as well and this helped.我也遇到了这个问题,这有帮助。 Older version of pyLDAvis does not work properly with Jupyter or Colab.旧版本的pyLDAvis不能与 Jupyter 或 Colab 一起正常工作。

I met the same problem and I just use this:我遇到了同样的问题,我只是使用这个:

pyLDAvis.save_html(plot, 'vis.html') pyLDAvis.save_html(绘图,'vis.html')

so the complete visuliazation would be saved in wd as a html file.因此完整的可视化将作为 html 文件保存在 wd 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM