Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a pre-trained Word2vec MODEL File and reuse it?

I want to use a pre-trained word2vec model, but I don't know how to load it in python.

This file is a MODEL file (703 MB). It can be downloaded here:
http://devmount.github.io/GermanWordEmbeddings/

like image 211
Vahid SJ Avatar asked Sep 17 '16 16:09

Vahid SJ


People also ask

How do I load Google's pre-trained Word2Vec model?

Before we start, download word2vec pre-trained vectors published by Google from here. It's 1.5GB! The published pre-trained vectors are trained on part of Google News dataset on about 100 billion words. The model contains 300-dimensional vectors for about 3 million words and phrases.

Is Word2Vec a Pretrained model?

Google's Word2vec Pretrained Word EmbeddingWord2Vec is one of the most popular pretrained word embeddings developed by Google. Word2Vec is trained on the Google News dataset (about 100 billion words).


1 Answers

just for loading

import gensim

# Load pre-trained Word2Vec model.
model = gensim.models.Word2Vec.load("modelName.model")

now you can train the model as usual. also, if you want to be able to save it and retrain it multiple times, here's what you should do

model.train(//insert proper parameters here//)
"""
If you don't plan to train the model any further, calling
init_sims will make the model much more memory-efficient
If `replace` is set, forget the original vectors and only keep the normalized
ones = saves lots of memory!
replace=True if you want to reuse the model
"""
model.init_sims(replace=True)

# save the model for later use
# for loading, call Word2Vec.load()

model.save("modelName.model")
like image 163
AbtPst Avatar answered Sep 20 '22 19:09

AbtPst