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

'FastTextTrainables' object has no attribute 'vectors' #2062

Closed
rpedela opened this issue May 25, 2018 · 9 comments · Fixed by #2313
Closed

'FastTextTrainables' object has no attribute 'vectors' #2062

rpedela opened this issue May 25, 2018 · 9 comments · Fixed by #2313
Assignees
Labels
bug Issue described a bug difficulty medium Medium issue: required good gensim understanding & python skills fasttext Issues related to the FastText model

Comments

@rpedela
Copy link

rpedela commented May 25, 2018

Using the pre-trained FastText English Wikipedia model, I load it and then save it to gensim's format. When I load the new file, I get a 'FastTextTrainables' object has no attribute 'vectors' error. I am using version 3.4.0.

from gensim.models import FastText
model = FastText.load_fasttext_format('./wiki.en.bin')
model.save('./gensim_en_fasttext_wiki_lg')
new_model = FastText.load('./gensim_en_fasttext_wiki_lg')

Saved Files

gensim_en_fasttext_wiki_lg
gensim_en_fasttext_wiki_lg.wv.vectors_ngrams.npy
gensim_en_fasttext_wiki_lg.wv.vectors.npy

Error

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/fasttext.py", line 718, in load
    model.trainables.vectors_vocab_lockf = ones(len(model.trainables.vectors), dtype=REAL)
