gensim - fasttext - Why `load_facebook_vectors` doesn't work?
Asked Answered
C

1

8

I've tried to load pre-trained FastText vectors from fastext - wiki word vectors.

My code is below, and it works well.

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

but, the warning message is a little annoying.

gensim_fasttext_pretrained_vector.py:13: DeprecationWarning: Call to deprecated `load_fasttext_format` (use load_facebook_vectors (to use pretrained embeddings)

The message said, load_fasttext_format will be deprecated so, it will be better to use load_facebook_vectors.

So I decided to changed the code. and My changed code is like below.

from gensim.models import FastText
model = FastText.load_facebook_vectors('./wiki.en/wiki.en.bin')

But, the error occurred, the error message is like this.

Traceback (most recent call last):
  File "gensim_fasttext_pretrained_vector.py", line 13, in <module>
    model = FastText.load_facebook_vectors('./wiki.en/wiki.en.bin')
AttributeError: type object 'FastText' has no attribute 'load_facebook_vectors'

I couldn't understand why these thing happen. I just change what the messages said, but it doesn't work. If you know anything about this, please let me know.

Always, thanks for you guys help.

Cyte answered 28/5, 2020 at 7:27 Comment(0)
P
7

You're almost there, you need to change two things:

  • First of all, it's fasttext all lowercase letters, not Fasttext.
  • Second of all, to use load_facebook_vectors, you need first to create a datapath object before using it.

So, you should do like so:

from gensim.models import fasttext
from gensim.test.utils import datapath

wv = fasttext.load_facebook_vectors(datapath("./wiki.en/wiki.en.bin"))
Pennsylvanian answered 28/5, 2020 at 8:50 Comment(4)
Thanks for your help. As you said, it works after chaging code like you said.Cyte
Glad I could helpPennsylvanian
I'm glad it's working; note however you don't need to use datapath. The load_facebook_vectors() method on the module gensim.models.fasttext will take a plain string as long as it's to a valid file.Intellectualize
if you use datapath, the utility function will look for the file in the /gensim/test/test_data/ dir, so if you downloaded a fasttext file in a dir of your own choice it will not be found.Lipread

© 2022 - 2024 — McMap. All rights reserved.