yinky
yinky

Reputation: 59

TypeError: __init__() got an unexpected keyword argument 'size'

This is my code below and the error I have is beneath it but I cant figure out why this is happening. Please share your thoughts

from gensim.models import word2vec
np.set_printoptions(suppress=True)

feature_size = 150
context_size= 2
min_word = 1
word_vec= word2vec.Word2Vec(tokenized, size=feature_size, \
                            window=context_size, min_count=min_word, \
                            iter=50, seed=42)



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-59-dbe3a4fa3884> in <module>
      5 context_size= 2
      6 min_word = 1
----> 7 word_vec= word2vec.Word2Vec(tokenized, size=feature_size, \
      8                             window=context_size, min_count=min_word, \
      9                             iter=50, seed=42)

TypeError: __init__() got an unexpected keyword argument 'size'

Upvotes: 6

Views: 21173

Answers (2)

george mano
george mano

Reputation: 6178

You should downgrade to gensim version 3.8

Upvotes: 0

555wen
555wen

Reputation: 179

I have met the same problem and solved it by looking up the Word2Vec embedding documentation. Notice there are two changes in parameters in new Gensim:

[1] size -> vector_size
[2] iter -> epochs

Here is a code example from the documentation:

from gensim.test.utils import common_texts
from gensim.models import Word2Vec

model = Word2Vec(sentences=common_texts, vector_size=100, window=5, min_count=1, workers=4)
model.save("word2vec.model")
model = Word2Vec.load("word2vec.model")
model.train([["hello", "world"]], total_examples=1, epochs=1)

Upvotes: 15

Related Questions