textDistance() computes the semantic distance between two text variables.
textDistance(x, y, method = "euclidean", center = FALSE, scale = FALSE)
Word embeddings (from textEmbed()).
Word embeddings (from textEmbed()).
(character) Character string describing type of measure to be computed; default is "euclidean" (see also measures from stats:dist() including "maximum", "manhattan", "canberra", "binary" and "minkowski". It is also possible to use "cosine", which computes the cosine distance (i.e., 1 - cosine(x, y)).
(boolean; from base::scale) If center is TRUE then centering is done by subtracting the embedding mean (omitting NAs) of x from each of its dimension, and if center is FALSE, no centering is done.
(boolean; from base::scale) If scale is TRUE then scaling is done by dividing the (centered) embedding dimensions by the standard deviation of the embedding if center is TRUE, and the root mean square otherwise.
A vector comprising semantic distance scores.
See textSimilarity
and textSimilarityNorm
.
# Compute the semantic distance score between the embeddings
# from "harmonytext" and "satisfactiontext".
if (FALSE) { # \dontrun{
distance_scores <- textDistance(
x = word_embeddings_4$texts$harmonytext,
y = word_embeddings_4$texts$satisfactiontext
)
# Show information about how distance_scores were constructed.
comment(distance_scores)
} # }