简体   繁体   中英

gensim - fasttext - Why `load_facebook_vectors` doesn't work?

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.

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM