Getting "__init__() got an unexpected keyword argument 'document'" this error in python I'm working with Word2Vec and gensim

Viewed 23474

I'm working on project using Word2vec and gensim,

model = gensim.models.Word2Vec(
    documents = 'userDataFile.txt',
    size=150,
    window=10,
    min_count=2,
    workers=10)
model = gensim.model.Word2Vec.load("word2vec.model")
model.train(documents, total_examples=len(documents), epochs=10)
model.save("word2vec.model")

this is the part code that I have at the moment, and I'm getting this error below

Traceback (most recent call last):
File "C:\Users\User\Desktop\InstaSubProject\templates\HashtagData.py", line

37, in <module>
workers=10)
TypeError: __init__() got an unexpected keyword argument 'documents'

UserDataFile.txt is the file that I stored output result data that I got from web scraping.

I'm not really sure what I need to fix here.

Thank you in advance !

4 Answers

The year is 2021 and if you're here for the same reason I am, it's because you're getting the same error on the size parameter.

You need to use vector_size instead.

Use vector_size instead of sizestrong text

# creating a word to vector model
model_w2v = gensim.models.Word2Vec(
            tokenize_data,
            vector_size=200)

__init__() is the class constructor for Word2Vec, it is possible that when you instantiated the class with gensim.models.Word2Vec(), that the parameter documents is not actually necessary

try this instead:

model = gensim.models.Word2Vec(
    size=150,
    window=10,
    min_count=2,
    workers=10)

Looks like that model doesn't take the keyword parameter documents on initialization. I think you could try either of these in replacement of your documents= statement:

corpus_file = 'userDataFile.txt'

or

sentences = # your iterable of sentences here

Depending on the format of what you're working with

Related