pyLDAvis .show function asks for missing .css file in Jupyter notebook

2.5k views Asked by At
import pyLDAvis
import pyLDAvis.gensim
pyLDAvis.enable_notebook()
LDAvis_prepared = pyLDAvis.gensim.prepare(lda_model, bow_corpus, dictionary)
pyLDAvis.show(LDAvis_prepared)

This is a very simple visualization however, when I ran the show command, an error popped up:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-152-64a947f66dc2> in <module>
----> 1 pyLDAvis.show(LDAvis_prepared)

/opt/anaconda3/lib/python3.7/site-packages/pyLDAvis/_display.py in show(data, ip, port, n_retries, local, open_browser, http_server, **kwargs)
    262                  open(urls.LDAVIS_LOCAL, 'r').read()],
    263                  '/LDAvis.css': ["text/css",
--> 264                                  open(urls.LDAVIS_CSS_URL, 'r').read()],
    265                  '/d3.js': ["text/javascript",
    266                             open(urls.D3_URL, 'r').read()]}

FileNotFoundError: [Errno 2] No such file or directory: 'https://cdn.rawgit.com/bmabey/pyLDAvis/files/ldavis.v1.0.0.css'

I searched online unfortunately, not much information on this error. However if I clicked on the .ccs link, I could still view this css file.
I even saved the display as a HTML file but it's a blank page (content is not rendered for some reasons)

pyLDAvis.save_html(LDAvis_prepared,'sss.html')

1

There are 1 answers

1
jwang421 On BEST ANSWER

Try to specify the version of pyLDAvis to 2.1.2

!pip install pyLDAvis==2.1.2

and use pyLDAvis.display() instead of pyLDAvis.show()

topic_data =  pyLDAvis.gensim.prepare(ldamodel, doc_term_matrix, dictionary, mds = 'pcoa', sort_topics=True)
pyLDAvis.display(topic_data)

This solved the same problem on my machine.