find_nns {conText} | R Documentation |
Return nearest neighbors based on cosine similarity
Description
Return nearest neighbors based on cosine similarity
Usage
find_nns(
target_embedding,
pre_trained,
N = 5,
candidates = NULL,
norm = "l2",
stem = FALSE,
language = "porter"
)
Arguments
target_embedding |
(numeric) 1 x D matrix. D = dimensions of pretrained embeddings. |
pre_trained |
(numeric) a F x D matrix corresponding to pretrained embeddings. F = number of features and D = embedding dimensions. rownames(pre_trained) = set of features for which there is a pre-trained embedding. |
N |
(numeric) number of nearest neighbors to return. |
candidates |
(character) vector of candidate features for nearest neighbors |
norm |
(character) - how to compute similarity (see ?text2vec::sim2):
|
stem |
(logical) - whether to stem candidates when evaluating nns. Default is FALSE.
If TRUE, candidate stems are ranked by their average cosine similarity to the target.
We recommend you remove misspelled words from candidate set |
language |
the name of a recognized language, as returned by
|
Value
(character) vector of nearest neighbors to target
Examples
find_nns(target_embedding = cr_glove_subset['immigration',],
pre_trained = cr_glove_subset, N = 5,
candidates = NULL, norm = "l2", stem = FALSE)