使用Gensim时报“the array at index 0 has size 1024 and the array at index 1 has size 1023”(没有解决)

这里只是记录一下这个问题。最近又用Gensim+LSI做了一些分类的事情,但是发现如果将LSI中的topic number设置过高,则很有可能会报错,一些示例性的代码如下:

dictionary = corpora.Dictionary(line.lower().split() for line in open(FILE_STRING))
corpus = [dictionary.doc2bow(line.lower().split()) for line in open(FILE_STRING)]
tfidf_model = models.TfidfModel(corpus)
corpus_tfidf = tfidf_model[corpus]
lsi_model = models.LsiModel(corpus_tfidf,id2word=dictionary,num_topics=NUM_TOPICS)
corpus_lsi = lsi_model[corpus_tfidf]


this_corpus=dictionary.doc2bow(this_line.lower().split())#例如这里要对this_line来生成其LSI向量
this_corpus_tfidf=tfidf_model[this_corpus]
this_lsi=lsi_model[this_corpus_tfidf]
print(this_lsi)
vec_list=[]
for each_topic in this_lsi:
    vec_list.append(each_topic[1])
print(len(vec_list))#生成之后发现如果NUM_TOPICS设置得太高,则这里的vector会少一个维度,真的太奇怪了。

如我设置NUM_TOPICS==1024,则很容易报下面的错:

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 1024 and the array at index 1 has size 1023

所以经验是使用LSI时维度不能设置得太高,否则很多训练数据会不可用。也实在不知道原因在哪里,只是觉得很奇怪!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值