TypeError:重新加载Gensim模型时'float'对象不可下标

时间:2019-05-25 22:30:19

标签: python nlp save gensim

我正在训练一个短语模型,以使用Gensim识别大型语料库上的双字母组。重新加载模型时,出现以下错误:

  

TypeError:“浮动”对象不可下标

我保存模型(以及训练)的代码如下:

from gensim.models.phrases import Phrases, Phraser
def train_bigram(corpus):
    sentence_stream = [doc.split(" ") for doc in corpus]
    bigram_model = Phrases(sentence_stream, min_count=180, threshold=3.5)
    return bigram_model

print("train bigram on cleaned text")
phrases = train_bigram(corpus_cleaned)
print("Build faster model for Gensim")
bigram = Phraser(phrases)  # construct faster model (this is only an wrapper)
# Store the bigram model
bigram.save(path_to_save + "bigram"

当我必须重新加载模型时,我会做什么?目前,我正在使用以下内容: bigram_reloaded = Phraser.load(path_to_save + 'bigram')

但是在这种情况下,我得到了之前显示的错误。关于解决方法有什么想法或提示吗?

0 个答案:

没有答案