How to train an existing word2vec gensim model on new words? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsNumber of epochs in Gensim Word2Vec implementationHow to retrive the results saved in model of gensim?How to initialize a new word2vec model with pre-trained model weights?Gensim word2vec training error on tweetsWord2vec using gensimHow does Phrases in Gensim work?how to update the pre-trained word2vec model with new train data using genismHow to count number of word embeddings in Gensim Word2Vec modelCan I use Gensim doc2vec model for classification new documents?How would I use Word2Vec model to find similar terms so that I can implement semantic search in some sense

Sci-Fi book where patients in a coma ward all live in a subconscious world linked together

Seeking colloquialism for “just because”

Generate an RGB colour grid

Storing hydrofluoric acid before the invention of plastics

Output the ŋarâþ crîþ alphabet song without using (m)any letters

Align equal signs while including text over equalities

Why did the rest of the Eastern Bloc not invade Yugoslavia?

How to deal with a team lead who never gives me credit?

Why was the term "discrete" used in discrete logarithm?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Resolving to minmaj7

Short Story with Cinderella as a Voo-doo Witch

What's the meaning of 間時肆拾貳 at a car parking sign

Single word antonym of "flightless"

Can a USB port passively 'listen only'?

51k Euros annually for a family of 4 in Berlin: Is it enough?

How to find all the available tools in macOS terminal?

Why is my conclusion inconsistent with the van't Hoff equation?

What causes the vertical darker bands in my photo?

Apollo command module space walk?

The logistics of corpse disposal

How do I stop a creek from eroding my steep embankment?

Coloring maths inside a tcolorbox

Dating a Former Employee



How to train an existing word2vec gensim model on new words?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsNumber of epochs in Gensim Word2Vec implementationHow to retrive the results saved in model of gensim?How to initialize a new word2vec model with pre-trained model weights?Gensim word2vec training error on tweetsWord2vec using gensimHow does Phrases in Gensim work?how to update the pre-trained word2vec model with new train data using genismHow to count number of word embeddings in Gensim Word2Vec modelCan I use Gensim doc2vec model for classification new documents?How would I use Word2Vec model to find similar terms so that I can implement semantic search in some sense










0












$begingroup$


According to gensim docs, you can take an existing word2vec model and further train it on new words.




The training is streamed, meaning sentences can be a generator,
reading input data from disk on-the-fly, without loading the entire
corpus into RAM.



It also means you can continue training the model later:






model = Word2Vec.load("word2vec.model")
model.train([["hello", "world"]], total_examples=1, epochs=1)







Source: docs



But when I actually try it, it doesn't seem to learn the new terms.



from gensim.models import Word2Vec

# initial a model
model = Word2Vec([["cat", "say", "meow"], ["dog", "say", "woof"]], min_count=1)

# count terms in model
print( len(model.wv.vocab) )

=> 5


# train existing model on new terms
model.train([['potoatoes', 'and', 'farmers']], total_examples=model.corpus_count, epochs=model.epochs)

# count terms in model
print( len(model.wv.vocab) )

=> 5


After adding new terms in the 2nd code block, the model still only has the same number of terms as before.



How can I make this work?










share|improve this question









$endgroup$
















    0












    $begingroup$


    According to gensim docs, you can take an existing word2vec model and further train it on new words.




    The training is streamed, meaning sentences can be a generator,
    reading input data from disk on-the-fly, without loading the entire
    corpus into RAM.



    It also means you can continue training the model later:






    model = Word2Vec.load("word2vec.model")
    model.train([["hello", "world"]], total_examples=1, epochs=1)







    Source: docs



    But when I actually try it, it doesn't seem to learn the new terms.



    from gensim.models import Word2Vec

    # initial a model
    model = Word2Vec([["cat", "say", "meow"], ["dog", "say", "woof"]], min_count=1)

    # count terms in model
    print( len(model.wv.vocab) )

    => 5


    # train existing model on new terms
    model.train([['potoatoes', 'and', 'farmers']], total_examples=model.corpus_count, epochs=model.epochs)

    # count terms in model
    print( len(model.wv.vocab) )

    => 5


    After adding new terms in the 2nd code block, the model still only has the same number of terms as before.



    How can I make this work?










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      According to gensim docs, you can take an existing word2vec model and further train it on new words.




      The training is streamed, meaning sentences can be a generator,
      reading input data from disk on-the-fly, without loading the entire
      corpus into RAM.



      It also means you can continue training the model later:






      model = Word2Vec.load("word2vec.model")
      model.train([["hello", "world"]], total_examples=1, epochs=1)







      Source: docs



      But when I actually try it, it doesn't seem to learn the new terms.



      from gensim.models import Word2Vec

      # initial a model
      model = Word2Vec([["cat", "say", "meow"], ["dog", "say", "woof"]], min_count=1)

      # count terms in model
      print( len(model.wv.vocab) )

      => 5


      # train existing model on new terms
      model.train([['potoatoes', 'and', 'farmers']], total_examples=model.corpus_count, epochs=model.epochs)

      # count terms in model
      print( len(model.wv.vocab) )

      => 5


      After adding new terms in the 2nd code block, the model still only has the same number of terms as before.



      How can I make this work?










      share|improve this question









      $endgroup$




      According to gensim docs, you can take an existing word2vec model and further train it on new words.




      The training is streamed, meaning sentences can be a generator,
      reading input data from disk on-the-fly, without loading the entire
      corpus into RAM.



      It also means you can continue training the model later:






      model = Word2Vec.load("word2vec.model")
      model.train([["hello", "world"]], total_examples=1, epochs=1)







      Source: docs



      But when I actually try it, it doesn't seem to learn the new terms.



      from gensim.models import Word2Vec

      # initial a model
      model = Word2Vec([["cat", "say", "meow"], ["dog", "say", "woof"]], min_count=1)

      # count terms in model
      print( len(model.wv.vocab) )

      => 5


      # train existing model on new terms
      model.train([['potoatoes', 'and', 'farmers']], total_examples=model.corpus_count, epochs=model.epochs)

      # count terms in model
      print( len(model.wv.vocab) )

      => 5


      After adding new terms in the 2nd code block, the model still only has the same number of terms as before.



      How can I make this work?







      python word2vec gensim






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 14 mins ago









      tim_xyztim_xyz

      717




      717




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49431%2fhow-to-train-an-existing-word2vec-gensim-model-on-new-words%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49431%2fhow-to-train-an-existing-word2vec-gensim-model-on-new-words%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown