python gensim_在python中使用gensim的LSI

博主利用Python的gensim库实现潜在语义索引(LSI),在每次添加新文档时更新模型。遇到问题:在连续处理文档时,遇到字典索引错误。尝试解决但未果,寻求帮助。
摘要由CSDN通过智能技术生成

我使用Python的gensim库来做潜在的语义索引。我看了网站上的教程,效果很好。现在我试图对其进行一些修改;每次添加文档时,我都希望运行lsi模型。

这是我的代码:stoplist = set('for a of the and to in'.split())

num_factors=3

corpus = []

for i in range(len(urls)):

print "Importing", urls[i]

doc = getwords(urls[i])

cleandoc = [word for word in doc.lower().split() if word not in stoplist]

if i == 0:

dictionary = corpora.Dictionary([cleandoc])

else:

dictionary.addDocuments([cleandoc])

newVec = dictionary.doc2bow(cleandoc)

corpus.append(newVec)

tfidf = models.TfidfModel(corpus)

corpus_tfidf = tfidf[corpus]

lsi = models.LsiModel(corpus_tfidf, numTopics=num_factors, id2word=dictionary)

corpus_lsi = lsi[corpus_tfidf]

geturl是我编写的函数,它以字符串形式返回网站的内容。同样,如果我在执行tfidf和

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值