Skip to main content

Let us look at a sample code:

>>>from gensim.models import word2vec #let us train a sample model like yours >>>sentences = [['first', 'sentence'], ['second', 'sentence']] >>>model1 = word2vec.Word2Vec(sentences, min_count=1) #let this be the model from which you want to reset >>>sentences = [['third', 'sentence'], ['fourth', 'sentence']] >>>model2 = word2vec.Word2Vec(sentences, min_count=1) >>>model1.reset_from(model2) >>>model1.similarity('third','sentence') -0.064622000988260417 

Hence, we observe that model1model1 is being reset by the model2model2 and hence the word, 'third''third' and 'sentence''sentence' are in it's vocabulary eventually giving its similarity. This is the basic use, you can also check reset_weights()reset_weights() to reset the weights to untrained/initial state.

Let us look at a sample code:

>>>from gensim.models import word2vec #let us train a sample model like yours >>>sentences = [['first', 'sentence'], ['second', 'sentence']] >>>model1 = word2vec.Word2Vec(sentences, min_count=1) #let this be the model from which you want to reset >>>sentences = [['third', 'sentence'], ['fourth', 'sentence']] >>>model2 = word2vec.Word2Vec(sentences, min_count=1) >>>model1.reset_from(model2) >>>model1.similarity('third','sentence') -0.064622000988260417 

Hence, we observe that model1 is being reset by the model2 and hence the word, 'third' and 'sentence' are in it's vocabulary eventually giving its similarity. This is the basic use, you can also check reset_weights() to reset the weights to untrained/initial state.

Let us look at a sample code:

>>>from gensim.models import word2vec #let us train a sample model like yours >>>sentences = [['first', 'sentence'], ['second', 'sentence']] >>>model1 = word2vec.Word2Vec(sentences, min_count=1) #let this be the model from which you want to reset >>>sentences = [['third', 'sentence'], ['fourth', 'sentence']] >>>model2 = word2vec.Word2Vec(sentences, min_count=1) >>>model1.reset_from(model2) >>>model1.similarity('third','sentence') -0.064622000988260417 

Hence, we observe that model1 is being reset by the model2 and hence the word, 'third' and 'sentence' are in it's vocabulary eventually giving its similarity. This is the basic use, you can also check reset_weights() to reset the weights to untrained/initial state.

Source Link
Hima Varsha
  • 2.4k
  • 16
  • 34

Let us look at a sample code:

>>>from gensim.models import word2vec #let us train a sample model like yours >>>sentences = [['first', 'sentence'], ['second', 'sentence']] >>>model1 = word2vec.Word2Vec(sentences, min_count=1) #let this be the model from which you want to reset >>>sentences = [['third', 'sentence'], ['fourth', 'sentence']] >>>model2 = word2vec.Word2Vec(sentences, min_count=1) >>>model1.reset_from(model2) >>>model1.similarity('third','sentence') -0.064622000988260417 

Hence, we observe that model1 is being reset by the model2 and hence the word, 'third' and 'sentence' are in it's vocabulary eventually giving its similarity. This is the basic use, you can also check reset_weights() to reset the weights to untrained/initial state.