作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在我的 LdaModel 中显示学习进度,但我在网络上找到的每个示例都会引发异常:
l = gensim.models.callbacks.CoherenceMetric(corpus=common_corpus, logger='shell')
lda = gensim.models.ldamodel.LdaModel(doc_term_matrix, num_topics=genres_count, id2word = common_corpus, passes=150, callbacks=[l])
抛出:
File "<ipython-input-165-6ad0e2e8516c>", line 2, in <module>
lda = gensim.models.ldamodel.LdaModel(doc_term_matrix, num_topics=genres_count, id2word = common_corpus, passes=150, callbacks=[l])
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 371, in __init__
self.update(corpus, chunks_as_numpy=use_numpy)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 750, in update
current_metrics = callback.on_epoch_end(pass_)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\callbacks.py", line 288, in on_epoch_end
value = metric.get_value(topics=topics, model=self.model, other_model=self.previous)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\callbacks.py", line 105, in get_value
coherence=self.coherence, topn=self.topn
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\coherencemodel.py", line 190, in __init__
self.window_size = SLIDING_WINDOW_SIZES[self.coherence]
KeyError: None
此代码(找到 here ):
class EpochLogger(CallbackAny2Vec):
'''Callback to log information about training'''
def __init__(self):
self.epoch = 0
def on_epoch_begin(self, model):
print("Epoch #{} start".format(self.epoch))
def on_epoch_end(self, model):
print("Epoch #{} end".format(self.epoch))
self.epoch += 1
l = EpochLogger()
lda = gensim.models.ldamodel.LdaModel(doc_term_matrix, num_topics=genres_count, id2word = common_corpus, passes=150, callbacks=[l])
抛出:
Traceback (most recent call last):
File "<ipython-input-167-e89e2bf41977>", line 1, in <module>
lda = gensim.models.ldamodel.LdaModel(doc_term_matrix, num_topics=genres_count, id2word = common_corpus, passes=150, callbacks=[l])
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 371, in __init__
self.update(corpus, chunks_as_numpy=use_numpy)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 688, in update
callback.set_model(self)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\callbacks.py", line 264, in set_model
if any(metric.logger == "visdom" for metric in self.metrics):
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\callbacks.py", line 264, in <genexpr>
if any(metric.logger == "visdom" for metric in self.metrics):
AttributeError: 'EpochLogger' object has no attribute 'logger'
目前我最感兴趣的是监控学习进度(目测 ETA)。
设置回调的正确方法是什么?
最佳答案
更新自:
l = gensim.models.callbacks.CoherenceMetric(corpus=common_corpus, logger='shell')
到:
l = gensim.models.callbacks.CoherenceMetric(corpus=common_corpus, coherence="u_mass", logger='shell')
“u_mass”只需要一个语料库。
关于python - 如何在 Gensim 的 LdaModel 中记录时代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55694532/
我是一名优秀的程序员,十分优秀!