topics.Rd
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, ...)
models | A model, i.e.: LDA or LSI, or a |
---|---|
... | Any other options, from the official documentation. |
A greater coherence is preferred: a higher value on the get_coherence
method, see example.
#> → Preprocessing 9 documents #> ← 9 documents after perprocessingdictionary <- 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.643125063496548bad_cm$get_coherence()#> -14.701487465421206