Calculate topic coherence for topic models.

model_coherence(models, ...)

# S3 method for gensim.models.basemodel.BaseTopicModel
model_coherence(models,
  ...)

# S3 method for list
model_coherence(models, ...)

Arguments

models

A model, i.e.: LDA or LSI, or a list of the latter.

...

Any other options, from the official documentation.

Details

A greater coherence is preferred: a higher value on the get_coherence method, see example.

Examples

# preprocess the corpus texts <- prepare_documents(corpus)
#> Preprocessing 9 documents #> 9 documents after perprocessing
dictionary <- corpora_dictionary(texts) corpus <- doc2bow(dictionary, texts) # create 2 models to compare good_lda_model <- model_lda( corpus = corpus, id2word = dictionary, iterations = 50L, num_topics = 2L ) bad_lda_model <- model_lda( corpus = corpus, id2word = dictionary, iterations = 1L, num_topics = 5L ) # create coherence models good_cm <- model_coherence( model = good_lda_model, corpus = corpus, dictionary = dictionary, coherence = 'u_mass' ) bad_cm <- model_coherence( model = bad_lda_model, corpus = corpus, dictionary = dictionary, coherence = 'u_mass' ) # compare coherence good_cm$get_coherence()
#> -14.643125063496548
bad_cm$get_coherence()
#> -14.701487465421206