python - 如何修复 LDA 模型一致性得分运行时错误?
问题描述
text='Alice 是一名学生。她喜欢学习。老师们给了很多家庭作业。'
我正在尝试从具有连贯性分数的简单文本(如上)中获取主题。这是我的 LDA 模型:
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)
我应该得到这个输出之王->连贯性分数:0.532947587081
我收到此错误: 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.
我应该怎么做才能解决这个问题?
解决方案
我遇到了同样的问题。在 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)
推荐阅读
- python-3.x - 如何通过beautifulsoup4将抓取的数据上传到csv文件
- video - 使用 FFmpeg 添加 2 个带有 scale2ref 40% 视频宽度和超时的水印
- node.js - 既然 appcfg 不见了,就从 app_engine 下载源代码?
- karate - 空手道 - 仅对引用的对象进行模式验证,默认情况下忽略未引用的对象
- android - DrawerLayout 内的 constraintLayout 内的 RecyclerView 不会滚动
- javascript - 是否可以在没有所有参数的情况下调用/等待异步函数?
- react-admin - 如果我想在过滤器和列表之间添加一些信息文本怎么办?
- assembly - 调用 printf 在使用 gcc 编译的程序集中产生分段错误、核心转储错误
- python - 如何检查 Python 脚本安装了哪些模块
- python - 如何使用另一个文件作为 azure 函数的输入参数运行 python 脚本?