Find the k words with the smallest distance. First execution can be slow because of precomputation. Search is done linearly, if your model is big you may want to use an approximate neighbour algorithm from other R packages (like RcppAnnoy).

get_nn(model, word, k)

Arguments

model

trained fastText model. Null if train a new model.

word

reference word

k

integer defining the number of results to return

Value

numeric with distances with names as words

Examples

library(fastrtext) model_test_path <- system.file("extdata", "model_unsupervised_test.bin", package = "fastrtext") model <- load_model(model_test_path) get_nn(model, "time", 10)
#> times size indicate access success allowing feelings #> 0.6120564 0.5041215 0.4941387 0.4777856 0.4719051 0.4696053 0.4652924 #> dictator amino accuracies #> 0.4595046 0.4582702 0.4535145