Description
tokenize = lambda x: x.split()
TEXT = data.Field(sequential=True, tokenize=tokenize, lower=True, include_lengths=True, batch_first=True, fix_length=200)
LABEL = data.LabelField()
train_data, test_data = datasets.IMDB.splits(TEXT, LABEL)
train_data
TEXT.build_vocab(train_data, vectors=GloVe(name='6B', dim=300))
LABEL.build_vocab(train_data)
word_embeddings = TEXT.vocab.vectors
TEXT.vocab
I want to get TEXT.vocab.vectors from not the vectors torchtext had but my pretrained vector.
for example
TEXT.build_vocab(train_data, vectors=my_pretrained_vectors)
and then I will get the torch text embedding vectors from my_pretrained_vectors.
I'm confused. Glove pretrained vector works fine in another issue https://github.com/pytorch/text/issues/634.
@mttk Any ideas?
@lsh23 I assume you want to load some vector file which you produced yourself (not one of the pretrained GloVe, word2vec,... files).
In that case you need to format your vector file in the standard format (each line contains a word and a vector, where all the values are separated by a single space). Then construct your own Vectors object by passing the path to your vector file to the constructor, e.g.:
my_pretrained_vectors = Vectors('/path/to/my/vectors.txt')
TEXT.build_vocab(train_data, vectors=my_pretrained_vectors)
thank you for the answer!
Most helpful comment
@lsh23 I assume you want to load some vector file which you produced yourself (not one of the pretrained GloVe, word2vec,... files).
In that case you need to format your vector file in the standard format (each line contains a word and a vector, where all the values are separated by a single space). Then construct your own
Vectorsobject by passing the path to your vector file to the constructor, e.g.: