【发布时间】:2020-05-12 11:29:24
【问题描述】:
我创建了一个 word2vec 模型,并使用 TSNE 和 matplotlib 对特定术语的前 n 个相似词进行了可视化。我不明白的是,当我多次运行它时,即使每次单词和向量都相同,相同的单词也会被绘制到不同的位置。为什么会这样?我感觉这与 TSNE 降低向量维数的方式有关。如果是这种情况,使用这种可视化方法真的可靠吗,因为它每次都不一样?
model = Word2Vec.load("a_w2v_model")
topn_words_list = [x[0] for x in model.wv.most_similar("king",topn=3)]
topn_vectors_list = model[topn_words_list]
tsne = TSNE(n_components=2, verbose=1, perplexity=27, n_iter=300)
Y = tsne.fit_transform(topn_vectors_list)
fig, ax = plt.subplots()
ax.plot(Y[:, 0], Y[:, 1], 'o')
ax.set_yticklabels([]) #Hide ticks
ax.set_xticklabels([]) #Hide ticks
for i, word in enumerate(topn_words_list):
plt.annotate(word, xy=(Y[i, 0], Y[i, 1]))
plt.show()
【问题讨论】:
标签: python matplotlib pca gensim word2vec