How to find the closest word to a vector using word2vec

前端 未结 3 606
忘了有多久
忘了有多久 2021-02-02 10:16

I have just started using Word2vec and I was wondering how can we find the closest word to a vector suppose. I have this vector which is the average vector for a set of vectors

3条回答
  •  深忆病人
    2021-02-02 10:43

    Alternatively, model.wv.similar_by_vector(vector, topn=10, restrict_vocab=None) is also available in the gensim package.

    Find the top-N most similar words by vector.

    Parameters:

    • vector (numpy.array) – Vector from which similarities are to be computed.

    • topn ({int, False}, optional) – Number of top-N similar words to return. If topn is False, similar_by_vector returns the vector of similarity scores.

    • restrict_vocab (int, optional) – Optional integer which limits the range of vectors which are searched for most-similar values. For example, restrict_vocab=10000 would only check the first 10000 word vectors in the vocabulary order. (This may be meaningful if you’ve sorted the vocabulary by descending frequency.)

    Returns: Sequence of (word, similarity).

    Return type: list of (str, float)

提交回复
热议问题