logistic_regression/word2vec.py
2021-09-20 22:20:34 +02:00

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]