Skip to content

Instantly share code, notes, and snippets.

@kommradHomer
Created January 7, 2021 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kommradHomer/8799f975b4e64f7d64e6eebb4cd7da75 to your computer and use it in GitHub Desktop.
Save kommradHomer/8799f975b4e64f7d64e6eebb4cd7da75 to your computer and use it in GitHub Desktop.
import fasttext
import gensim
import torch
fasttext.load_model("path/to/model/wiki-news-300d-1M.vec")
.
.
## OUT >>
## OUT >> ValueError: path/to/embedding/wiki-news-300d-1M.vec has wrong file format!
## OUT >>
.
.
## using binary=False is important.
##The vectors downloaded from the fastText homepage are not binary
temp_model = gensim.models.KeyedVectors.load_word2vec_format("path/to/embedding/wiki-news-300d-1M.vec",binary=False)
temp_weights=torch.FloatTensor(temp_model.vectors)
print(temp_weights.shape)
## OUT >>
## OUT >> torch.Size([1000000, 300])
## OUT >>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment