Skip to main content

Load pretrained word embeddings (word2vec, glove format) into torch.FloatTensor for PyTorch

Project description

Load pretrained word embeddings (word2vec, glove format) into torch.FloatTensor for PyTorch

Install

PyTorch required.

pip install torchwordemb

Usage

import torchwordemb

torchwordemb.load_word2vec_bin(path)

read word2vec binary-format model from path.

returns (vocab, vec)

  • vocab is a dict mapping a word to its index.
  • vec is a torch.FloatTensor of size V x D, where V is the vocabulary size and D is 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for torchwordemb, version 0.0.7
Filename, size File type Python version Upload date Hashes
Filename, size torchwordemb-0.0.7.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page