You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
self.model = model #store the Word2Vec model object in case of future use
self.word_to_vec = {word:model.wv[word] for word in model.wv.vocab} #mapping from word strings to vectors
self.vectors = [model.wv[word] for word in model.wv.vocab]
clusterer = KMeansClusterer(num_means=5, distance=cosine_distance) #the object that will cluster our vectors, num_means will eventually be parameterized
clusterer.cluster_vectorspace(self.vectors)
self.central_words = []
#find closest words to centroids
for centroid in clusterer._means:
closest = None
for word in self.word_to_vec:
vector = self.word_to_vec[word]
if not closest or (cosine_distance(vector, centroid) < cosine_distance(closest[1], centroid)):