retrieve_neighbors: Retrieve a list of neighbor vectors

Description Usage Arguments Details Examples

Description

Use RcppAnnoy to rapidly retrieve a list of vector neighbors.

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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)
}

projector documentation built on May 2, 2019, 3:42 a.m.