4

I am having trouble converting a fast FastText vector back to a word. Here is my python code:

from gensim.models import KeyedVectors
en_model = KeyedVectors.load_word2vec_format('wiki.en/wiki.en.vec')
vect = en_model.get_vector("turtles")

How can I take the vector (especially an arbitrary vector with the proper dimensions) and have it spit out a word?

DMM
  • 41
  • 3
  • `words = ['turtles','flower','hello']` `vect = {word: en_model.get_vector(i) for i in words}` i did something similar previously and i decided to place it in a dictionary so that i do not lose the exact word. maybe you could try something similar to this – Cua Nov 07 '18 at 07:05

1 Answers1

5

You want to use ret_vals = en_model.similar_by_vector(vect) (see similar_by_vector). Since vect is any arbitrary vector, you'll get back the closest matches. You can control the number you get back with the param topn=XX. If not supplied, you'll get back the top 10. The return values are a list of tuples, formatted (str, float) where str is the word and float is the similarity.

bivouac0
  • 2,494
  • 1
  • 13
  • 28