get_nn: Get nearest neighbour vectors

Description Usage Arguments Value Examples

View source: R/API.R

Description

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).

Usage

1
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

1
2
3
4
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)

fastrtext documentation built on Oct. 30, 2019, 11:32 a.m.