Created
April 12, 2019 21:17
-
-
Save dhruvdcoder/cbb8d7967a499ba85418c18414e2cdce to your computer and use it in GitHub Desktop.
Load glove embeddings into pytorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert glove to word2vec format | |
from gensim.scripts.glove2word2vec import glove2word2vec | |
glove2word2vec(glove_input_file="emb.txt", word2vec_output_file="emb_word2vec_format.txt") | |
import gensim | |
import torch | |
model = gensim.models.KeyedVectors.load_word2vec_format('emb_word2vec_format.txt') | |
weights = torch.FloatTensor(model.vectors) | |
# Ref: https://stackoverflow.com/questions/37793118/load-pretrained-glove-vectors-in-python | |
# https://stackoverflow.com/questions/49710537/pytorch-gensim-how-to-load-pre-trained-word-embeddings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment