python - gensim 生成LSI模型导致 "Python has stopped working"

标签 python python-3.x gensim latent-semantic-indexing latent-semantic-analysis

所以我尝试使用 gensim 和 corpus_lsi 一起生成 LSI 模型,如下 this教程。

我从自己生成的语料库和字典开始。 文档列表太小(9行=9个文档),这是gensim中提供的示例列表教程

但是,当 pythos 到达生成 LSI_model 的行时就会崩溃。 您可以在下面看到我的代码以及生成的输出

代码

#!/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)

输出

Used files generated Dataset Generator
generating tf-idf model ...
generating corpus_tf-idf model ...
generating LSI model ...

打印“生成LSI模型”后崩溃

有什么建议吗?

我尝试过的其他事情

  • 将 python 版本更改为 python 2.6
  • 删除 gensim 并从 github 重新安装(而不是 conda)

最佳答案

问题似乎出在教程中使用的函数(可能是降级或其他什么)

所以我改变了路线

lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=2) # initialize an LSI transformation

lsi = LsiModel(corpus_tfidf,num_topics=2)

实际上效果很好

关于python - gensim 生成LSI模型导致 "Python has stopped working",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40205725/

相关文章:

python - 为什么 string.maketrans 在 Python 3.1 中不起作用?

python - 停止句子标记器在 "no."缩写上分割句子

python - 在 RaspberryPi 上使用 Flask 应用程序出现 500 错误

python - 我如何将数据从数据框(在 python 中)插入到 greenplum 表?

Python 错误 : 'float' object is not iterable

python - Gensim Doc2Vec 为模型生成大文件

machine-learning - 分类 LDA 与 TFIDF

python - 在大文本文件中查找重复记录

python - Pygame 没有在窗口中显示任何内容

python-3.x - Django 项目中的多个应用程序