Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 681
frhyme Avatar asked May 28 '20 07:05

frhyme


People also ask

How do I load a fastText model in Gensim?

The model can be stored/loaded via its save() and load() methods, or loaded from a format compatible with the original Fasttext implementation via load_facebook_model() .

How do I load a vector on fastText?

. bin is a binary fasttext model that can be loaded using fasttext. load_model('file. bin') and that can provide word vector for unseen words (OOV), be trained more, etc.

What is fastText word embedding?

fastText is another word embedding method that is an extension of the word2vec model. Instead of learning vectors for words directly, fastText represents each word as an n-gram of characters.


1 Answers

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"))
like image 76
Anwarvic Avatar answered Sep 20 '22 11:09

Anwarvic