16 lines
451 B
Python
16 lines
451 B
Python
import gensim.downloader
|
|
import numpy as np
|
|
|
|
|
|
class Word2Vec():
|
|
def __init__(self) -> None:
|
|
pass
|
|
|
|
def load(self):
|
|
self.model = gensim.downloader.load('word2vec-google-news-300')
|
|
|
|
def sentence2vec(self, sentence):
|
|
return np.mean([self.model[word] if word in self.model else np.zeros(300) for word in sentence])
|
|
|
|
def list_of_sentences2vec(self, sentences):
|
|
return [self.sentence2vec(x) for x in sentences] |