Gensim - Using Pretrained Models
sifoo bad
1 min read
import gensim
import gensim.downloader
for model_name in list(gensim.downloader.info()['models'].keys()):
print(model_name)
Download pretrained model
import gensim
import gensim.downloader
model_google_news = gensim.downloader.load('word2vec-google-news-300')
Save pretrained model to Google Drive
!cp /root/gensim-data/word2vec-google-news-300/word2vec-google-news-300.gz /content/drive/MyDrive/model/gensim/word2vec-google-news-300/word2vec-google-news-300.gz
Load pretrained model from Google Drive
from gensim.models import KeyedVectors
model_w2v = KeyedVectors.load_word2vec_format('/content/drive/MyDrive/model/word2vec-google-news-300/word2vec-google-news-300.gz', binary=True)
vector_test = model_w2v.get_vector("test")
Save pretrained model to Google Drive as keyed vector model
model_w2v.save('/content/drive/MyDrive/Content/vector_w2v.kv')
Load keyed vector model
from gensim.models import KeyedVectors
model_w2v = KeyedVectors.load('/content/drive/MyDrive/Content/vector_w2v.kv')
0
Subscribe to my newsletter
Read articles from sifoo bad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by