[英]gensim Generating LSI model causes “Python has stopped working”
So I am trying to use gensim to generate an LSI model along with corpus_lsi following this tutorial. 因此,在本教程之后,我尝试使用gensim与corpus_lsi一起生成LSI模型。
I start with a corpus and a dictionary that I generated myself. 我从生成自己的语料库和字典开始。 The list of documents are too small (9 lines = 9 documents), which is the sample list provided in gensim tutorials
文档列表太小(9行= 9个文档),这是gensim教程中提供的示例列表
However, pythos just crashes when it reaches the line for generating LSI_model. 但是,当pythos到达生成LSI_model的行时,它就会崩溃。 You can see below my code along with the generated output
您可以在下面的代码以及生成的输出中看到
Code 码
#!/usr/bin/env python
import os
from gensim import corpora, models, similarities
import logging
#logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
if __name__ == '__main__':
if (os.path.exists("tmp\dictionary.dict")):
dictionary = corpora.Dictionary.load('tmp\dictionary.dict')
corpus = corpora.MmCorpus('tmp\corpus.mm')
print("Used files generated Dataset Generator")
else:
print("Please run dataset generator")
print ("generating tf-idf model ...")
tfidf = models.TfidfModel(corpus) # Generate tfidf matrix (tf-idf model)
print ("generating corpus_tf-idf model ...")
corpus_tfidf = tfidf[corpus] #use the model to transform vectors
print ("generating LSI model ...")
lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=2) # initialize an LSI transformation
print ("generating corpus_lsi model ...")
corpus_lsi = lsi[corpus_tfidf] # create a double wrapper over the original corpus: bow->tfidf->fold-in-lsi
lsi.print_topics(2)
Output 输出量
Used files generated Dataset Generator
generating tf-idf model ...
generating corpus_tf-idf model ...
generating LSI model ...
After printing "generating LSI model" it crashes 打印“生成LSI模型”后,它崩溃
Any suggestions ? 有什么建议么 ?
Other things I tried 我尝试过的其他事情
It seems that the issue was the function used in the tutorial (maybe downgraded or something) 看来问题出在本教程中使用的功能(可能降级了)
so I changed the line 所以我换了线
lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=2) # initialize an LSI transformation
To 至
lsi = LsiModel(corpus_tfidf,num_topics=2)
And it actually worked fine 它实际上工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.