While defining corpus and dictionary for building the LDA model by defining topics how can we different topics keywords
It is working while giving an explicitly topic number, but I want that to be iterated.
from gensim import corpora
dictionary = corpora.Dictionary(doc_clean)
corpus = [dictionary.doc2bow(doc) for doc in doc_clean]
lda_model = gensim.models.ldamodel.LdaModel(corpus = corpus , id2word=dictionary , num_topics=10 , random_state=100, update_every=1 , chunksize=100 , passes=10 , alpha='auto' , per_word_topics=True)
topics = print(lda_model.print_topic(6))
doc_lda = lda_model[corpus]
I want to know how can we iterate the topics instead of giving manually each time topic number
If I understood your ask correctly, all you need is:
topics = []
num_topics=10
for i in range((num_topics)):
topics.append(lda_model.print_topic(i+1))
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.