5

The examples (related to word representations) on fasttext official web site (fasttext.cc) suggest that it is possible to calculate the nearest neighbors on vectors derived with cbow (or skip-gram model) (in short, on unsupervised learning models). It is stated that this can be done using the get_nearest_neighbors function on the model (model.get_nearest_neighbors). However, when I tried to do that Python (3.7.) it shows me the message that this function does not exist in fasttext for unspervised learning models, and indeed when I look at the fasttext help, I do not see that this function. The only similar function that exists is a predicate on model (model.predict (where k is specified)), however this can only be done on a supervised learning models.

Can anyone explain to me what's going on, and help me with this? And is there any way to calculate nearest neighbors for unspervised learning models in fasttext? :-)

jottbe
  • 4,228
  • 1
  • 15
  • 31
IsidoraG
  • 51
  • 1
  • 2

1 Answers1

3

Although fasttext has a get_nearest_neighbor method, their pypi relaese still does not have that method.

So either you can install pyfasttext library and access their nearest neighbor function.

from pyfasttext import FastText
model = FastText('model.bin')
model.nearest_neighbors('dog', k=2000)

or, you can get the latest development version of fasttext, you can install from the github repository

import fasttext
model = fasttext.load_model('model.bin')
model.get_nearest_neighbors('dog', k=100)
Kalana Geesara
  • 141
  • 1
  • 3