Skip to contents

Create a matrix of pairwise similarities between each string in strings_A and strings_B.

Usage

get_similarity_matrix(embeddings, strings_A = NULL, strings_B = NULL)

Arguments

embeddings

A matrix of text embeddings

strings_A

A string vector

strings_B

A string vector

Value

A matrix of cosine similarities between the embeddings of strings_A and the embeddings of strings_B

Examples

embeddings <- get_embeddings(c('UPS', 'USPS', 'Postal Service'))
get_similarity_matrix(embeddings)
#>                      UPS      USPS Postal Service
#> UPS            1.0000002 0.7534348      0.6256223
#> USPS           0.7534348 0.9999999      0.8407916
#> Postal Service 0.6256223 0.8407916      1.0000000
get_similarity_matrix(embeddings, 'Postal Service')
#>                      UPS      USPS Postal Service
#> Postal Service 0.6256223 0.8407916              1
get_similarity_matrix(embeddings, 'Postal Service', c('UPS', 'USPS'))
#>                      UPS      USPS
#> Postal Service 0.6256223 0.8407916