Skip to content

Instantly share code, notes, and snippets.

@jmrobles
Created August 17, 2020 17:58
Show Gist options
  • Save jmrobles/548f0a1fee4f8ef63b1cc6bba523ffa5 to your computer and use it in GitHub Desktop.
Save jmrobles/548f0a1fee4f8ef63b1cc6bba523ffa5 to your computer and use it in GitHub Desktop.
perplexities = []
coherence = []
num_topics = [3,4, 10, 20] + list(range(5, 75, 10))
for nt in tqdm(num_topics):
lda_model = gensim.models.ldamodel.LdaModel(corpus=corpus,
id2word=words,
num_topics=nt,
random_state=2,
update_every=1,
passes=10,
alpha='auto',
per_word_topics=True)
perplexities.append(lda_model.log_perplexity(corpus))
coherence_lda_model = CoherenceModel(model=lda_model, texts=docs, dictionary=words, coherence='c_v')
print(f"Num: {nt} - Per: {lda_model.log_perplexity(corpus)} - Coh: {coherence_lda_model.get_coherence()}")
coherence.append(coherence_lda_model.get_coherence())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment