简体   繁体   中英

How to fix 'KeyError: dtype('float32')' in LDAviz

I use LDAvis library to visualize my LDA topics. It works fine before, but it gets me this error when I download the saved model files from Sagemaker to the local computer. I don't know why does this happen? Does that relate to Sagemaker?

If I run from the local, and saved the model from local, and then run LDAviz library, it works fine.


KeyError Traceback (most recent call last) in ()

~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\pyLDAvis\\gensim.py in prepare(topic_model, corpus, dictionary, doc_topic_dist, **kwargs) 116 See pyLDAvis.prepare for **kwargs. 117 """ --> 118 opts = fp.merge(_extract_data(topic_model, corpus, dictionary, doc_topic_dist), kwargs) 119 return vis_prepare(**opts)

~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\pyLDAvis\\gensim.py in _extract_data(topic_model, corpus, dictionary, doc_topic_dists) 46 gamma = topic_model.inference(corpus) 47 else: ---> 48 gamma, _ = topic_model.inference(corpus) 49 doc_topic_dists = gamma / gamma.sum(axis=1)[:, None] 50 else:

~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\gensim\\models\\ldamodel.py in inference(self, chunk, collect_sstats) 665 # phinorm is the normalizer. 666 # TODO treat zeros explicitly, instead of adding epsilon? --> 667 eps = DTYPE_TO_EPS[self.dtype] 668 phinorm = np.dot(expElogthetad, expElogbetad) + eps 669

KeyError: dtype('float32')

我知道这已经晚了,但我只是通过将我的 gensim 库从 3.4 更新到对我来说是 3.8 的当前版本来解决类似的问题。

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