简体   繁体   中英

Topic modelling- Calculate the coherence score of an sklearn LDA model?

I tried several things to calculate the coherence score for a sklearn LDA model, but it does not work out. What is a way to calculate the Coherence score for a sklearn LDA model?

When I use the standard gensim code to calculate the coherence score, I receive the following error: ValueError: This topic model is not currently supported. Supported topic models should implement the get_topics method.```

Here is part of my code:

count_vectorizer = CountVectorizer(stop_words='english')

  # Fit and transform the processed titles

count_data = count_vectorizer.fit_transform(training_data_preprocessed['Input'])
tf = count_data




number_topics = 5
number_words = 5

# Create and fit the LDA model
lda = LDA(n_components=number_topics)
lda.fit(tf)

# Print the topics found by the LDA model
print("Topics found via LDA:")
print_topics(lda, count_vectorizer, number_words)

I think you can use this code below for coherence model in LDA:

# import library from gensim  
from gensim.models import CoherenceModel

# instantiate topic coherence model
cm = CoherenceModel(model=lda_model_15, corpus=bow_corpus, texts=docs, coherence='c_v')

# get topic coherence score
coherence_lda = cm.get_coherence() 
print(coherence_lda)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM