编程语言
首页 > 编程语言> > python-gensim-Word2vec在现有模型上继续训练-AttributeError:“ Word2Vec”对象没有属性“ compute_loss”

python-gensim-Word2vec在现有模型上继续训练-AttributeError:“ Word2Vec”对象没有属性“ compute_loss”

作者:互联网

我正在尝试继续在现有模型上进行训练,

model = gensim.models.Word2Vec.load('model/corpus.zhwiki.word.model')
more_sentences = [['Advanced', 'users', 'can', 'load', 'a', 'model', 'and', 'continue', 'training', 'it', 'with', 'more', 'sentences']]    
model.build_vocab(more_sentences, update=True)
model.train(more_sentences, total_examples=model.corpus_count, epochs=model.iter)

但最后一行出现错误:

AttributeError:’Word2Vec’对象没有属性’compute_loss’

一些帖子说,这是由于使用了较早版本的gensim引起的,我尝试在加载现有模型之后且在train()之前添加它.

model.compute_loss = False

之后,它没有给我AttributeError,但是model.train()的输出为0,并且模型没有使用新的句子进行训练.

enter image description here

如何解决这个问题呢?提前致谢.

解决方法:

这是我继续训练模型的方法

# training_data: initial training data. contain list of tokenized sentences
model = Word2Vec(training_data, size=50, window=5, min_count=10, workers=4)

# datasmall: more sentences
# total_examples: number of additional sentence
# epochs: provide your current epochs. model.epochs is ok 
model.train(datasmall, total_examples=len(datasmall), epochs=model.epochs)

标签:gensim,word2vec,nlp,python
来源: https://codeday.me/bug/20191025/1928389.html