[英]How to fix LDA model coherence score runtime Error?
text='Alice is a student.She likes studying.Teachers are giving a lot of homewok.' text='爱丽丝是一名学生。她喜欢学习。老师们给了很多家庭作业。'
id2word = corpora.Dictionary(data_lemmatized)
texts = data_lemmatized
corpus = [id2word.doc2bow(text) for text in texts]
lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
id2word=id2word,
num_topics=5,
random_state=100,
update_every=1,
chunksize=100,
passes=10,
alpha='auto',
per_word_topics=True)
# Print the Keyword in the 10 topics
pprint(lda_model.print_topics())
doc_lda = lda_model[corpus]
coherence_model_lda = CoherenceModel(model=lda_model, texts=data_lemmatized, dictionary=id2word,
coherence='c_v')
coherence_lda = coherence_model_lda.get_coherence()
print('\nCoherence Score: ', coherence_lda)
I get this error: raise RuntimeError(''' RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.我收到此错误: raise RuntimeError(''' RuntimeError: 在当前进程完成其引导阶段之前已尝试启动新进程。
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
What should i do to fix this?我应该怎么做才能解决这个问题?
I have faced the same issue.我遇到了同样的问题。 Adding 'Coherence Model' inside if__name__==" main " resolved the issue for me.
在 if__name__==" main " 中添加“一致性模型”为我解决了这个问题。
if __name__ == "__main__":
coherence_model_lda = CoherenceModel(model=lda_model, texts=data_lemmatized,
dictionary=id2word,
coherence='c_v')
coherence_lda = coherence_model_lda.get_coherence()
print('\nCoherence Score: ', coherence_lda)
I'm having the same issue when running gensim Nmf and the way to fix it was to change from coherence='c_v' to coherence='u_mass'我在运行 gensim Nmf 时遇到了同样的问题,修复它的方法是从 coherence='c_v' 更改为 coherence='u_mass'
You can use coherence='c_v' without problem.您可以毫无问题地使用 coherence='c_v' 。 My answer is quite similar to AKHILA one.
我的回答与 AKHILA 非常相似。 But I call freeze_support() in the main process and start the method with support for Windows.
但我在主进程中调用 freeze_support() 并启动支持 Windows 的方法。
Consider the structure from the beginning:从头考虑结构:
# imports
from multiprocessing import Process, freeze_support
import ...
# general constants and variables
...
# functions definition
def ...
...
def ...
...
# main function
def principal(): # can be another name
...
...
if __name__ == '__main__':
freeze_support()
Process(target=main).start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.