import logging, gensim logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) # load id->word mapping (the dictionary), one of the results of step 2 above id2word = gensim.corpora.Dictionary.load_from_text('wiki_en/wiki_en_wordids.txt.bz2') # load corpus iterator mm = gensim.corpora.MmCorpus('wiki_en/wiki_en_tfidf.mm') # extract 10 LSA topics; use the default one-pass algorithm lsa = gensim.models.lsimodel.LsiModel(corpus=mm, id2word=id2word, num_topics=10) print(lsa.show_topics()) # extract 10 LDA topics, using 1 pass and updating once every 1 chunk (5,000 documents) lda = gensim.models.ldamodel.LdaModel(corpus=mm, id2word=id2word, num_topics=10, update_every=1, chunksize=5000, passes=1) print(lda.show_topics()) # compute coherence for LDA model cm = gensim.models.coherencemodel.CoherenceModel(model=lda, corpus=mm, coherence='u_mass') print(cm.get_coherence())