-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'Doc2Vec' object has no attribute 'syn0' when call infer_vector #785
Comments
@xchangcheng can you explain your fix / reason for closing? Other people may google up this issue in the future. |
@piskvorky Sorry for closing it before. As in the #483, I found that when I tried to load my model, I haven't loaded syn0 & syn1 successfully. I think the model I have trained before may have some problems. So I retrained it and the problem gone. The following may be the output for a successful loading :) 2016-07-12 17:22:28,782 - gensim.utils - INFO - loading Doc2Vec object from ./imdb.d2v |
I'm having a similar problem. I'm not sure exactly what steps are required to reproduce it because it doesn't seem to happen every time. I have a script which trains a model on about 700,000 paragraphs, with a vocabulary of about 100,000 words and then immediately saves the trained model using model.save(). When I just run one epoch, everything works fine: The syn0 and syn1 matrices are saved and I can load the model and compute similarities. But every time I have trained the model with a larger number of epochs (I'm trying 20. This takes a while so I have only done it a handful of times), the syn0 and syn1 matrices are not saved. Furthermore, after trying to save, the model object no longer has syn0 or syn1 properties, so if I try to train it again, I get "RuntimeError: you must first finalize vocabulary before training the model". I don't know if the number of epochs is making a difference or if it is just a coincidence... This is the most relevant part of my code:
(My paragraphs object contains both a string and tag for each paragraph, so the shuffle isn't mixing those up) |
The number of epochs shouldn't affect saving at all: the structures have the same size/shape no matter how much training has occurred. If a I suggest making sure you're using the latest gensim, enabling logging to the INFO level, and extending your code example to confirm the expected existence of Unrelated notes about your code: by supplying a corpus to the Doc2Vec constructor, training will automatically occur. And, by a default |
Closing as abandoned |
I trained a model with the corpus, and saved it to the disk by:
mode.save(filename)
Then I load the model and try to call the 'infer_vector' to calculate the vector of a new sentence by:
model = Doc2Vec.load(filename)
words = ['This', 'is', 'an', 'example']
model.infer_vector(words)
However, I get an exception as:
AttributeError: 'Doc2Vec' object has no attribute 'syn0'
How can I fixed this? The same reason like #483 ?
Thanks
The text was updated successfully, but these errors were encountered: