Home > Blockchain >  Converting word to vector using GloVe
Converting word to vector using GloVe

Time:10-01

I loaded my glove package as follows:

import gensim.downloader as api
model = api.load("glove-wiki-gigaword-100")

and would want to create a function where I pass in a word and the GloVe model, and it will return the corresponding vector, for instance,

def convert_word_to_vec(word, model):

and when I pass in convert_word_to_vec(lol, model) it will return the vectors for the word lol

Is there a way around this? Thank you!

CodePudding user response:

Usage:

import gensim.downloader as api
model = api.load("glove-wiki-gigaword-100")

vector = model['lol']
print(vector)  # array with shape (100,)

Please check the documentations for more options:

https://radimrehurek.com/gensim/models/keyedvectors.html

  • Related