sem_nearest_neighbors: Find Nearest Neighbors Based on Cosine Similarity

View source: R/sem_nearest_neighbors.R

sem_nearest_neighborsR Documentation

Find Nearest Neighbors Based on Cosine Similarity

Description

This function identifies the nearest neighbors of a given term or vector in a matrix based on cosine similarity.

Usage

sem_nearest_neighbors(x, matrix, n = 10)

Arguments

x

A character or numeric vector representing the term or vector.

matrix

A numeric matrix or a sparse matrix against which the similarity is calculated.

n

Number of nearest neighbors to return.

Value

A data frame with the ranks, terms, and their cosine similarity scores.

Examples

## Not run: 
 api_token <- ''
 matrix <- api_huggingface_embeddings(tif,
                                      text_hierarchy = c('doc_id', 'sentence_id'),
                                      api_token = api_token)
 query <- api_huggingface_embeddings(query = "Where's the party at?",
                                     api_token = api_token)
 neighbors <- sem_nearest_neighbors(x = query, matrix = matrix)

## End(Not run)




textpress documentation built on Oct. 14, 2024, 5:08 p.m.