簡體   English   中英

如何修復 LDA model 一致性分數運行時錯誤?

[英]How to fix LDA model coherence score runtime Error?

text='愛麗絲是一名學生。她喜歡學習。老師們給了很多家庭作業。'

我正在嘗試從具有一致性分數的簡單文本(如上)獲取主題。這是我的 LDA model:

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]

當我嘗試運行此一致性 model 時:

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)

我在運行 gensim Nmf 時遇到了同樣的問題,修復它的方法是從 coherence='c_v' 更改為 coherence='u_mass'

您可以毫無問題地使用 coherence='c_v' 。 我的回答與 AKHILA 非常相似。 但我在主進程中調用 freeze_support() 並啟動支持 Windows 的方法。

從頭考慮結構:

# 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM