2

How can I find the N-nearest words given a word using gensim's word2vec implementation. What is the API for that? I am referring to skip grams here. Maybe I missed something, I read all about finding similar words, finding the odd one out and so on...

In DL4j I have this method called wordsNearest(String A, int n) which gives me the n-nearest words to A. What is the equivalent of this in Gensim?

4

2 に答える 2

1

この質問は本当に古いですが、とにかく:階層的なソフトマックスと負のサンプリングがどのように機能するかはまだ完全にはわかりませんが、原則として、入力行列からベクトルを取得し、それを出力行列のベクトルで乗算し、最高値を選択します。

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)))

次に、出力から最大値を選択します。ネガティブ サンプリング / 階層的ソフトマックスに応じて syn1neg / syn1 を使用します。いくつかのサンプル テキストでこの手法を使用しましたが、結果は妥当です。

于 2016-05-06T17:19:46.807 に答える
0

あなたの質問を正しく理解できれば、most_similarを使用できます。

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