1
votes

I am trying to use a pre-trained model and add additional vocabulary to it. I have a csv file with 1 column of sentences in it.

import gensim

existing_model_fr = gensim.models.Word2Vec.load('./fr/fr.bin')

new_sentences = gensim.models.word2vec.LineSentence('./data/french.csv')
existing_model_fr.build_vocab(new_sentences, update=True)

existing_model_fr.train(new_sentences, total_examples=existing_model_fr.corpus_count, epochs=5)
existing_model_fr.save('new_model_fr')

I get following error on existing_model_fr.train() line. What am I missing?

AttributeError Traceback (most recent call last) in ()

/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py in train(self, sentences, total_examples, total_words, epochs, start_alpha, end_alpha, word_count, queue_factor, report_delay, compute_loss) 863 is only called once, the model's cached iter value should be supplied as epochs value. 864 """ --> 865 if self.model_trimmed_post_training: 866 raise RuntimeError("Parameters for training were discarded using model_trimmed_post_training method") 867 if FAST_VERSION < 0:

AttributeError: 'Word2Vec' object has no attribute 'model_trimmed_post_training'

1

1 Answers

1
votes

It's likely you're loading a model from a earlier version of gensim where the property model_trimmed_post_training wasn't defined. You can likely work around the issue by setting the property yourself, after loading but before train():

existing_model_fr. model_trimmed_post_training = false