Skip to content
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

'Word2VecKeyedVectors' object has no attribute 'vectors' #1994

Open
lzfelix opened this issue Mar 22, 2018 · 17 comments
Open

'Word2VecKeyedVectors' object has no attribute 'vectors' #1994

lzfelix opened this issue Mar 22, 2018 · 17 comments
Assignees
Labels
bug Issue described a bug

Comments

@lzfelix
Copy link

lzfelix commented Mar 22, 2018

I have a word2vec model which I was able to load into Gensim, normalize and retrieve word vectors with model.init_sims(replace=True) and model[word] previously. After updating to gensim 3.4.0 I'm receiving the following error messages for these operations:

Traceback (most recent call last):
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-13-4a9edd1d9ae5>", line 1, in <module>
    vsm.init_sims()
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/gensim/models/keyedvectors.py", line 1048, in init_sims
    self.vectors_norm = (self.vectors / sqrt((self.vectors ** 2).sum(-1))[..., newaxis]).astype(REAL)
AttributeError: 'Word2VecKeyedVectors' object has no attribute 'vectors'

and

Traceback (most recent call last):
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-b955394cb092>", line 1, in <module>
    vsm['oi']
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/gensim/models/keyedvectors.py", line 169, in __getitem__
    return self.get_vector(entities)
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/gensim/models/keyedvectors.py", line 277, in get_vector
    return self.word_vec(word)
  File "/Users/lzfelix/anaconda3/envs/mirror/lib/python3.5/site-packages/gensim/models/keyedvectors.py", line 269, in word_vec
    result = self.vectors[self.vocab[word].index]
AttributeError: 'Word2VecKeyedVectors' object has no attribute 'vectors'

This seems related to the issues caused by the vector models re-implementation #1777, similarly to #1882 and #1952. Unfortunately I can't provide the binary file.

Thank you,
Luiz Felix

@piskvorky piskvorky added the bug Issue described a bug label Mar 22, 2018
@menshikh-iv
Copy link
Contributor

menshikh-iv commented Mar 24, 2018

Hello @lzfelix, can you say, what's gensim version you used before for training/saving of your model?t
Also, if possible, please provide code that you used for training/saving.

@lzfelix
Copy link
Author

lzfelix commented Mar 26, 2018

Hi @menshikh-iv, a colleague of mine has trained the model, so I'm not completely sure about the details. I know that it was trained using word2vec C implementation from Google and then I converted it to gensim binary format using gensim 3.1.0.

@menshikh-iv
Copy link
Contributor

@lzfelix thanks for the info

@lzfelix
Copy link
Author

lzfelix commented Mar 26, 2018

@menshikh-iv, sure! Anything that I can help!

@menshikh-iv
Copy link
Contributor

related issue #2000

@lzfelix
Copy link
Author

lzfelix commented Apr 1, 2018

Thanks a lot, @menshikh-iv, I'll start tracking the other issue, which already has a pull request referencing it. Maybe you can close this issue for now just to keep things in one place.

@menshikh-iv
Copy link
Contributor

menshikh-iv commented Apr 1, 2018

PR with the fix - #2012, @lzfelix I'll close issues when a fix will be merged to develop.

@manneshiva
Copy link
Contributor

@menshikh-iv This issue may or may not be related to #2012. @lzfelix Can you please outline the steps to reproduce this issue? More specifically, provide the file/similar file that you are trying to load and the code using which you are loading the file. Thanks.

@lzfelix
Copy link
Author

lzfelix commented Apr 1, 2018

Hi @manneshiva, after loading a word2vec binary (details on this later), I get the following error message if I try to pre-compute vectors similarity with model.init_sims(replace=True) or even retrieve a word-vector with model[word]. Namely:

model = KeyedVectors.load(constants.DEFAULT_WORD2VEC_PATH)
model.init_sims(replace=True)   # < error happens here
vector = model['banana']        # < or here if the previous line is not used.

Details on the model: This binary file was obtained from a model trained with Google's word2vec C code and then converted to Gensim format. Since it's being used for a private project, I might only be able to share the model with you through some private mean, ie: Google Drive link via e-mail.

@menshikh-iv
Copy link
Contributor

@lzfelix please sent me a link to [email protected] (don't worry, we will not share your file).

@lzfelix
Copy link
Author

lzfelix commented Apr 15, 2018

HI @menshikh-iv, thank you. I have just sent the email.

@menshikh-iv
Copy link
Contributor

@lzfelix reproduced, thanks! We'll fix it.

@lzfelix
Copy link
Author

lzfelix commented Apr 15, 2018

Great! Thanks a lot.

@rachhitgarg
Copy link

what if i want to update the model loaded with syntax (gensim.models.KeyedVectors.load_word2vec_format) by new sentences
I tried : showing error

model.build_vocab(more_sentences, update=True)
AttributeError: 'Word2VecKeyedVectors' object has no attribute 'build_vocab'

@menshikh-iv
Copy link
Contributor

@rachhitgarg load_word2vec_format returns only vectors (not full model), you can't continue training, see https://radimrehurek.com/gensim/models/keyedvectors.html

@nikita-smetanin
Copy link

Any progress on this bug?

@lzfelix
Copy link
Author

lzfelix commented Jun 18, 2019

Not that I am aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue described a bug
Projects
None yet
Development

No branches or pull requests

7 participants