pytorch-wordemb
June 20, 2019 ยท View on GitHub
Load pretrained word embeddings (word2vec, glove format) into torch.FloatTensor for PyTorch
Install
PyTorch required.
pip install torchwordemb
Usage
import torch
import torchwordemb
torchwordemb.load_word2vec_bin(path)
read word2vec binary-format model from path.
returns (vocab, vec)
vocabis adictmapping a word to its index.vecis atorch.FloatTensorof sizeV x D, whereVis the vocabulary size andDis the dimension of word2vec.
vocab, vec = torchwordemb.load_word2vec_bin("/path/to/word2vec/model.bin")
print(vec.size())
print(vec[ w2v.vocab["apple"] ] )
torchwordemb.load_word2vec_text(path)
read word2vec text-format model from path.
torchwordemb.load_glove_text(path)
read GloVe text-format model from path.