Search code examples
pythonjupyter-notebookjupytergoogle-colaboratorydoc2vec

Doc2Vec __init__() got an unexpected keyword argument 'size'


instantiated the Doc2Vec model like this

mv_tags_doc = [TaggedDocument(words=word_tokenize_clean(D), tags=[str(i)]) for i, D in enumerate(mv_tags_corpus)]

max_epochs = 50
vector_size = 20
alpha = 0.025

model = Doc2Vec(size=vector_size,
                alpha=alpha, 
                min_alpha=0.00025,
                min_count=1,
                dm=0)
  
model.build_vocab(mv_tags_doc)

but getting error

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

Solution

  • In the latest version of the Gensim library that you appear to be using, the parameter size is now more consistently vector_size everywhere. See the 'migrating to Gensim 4.0' help page:

    https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#1-size-ctr-parameter-is-now-consistently-vector_size-everywhere

    Separately, if you're consulting any online example with that outdated parameter name, and which also suggested that unnecessary specification of min_alpha and alpha, there's a good chance the example you're following is a bad reference in other ways.

    So, also take a look at this answer: My Doc2Vec code, after many loops of training, isn't giving good results. What might be wrong?