在更新gensim的LdaModel时,我面临以下错误:
IndexError:对于尺寸为6614的轴1,索引6614超出了界限。
我检查了为什么其他人在这条线上有这个问题,但我从一开始到最后都使用同一本字典,这是他们的错误。
因为我有一个很大的数据集,所以我正在逐块地加载它(使用pickle.load)。我正在以这种方式构建字典,迭代地,多亏了这段代码:
fr_documents_lda = open("documents_lda_40_rails_30_ruby_full.dat", 'rb')
dictionary = Dictionary()
chunk_no = 0
while 1:
try:
t0 = time()
documents_lda = pickle.load(fr_documents_lda)
chunk_no += 1
dictionary.add_documents(documents_lda)
t1 = time()
print("Chunk number {0} took {1:.2f}s".format(chunk_no, t1-t0))
except EOFError:
print("Finished going through pickle")
break一旦为整个数据集构建,我将以同样的方式对模型进行训练,迭代的方式如下:
fr_documents_lda = open("documents_lda_40_rails_30_ruby_full.dat", 'rb')
first_iter = True
chunk_no = 0
lda_gensim = None
while 1:
try:
t0 = time()
documents_lda = pickle.load(fr_documents_lda)
chunk_no += 1
corpus = [dictionary.doc2bow(text) for text in documents_lda]
if first_iter:
first_iter = False
lda_gensim = LdaModel(corpus, num_topics=no_topics, iterations=100, offset=50., random_state=0, alpha='auto')
else:
lda_gensim.update(corpus)
t1 = time()
print("Chunk number {0} took {1:.2f}s".format(chunk_no, t1-t0))
except EOFError:
print("Finished going through pickle")
break我还试着在每个块上更新字典,也就是对每个块进行更新。
dictionary.add_documents(documents_lda)就在此之前
corpus = [dictionary.doc2bow(text) for text in documents_lda]在最后一段代码中。最后,我尝试将allow_update参数doc2bow设置为True。毫无办法。
FYI,我最后一本字典的大小是85k。我的字典仅由第一大块建成,大小为10k。该错误发生在第二次迭代中,当它在其他条件下传递时,当调用update方法时。
错误由行expElogbetad = self.expElogbeta[:, ids]引发,由gamma, sstats = self.inference(chunk, collect_sstats=True)调用,由gammat = self.do_estep(chunk, other)调用,由lda_gensim.update(corpus)调用。
有没有人知道如何解决这个问题,或者正在发生什么?
提前谢谢你。
https://stackoverflow.com/questions/50214899
复制相似问题