Skip to contents

This function calculates the topic similarity between two conversations using either Latent Dirichlet Allocation (LDA) or Latent Semantic Analysis (LSA).

Usage

topic_similarity(conv1, conv2, method = "lda", num_topics = 2)

Arguments

conv1

A character vector representing the first conversation

conv2

A character vector representing the second conversation

method

A character string specifying the method to use: "lda" or "lsa"

num_topics

An integer specifying the number of topics to use in the model

Value

A numeric value representing the topic similarity

Examples

conv1 <- c("I love pizza", "Pizza is my favorite food")
conv2 <- c("I prefer pasta", "Pasta is delicious")
topic_similarity(conv1, conv2, method = "lda", num_topics = 2)
#> [1] 0.9995592
topic_similarity(conv1, conv2, method = "lsa", num_topics = 2)
#>      [,1]
#> [1,]    1