-
-
Save bhaettasch/d7f4e22e79df3c8b6c20 to your computer and use it in GitHub Desktop.
from gensim.models import Word2Vec | |
# Load pretrained model (since intermediate data is not included, the model cannot be refined with additional data) | |
model = Word2Vec.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True, norm_only=True) | |
dog = model['dog'] | |
print(dog.shape) | |
print(dog[:10]) | |
# Deal with an out of dictionary word: Михаил (Michail) | |
if 'Михаил' in model: | |
print(model['Михаил'].shape) | |
else: | |
print('{0} is an out of dictionary word'.format('Михаил')) | |
# Some predefined functions that show content related information for given words | |
print(model.most_similar(positive=['woman', 'king'], negative=['man'])) | |
print(model.doesnt_match("breakfast cereal dinner lunch".split())) | |
print(model.similarity('woman', 'man')) |
Thanks man. i'll try it. @maifeeulasad
Try passing the url, instead of passing the location of the file..
you may even need to write your own stream receiver too..
good luck, if I'm done, i will share..
and if anyone finishes earlier, please share..
@mamad-knight
Thanks so much for spending time. i'll try it today or tomorrow. @maifeeulasad
Is there any API of this model so I can call it and get a vector for any word and without loading that model at my server? someone please help me with this, I am thinking this because my server can afford 4gb of ram for this model.
Thanks In advance.
Since this example this deprecated, I created a Google Colab demo for the same.
Reg "the model cannot be refined with additional data" - gensim has an online algorithm which allows to augment existing model (since 2015) https://rutumulkar.com/blog/2015/word2vec/
AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.
Use KeyedVector's .key_to_index dict, .index_to_key list, and methods .get_vecattr(key, attr) and .set_vecattr(key, attr, new_val) instead.
See https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4
Google Colab demo
Thank you for the Colab demo !!
try colab , not sure if they support such huge files @mamad-knight