简体   繁体   中英

Converting word to vector using GloVe

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM