简体   繁体   中英

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

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')

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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