我对gensim的Word2vecKeyedVectors中的most_similar和similar_by_vector的结果感到困惑。它们应该以相同的方式计算余弦相似性 - 但是:
使用一个单词运行它们会产生相同的结果,例如: model.most_similar([' obama'])和similar_by_vector(model [' obama'])
但如果我给它一个等式:
model.most_similar(positive=['king', 'woman'], negative=['man'])
给出:
[('queen', 0.7515910863876343), ('monarch', 0.6741327047348022), ('princess', 0.6713887453079224), ('kings', 0.6698989868164062), ('kingdom', 0.5971318483352661), ('royal', 0.5921063423156738), ('uncrowned', 0.5911505818367004), ('prince', 0.5909028053283691), ('lady', 0.5904011130332947), ('monarchs', 0.5884358286857605)]
同时:
q = model['king'] - model['man'] + model['woman']
model.similar_by_vector(q)
给出:
[('king', 0.8655095100402832), ('queen', 0.7673765420913696), ('monarch', 0.695580005645752), ('kings', 0.6929547786712646), ('princess', 0.6909604668617249), ('woman', 0.6528975963592529), ('lady', 0.6286187767982483), ('prince', 0.6222133636474609), ('kingdom', 0.6208546161651611), ('royal', 0.6090123653411865)]
女王,君主等词的余弦距离存在显着差异......我想知道为什么?
谢谢!