def KMeansPredict(self,details,vec): # Details: centers , xtoc , distances return Kmeans_l1.nearestcentres(X = [vec], centres = details[0], metric="cosine")
mv = len(model.vocab) level = 1 while threshold < mv: # KMeans print() print() print(str(numInter) + " more iterations left ...") print() t0 = time.time() curVecs = list(set(curVecs) - set(Rseeds)) #L2# kmeans = cluster.KMeans(n_clusters=len(Rseeds), init=np.array(Rseeds), max_iter = 1) #kmeans.fit(np.array(curVecs)) centers, xtoc, distances = Kmeans_l1.kmeans(np.array(curVecs), np.array(Rseeds), maxiter=1, metric='cosine') #print(kmeans) print(str(time.time() - t0)) #print("Level "+ str(level) + "\nIntertia = " + str(kmeans.inertia_)) print("Level " + str(level) + " Done.") kmeans = [centers, xtoc] save_obj(kmeans, path + "Level" + str(level)) print("Mapping Centroids to Labels") centroid2Word = dict() for c in Rseeds: w = words[allseeds.index(tuple(c))] centroid2Word[Rseeds.index(c)] = w save_obj(centroid2Word, path + "Level" + str(level) + "c2w")
threshold = len(Rseeds) mv = len(model.vocab) level = 1 while threshold < mv: # KMeans print() print() print(str(numInter) + " more iterations left ...") print() t0 = time.time() curVecs = list(set(curVecs) - set(Rseeds)) #L2# kmeans = cluster.KMeans(n_clusters=len(Rseeds), init=np.array(Rseeds), max_iter = 1) #kmeans.fit(np.array(curVecs)) centers , xtoc , distances = Kmeans_l1.kmeans(np.array(curVecs), np.array(Rseeds), maxiter=1, metric='cosine') #print(kmeans) print(str(time.time()-t0)) #print("Level "+ str(level) + "\nIntertia = " + str(kmeans.inertia_)) print("Level "+ str(level) + " Done.") kmeans = [centers,xtoc] save_obj(kmeans,path+"Level"+str(level)) print("Mapping Centroids to Labels") centroid2Word = dict() for c in Rseeds: w = words[allseeds.index(tuple(c))] centroid2Word[Rseeds.index(c)] = w save_obj(centroid2Word,path+"Level"+str(level)+"c2w") print()