def get_antonyms(self,wordA:str, topk:int=10,ispositive:bool=True):
seed=[['??','??'],['??','??'],['??','??'],['??','??'],['??','??']]
proposal={}
for pair in seed:
if ispositive:
result=self.analogy(pair[0],pair[1],wordA,topk)
print(w2v.find_nearest_word((self[pair[0]] + self[pair[1]]) / 2, 3))
else:
result = self.analogy(pair[1], pair[0], wordA, topk)
print(w2v.find_nearest_word((self[pair[0]] + self[pair[1]]) / 2, 3))
for item in result:
term_products = np.argwhere(self[wordA] * self[item[0]] < 0)
#print(item[0] + ':' +wordA + str(term_products))
#print(item[0] + ':' +wordA+'('+str(pair)+') '+ str(len(term_products)))
if len(term_products)>=self.dims/4:
if item[0] not in proposal:
proposal[item[0]] = item[1]
elif item[1]> proposal[item[0]]:
proposal[item[0]] +=item[1]
for k,v in proposal.items():
proposal[k]=v/len(seed)
sortitems=sorted(proposal.items(), key=lambda d: d[1],reverse=True)
return [sortitems[i] for i in range(min(topk,len(sortitems)))]
评论列表
文章目录