wordvectors icon indicating copy to clipboard operation
wordvectors copied to clipboard

Loading embeddings

Open Joseph94m opened this issue 6 years ago • 3 comments

Hi,

I downloaded the French embeddings, and extracted the zip file. How can I load these embeddings in a python code and return the embeddings for a specified word, e.g.: embedding("bonjour") -----> [0.2, -0,2, etc...]

Thanks

Joseph94m avatar Oct 13 '18 10:10 Joseph94m

You can use gensim to load the .bin model:

from gensim.models import Word2Vec model = Word2Vec.load("vi.bin") model.wv['nhà']

Then, you will get the embedding vector of the word "nhà", in Vietnamese for example. Remember to install gensim library

nvietsang avatar Mar 12 '19 15:03 nvietsang

But it didn't work with FastText, below is my code:

from gensim.models import FastText

model_f = FastText.load("zh.bin") v = model_f.wv['你好']`

It throws a exception: Exception has occurred: _pickle.UnpicklingError invalid load key, ','.

fadeawaygod avatar Mar 13 '19 07:03 fadeawaygod

But it didn't work with FastText, below is my code:

from gensim.models import FastText

model_f = FastText.load("zh.bin") v = model_f.wv['你好']`

It throws a exception: Exception has occurred: _pickle.UnpicklingError invalid load key, ','.

I fixed it by replacing load with load_fasttext_format.

fadeawaygod avatar Mar 13 '19 09:03 fadeawaygod