Learn R Programming

text (version 1.0)

textDistanceMatrix: Compute semantic distance scores between all combinations in a word embedding

Description

Compute semantic distance scores between all combinations in a word embedding

Usage

textDistanceMatrix(x, method = "euclidean", center = FALSE, scale = FALSE)

Value

A matrix of semantic distance scores

Arguments

x

Word embeddings (from textEmbed).

method

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)).

center

(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.

scale

(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.

See Also

see textDistanceNorm

Examples

Run this code
distance_scores <- textDistanceMatrix(word_embeddings_4$texts$harmonytext[1:3, ])
round(distance_scores, 3)

Run the code above in your browser using DataLab