Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 !

like image 872
dubooduboo Avatar asked Nov 07 '18 18:11

dubooduboo


3 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.

like image 143
Major Major Avatar answered Oct 30 '22 12:10

Major Major


Use vector_size instead of sizestrong text

# creating a word to vector model
model_w2v = gensim.models.Word2Vec(
            tokenize_data,
            vector_size=200)
like image 4
Biman Pal Avatar answered Oct 30 '22 12:10

Biman Pal


__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)
like image 1
vencaslac Avatar answered Oct 30 '22 11:10

vencaslac