2

如何使用 gensim 的 word2vec 实现找到给定单词的 N 个最近单词。什么是 API?我在这里指的是跳过克。也许我错过了一些东西,我阅读了所有关于寻找相似词,找出奇怪的词等等......

在 DL4j 中,我有这个方法称为wordsNearest(String A, int n) which gives me the n-nearest words to A. 在 Gensim 中相当于什么?

4

2 回答 2

1

这个问题真的很老,但无论如何:我仍然不完全确定分层softmax和负采样是如何工作的,但原则上你应该能够从输入矩阵中获取一个向量,将它乘以输出矩阵中的向量,并且选择最高值。

w1_vec = model[word] #Get the vector for the word you're interested in.
# Loop over the words in the output matrix and take dot products.
for idx, w2_vec in enumerate(model.syn1neg):
    print(idx, model.index2word[idx], np.exp(np.dot(w1_vec, w2_vec)))

然后从输出中选择最高值。根据负采样/分层 softmax 使用 syn1neg / syn1。我在一些示例文本上使用了这种技术,结果是合理的。

于 2016-05-06T17:19:46.807 回答
0

如果我正确理解您的问题,您可以使用most_similar

model.most_similar(positive=['woman'])
于 2016-12-02T16:22:05.017 回答