python启动应用程序错误_运行python程序时出现“应用程序发生异常”的内存错误?...

我写了一个70行左右的python小程序,用来计算文档的相似性。

材料是88篇论文文档,用到了gensim包。

程序的流程是预处理文档(删去不必要的符号,分词等),计算文档的tfidf值,建立88篇论文的tfidf模型以及模型索引。到这里程序运行都是正常的,但是在使用索引的时候,报错:

2d6d0991b1d6247f5f374ee247bb5e2d.png

请问这是什么原因引起的呢?谢谢~

以下是部分运行没有问题的源代码:

#分词:

texts = [[word for word in document.split()]for document in documents]

#利用所有文档,创建词典

dictionary = corpora.Dictionary(texts)

#创建语料

corpus = [dictionary.doc2bow(text) for text in texts]

#利用这些语料,创建tfidf模型

tfidf_model = models.TfidfModel(corpus)

#计算每个文档的tfidf

tfidfs = tfidf_model[corpus]

#创建tfidf的索引

index = similarities.SparseMatrixSimilarity(tfidfs,num_features=88075)

运行这个代码时出现了问题:

#创建目标文档的语料

content = 'A student of music needs as long and as arduous a training to become a performer as a medical student needs to become a doctor'

content = content.lower().split()

test = dictionary.doc2bow(content)

#计算目标文档的tfidf

test_tfidf = tfidf_model[test]

sims = index[test_tfidf]#**就是这一句出现了问题!**

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值