如何解决LDA模型一致性得分运行时出错?

问题描述 投票:0回答:1

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.

我应该怎么做才能解决这个问题?

python nlp runtime-error lda topic-modeling
1个回答
0
投票

我也遇到了同样的问题。在if__name__=="中添加 "一致性模型"。"为我解决了这个问题。

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)
© www.soinside.com 2019 - 2024. All rights reserved.