similarity: Compute similarity between word or document vectors

View source: R/utils.R

similarityR Documentation

Compute similarity between word or document vectors

Description

Compute the cosine similarity between word vectors for selected words.

Usage

similarity(
  x,
  targets,
  layer = c("words", "documents"),
  mode = c("character", "numeric")
)

Arguments

x

a textmodel_wordvector object.

targets

words or documents for which similarity is computed.

layer

the layer based on which similarity is computed. This must be "documents" when targets are document names.

mode

specify the type of resulting object.

Value

a matrix of cosine similarity scores when mode = "numeric" or of words sorted in descending order by the similarity scores when mode = "character". When words is a named numeric vector, word (or document) vectors are weighted and summed before computing similarity scores.

See Also

probability()


wordvector documentation built on Dec. 9, 2025, 5:09 p.m.