AttributeError: 'FastTextTrainables' object has no attribute 'vectors'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cluster_vectors.py", line 26, in <module>
    new_model = FastText.load('./gensim_en_fasttext_wiki_lg')
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/fasttext.py", line 725, in load
    return load_old_fasttext(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/deprecated/fasttext.py", line 53, in load_old_fasttext
    old_model = FastText.load(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/deprecated/word2vec.py", line 1616, in load
    model = super(Word2Vec, cls).load(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/deprecated/old_saveload.py", line 87, in load
    obj = unpickle(fname)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/deprecated/old_saveload.py", line 380, in unpickle
    return _pickle.loads(file_bytes, encoding='latin1')
AttributeError: Can't get attribute 'FastTextVocab' on <module 'gensim.models.deprecated.fasttext' from '/usr/local/lib/python3.5/dist-packages/gensim/models/deprecated/fasttext.py'>
@mcharrak
Copy link

Same issue here, why does it save 3 different files and why do we get his error message? Pushing please!

@piskvorky
Copy link
Owner

CC @manneshiva

@mcharrak
Copy link

mcharrak commented Jun 11, 2018

This is how my case looks like and the following error message (demonstrating from within iPython console):

In [1]: from gensim.models.fasttext import FastText as FT_gensim

In my directory I do have both files "wiki.en.vec" and "wiki.en.bin".

In [2]: %%time model = FT_gensim.load_fasttext_format("wiki.en")
CPU times: user 5min 47s, sys: 27.3 s, total: 6min 14s
Wall time: 6min 28s

Note: I takes extremely long to load the model in the first place. It is really annoying is that normal? What is the binary file there for, loading the gensim binary file which I generated from first reading the .vec file and than saving as Word2Vec gensim format only takes 45secs BUT it is not able to handle OOV words, therefore I really need to be able to load this model with the method showed below as I thought it should be way faster to load ones the model was build and saved.

In [3]: print(model)
FastText(vocab=2519370, size=300, alpha=0.025)
In [4]: %%time model.save("saved_model")
CPU times: user 8.58 s, sys: 7.73 s, total: 16.3 s
Wall time: 17.2 s
In [5]: ls | grep saved_model
saved_model
saved_model.wv.vectors.npy
saved_model.wv.vectors_ngrams.npy

Why the hell does it generate 3 files?! Can you guys please explain the reason behind that? I really do not understand this!

In [6]: %%time loaded_model = FT_gensim.load("saved_model")
Traceback (most recent call last):

  File "<timed exec>", line 1, in <module>

  File "/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/fasttext.py", line 725, in load
    return load_old_fasttext(*args, **kwargs)

  File "/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/deprecated/fasttext.py", line 53, in load_old_fasttext
    old_model = FastText.load(*args, **kwargs)

  File "/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/deprecated/word2vec.py", line 1616, in load
    model = super(Word2Vec, cls).load(*args, **kwargs)

  File "/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/deprecated/old_saveload.py", line 87, in load
    obj = unpickle(fname)

  File "/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/deprecated/old_saveload.py", line 380, in unpickle
    return _pickle.loads(file_bytes, encoding='latin1')

AttributeError: Can't get attribute 'FastTextVocab' on <module 'gensim.models.deprecated.fasttext' from '/anaconda2/envs/tf/lib/python3.5/site-packages/gensim/models/deprecated/fasttext.py'>

Side notes:

  1. For what reason does the loading function want to access gensim/models/deprecated/old_saveload.py ? I do not understand this and I think this might somehow be correlated with the error message...
    2.Error message comes not instantly but only after the command is already running for around 15 secs.

Thanks @piskvorky and @manneshiva for hopefully solving that issue quite soon!

@menshikh-iv menshikh-iv added bug Issue described a bug difficulty medium Medium issue: required good gensim understanding & python skills labels Jun 21, 2018
@menshikh-iv
Copy link
Contributor

menshikh-iv commented Jul 30, 2018

@rpedela thanks for the report, reproduced with python2.7 and gensim==3.5.0

similar trace

AttributeError                            Traceback (most recent call last)
<ipython-input-2-a1c692ae9dff> in <module>()
----> 1 m = FastText.load("gensim_en_fasttext_wiki_lg")

/home/ivan/.virtualenvs/math/local/lib/python2.7/site-packages/gensim/models/fasttext.pyc in load(cls, *args, **kwargs)
    901             logger.info('Model saved using code from earlier Gensim Version. Re-loading old model in a compatible way.')
    902             from gensim.models.deprecated.fasttext import load_old_fasttext
--> 903             return load_old_fasttext(*args, **kwargs)
    904 
    905     @deprecated("Method will be removed in 4.0.0, use self.wv.accuracy() instead")

/home/ivan/.virtualenvs/math/local/lib/python2.7/site-packages/gensim/models/deprecated/fasttext.pyc in load_old_fasttext(*args, **kwargs)
     51 
     52 def load_old_fasttext(*args, **kwargs):
---> 53     old_model = FastText.load(*args, **kwargs)
     54     params = {
     55         'size': old_model.vector_size,

/home/ivan/.virtualenvs/math/local/lib/python2.7/site-packages/gensim/models/deprecated/word2vec.pyc in load(cls, *args, **kwargs)
   1615     @classmethod
   1616     def load(cls, *args, **kwargs):
-> 1617         model = super(Word2Vec, cls).load(*args, **kwargs)
   1618         # update older models
   1619         if hasattr(model, 'table'):

/home/ivan/.virtualenvs/math/local/lib/python2.7/site-packages/gensim/models/deprecated/old_saveload.pyc in load(cls, fname, mmap)
     85         compress, subname = SaveLoad._adapt_by_suffix(fname)
     86 
---> 87         obj = unpickle(fname)
     88         obj._load_specials(fname, mmap, compress, subname)
     89         logger.info("loaded %s", fname)

/home/ivan/.virtualenvs/math/local/lib/python2.7/site-packages/gensim/models/deprecated/old_saveload.pyc in unpickle(fname)
    380             return _pickle.loads(file_bytes, encoding='latin1')
    381         else:
--> 382             return _pickle.loads(file_bytes)
    383 
    384 

AttributeError: 'module' object has no attribute 'FastTextVocab'

I takes extremely long to load the model in the first place. It is really annoying is that normal?

That's expected, we already have an issue for it #1261

Why the hell does it generate 3 files?! Can you guys please explain the reason behind that? I really do not understand this!

The model contains 2 matrices (vectors and vectors_ngrams) + some model attributes saved_model, 3 files because we store matrices as distinct files.

@drozzy
Copy link

drozzy commented Nov 21, 2018

Any progress on this?

I hoped that saving in gensim format and loading would result in faster load times. Alas, load fails:

m = FastText.load('/src/workspace/model/cc.en.300.wv')

AttributeError: 'FastTextTrainables' object has no attribute 'vectors'

@menshikh-iv
Copy link
Contributor

@drozzy I hope that this will be fixed soon by @mpenkov, is it?

@menshikh-iv
Copy link
Contributor

Can be related to #2160

@mpenkov mpenkov added the fasttext Issues related to the FastText model label Dec 15, 2018
@mpenkov
Copy link
Collaborator

mpenkov commented Dec 15, 2018

@drozzy FYI (and for my record-keeping), the bug you've reported may also be related to #1994

@menshikh-iv
Copy link
Contributor

Fixed by #2313

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 fasttext Issues related to the FastText model
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants