-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadModels.py
36 lines (28 loc) · 1.17 KB
/
loadModels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from gensim.models.keyedvectors import KeyedVectors
from constants import *
from gensim.models import word2vec
def load_google_news(enable_print=True):
if enable_print:
print("Loading Google News pretrained model...")
# Load Google's pre-trained Word2Vec model.
return KeyedVectors.load_word2vec_format(GOOGLE_NEWS, binary=True)
def load_glove(enable_print=True):
if enable_print:
print("Loading GloVe model...")
import gensim
# Convertir le modele Glove en Word2vec
gensim.scripts.glove2word2vec.glove2word2vec(GLOVE, 'glove_as_w2v.txt')
# Charger le nouveau fichier qui constitue un modele
return KeyedVectors.load_word2vec_format('glove_as_w2v.txt')
def load_text8(enable_print=True):
if enable_print:
print("Training Text8 model...")
sentences = word2vec.Text8Corpus(TEXT8)
return word2vec.Word2Vec(sentences, size=300, window=12, min_count=25, workers=3, sg=1, negative=12)
def load(modelname, enable_print=True):
if modelname == GOOGLE_NEWS:
return load_google_news(enable_print)
elif modelname == TEXT8:
return load_text8(enable_print)
else:
return load_glove(enable_print)