Skip to content

Is it possible to extract word/sentence from vector? #5349

Discussion options

You must be logged in to vote

You can use Vectors.most_similar to find the word(s) closest to a given vector. In a loaded model, you can access the vectors under nlp.vocab.vectors, so:

# convert vector to numpy array (if it isn't already)
query_vector = numpy.asarray([0.1, 0.3, 0.5, ...])
keys, _, _ = nlp.vocab.vectors.most_similar([query_vector])
# get string for the most similar hash
print(nlp.vocab.strings[keys[0][0]])

(I just noticed that the example in the docs uses nlp.vectors instead of nlp.vocab.vectors. We'll get that updated.)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / vectors Feature: Word vectors and similarity
2 participants
Converted from issue

This discussion was converted from issue #5349 on December 11, 2020 00:35.