projector (version 0.0.2)

retrieve_neighbors: Retrieve a list of neighbor vectors

Description

Use RcppAnnoy to rapidly retrieve a list of vector neighbors.

Usage

retrieve_neighbors(text, projection_type, annoy_model, n,
  search_k = max(10000, 10 * n), center_pivot = TRUE, ...)

Arguments

text

character containing the text related to the pivot vector

projection_type

character defining the algorithm to use to compute the coordinates. (tsne or pca)

annoy_model

RcppAnnoy model

n

number of neighbors to retrieve

search_k

number of nodes to search in (RcppAnnoy parameter). Higher = ++precision & --speed

center_pivot

put pivot text in the middle of the graph

...

parameters passed to projection algorithm (max_iter, perplexity, verbose, transformations)

Details

Transform original vectors in 2D coordinates applying either:

Examples

Run this code
# NOT RUN {
if (interactive()){
# This example should be run with a higher quality model
# than the one embedded in fastrtext
library(projector)
library(fastrtext)

model_test_path <- system.file("extdata",
                               "model_unsupervised_test.bin",
                               package = "fastrtext")
model <- load_model(model_test_path)
word_embeddings <- get_word_vectors(model,
                                    words = head(get_dictionary(model), 2e5))

annoy_model <- get_annoy_model(word_embeddings, 5)

selected_word <- "out"
df <- retrieve_neighbors(text = selected_word,
                         projection_type = "tsne",
                         annoy_model = annoy_model,
                         n = 1000)
}
# }

Run the code above in your browser using DataLab