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

Unable to load KeyedVectors models created with gensim==3.2.0: AttributeError: Can't get attribute 'EuclideanKeyedVectors' #2201

Closed
pypt opened this issue Sep 29, 2018 · 2 comments · Fixed by #2457
Assignees
Labels
bug Issue described a bug difficulty medium Medium issue: required good gensim understanding & python skills

Comments

@pypt
Copy link

pypt commented Sep 29, 2018

Description

Hi there,

I can't seem to be able to load trimmed KeyedVectors models created with gensim 3.2.0 with any newer version of gensim (3.3.0 - 3.6.0) because:

AttributeError: Can't get attribute 'EuclideanKeyedVectors' on <module 'gensim.models.keyedvectors' from '/usr/local/lib/python3.7/site-packages/gensim/models/keyedvectors.py'>

Steps/Code/Corpus to Reproduce

To replicate:

  1. Create a model with gensim==3.2.0, convert it to KeyedVectors and then save it:
pip3.7 install -qU gensim==3.2.0
from gensim.models import Word2Vec
from gensim.test.utils import common_texts

model = Word2Vec(common_texts, size=100, window=5, min_count=1, workers=4)
trimmed_model = model.wv
trimmed_model.save('test.word2vec')
  1. Try loading the model with gensim>=3.2.0:
pip3.7 install -qU gensim==3.6.0	# same with 3.3.0, 3.4.0 and 3.5.0 too
from gensim.models import KeyedVectors

word_vectors = KeyedVectors.load('test.word2vec')

Expected Results

Model should get loaded and be functional.

Actual Results

KeyedVectors.load() fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/gensim/models/keyedvectors.py", line 212, in load
    return super(BaseKeyedVectors, cls).load(fname_or_handle, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/gensim/utils.py", line 422, in load
    obj = unpickle(fname)
  File "/usr/local/lib/python3.7/site-packages/gensim/utils.py", line 1361, in unpickle
    return _pickle.load(f, encoding='latin1')
AttributeError: Can't get attribute 'EuclideanKeyedVectors' on <module 'gensim.models.keyedvectors' from '/usr/local/lib/python3.7/site-packages/gensim/models/keyedvectors.py'>

Versions

>>> import platform; print(platform.platform())
Darwin-18.0.0-x86_64-i386-64bit
>>> import sys; print("Python", sys.version)
Python 3.7.0 (default, Sep 18 2018, 18:47:08) 
[Clang 10.0.0 (clang-1000.10.43.1)]
>>> import numpy; print("NumPy", numpy.__version__)
NumPy 1.15.2
>>> import scipy; print("SciPy", scipy.__version__)
SciPy 1.1.0
>>> import gensim; print("gensim", gensim.__version__)
gensim 3.6.0
>>> from gensim.models import word2vec;print("FAST_VERSION", word2vec.FAST_VERSION)
FAST_VERSION 0
@menshikh-iv
Copy link
Contributor

menshikh-iv commented Oct 1, 2018

@pypt thanks for the report: reproduced (python2, gensim 3.2.0 + 3.6.0), looks like this can be related to #1777 again, argh @manneshiva.

@menshikh-iv menshikh-iv added the difficulty medium Medium issue: required good gensim understanding & python skills label Oct 1, 2018
@mpenkov
Copy link
Collaborator

mpenkov commented Apr 20, 2019

Still reproducible with 3.7.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue described a bug difficulty medium Medium issue: required good gensim understanding & python skills
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants