The function to create and train and an LDA model.

topicsModel(
  dtm,
  num_topics = 20,
  num_top_words = 10,
  num_iterations = 1000,
  seed = 42,
  save_dir = "./results",
  load_dir = NULL
)

Arguments

dtm

(R_obj) The document term matrix

num_topics

(integer) The number of topics to be created

num_top_words

(integer) The number of top words to be displayed

num_iterations

(integer) The number of iterations to run the model

seed

(integer) The seed to set for reproducibility

save_dir

(string) The directory to save the model, if NULL, the model will not be saved

load_dir

(string) The directory to load the model from, if NULL, the model will not be loaded

Value

A list of the model, the top terms, the labels, the coherence, and the prevalence

Examples

# \donttest{
# Create LDA Topic Model 
dtm <- topicsDtm(data = dep_wor_data$Depphrase)
#> [1] "The Dtm, data, and summary are saved in./results/seed_42/dtms.rds"
model <- topicsModel(dtm = dtm, # output of topicsDtm()
                     num_topics = 20,
                     num_top_words = 10,
                     num_iterations = 1000,
                     seed = 42,
                     save_dir = "./results")
#> [1] "The Model is saved in./results/seed_42/model.rds"
                   
# Load precomputed LDA Topic Model
model <- topicsModel(load_dir = "./results",
                     seed = 42)
#> [1] "The Model is saved in./results/seed_42/model.rds"
# }