did*_*isy 5 python nlp gensim word2vec
我正在尝试继续在现有模型上进行训练,
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)
Run Code Online (Sandbox Code Playgroud)
但最后一行出现错误:
AttributeError:'Word2Vec'对象没有属性'compute_loss'
一些帖子说,这是由于使用了较早版本的gensim引起的,我尝试在加载现有模型之后且在train()之前添加它。
model.compute_loss = False
Run Code Online (Sandbox Code Playgroud)
之后,它没有给我AttributeError,但是model.train()的输出为0,并且模型没有使用新的句子进行训练。
如何解决这个问题呢?
这是我如何继续训练我的模型
# 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)
Run Code Online (Sandbox Code Playgroud)
total_examples( 和epochs) 参数应train()与您当前在more_sentences\xe2\x80\x93 中提供的内容相匹配,而不是先前训练的剩余值。
例如,假设您的代码仅显示一个附加句子,您可以指定total_examples=1.
如果这不是问题的根源,请仔细检查是否more_sentences是您在通话时所期望的情况train()。
| 归档时间: |
|
| 查看次数: |
2519 次 |
| 最近记录: |