如何在gensim中使用sklearn api显示主题词

时间:2018-11-15 13:50:26

标签: python-3.x scikit-learn gensim lda

我正在尝试使用gensim api执行LDATransformer,然后我只想使用以下代码获取主题词:

This site can’t be reached

但是当我打印这些主题词时,我收到了以下错误消息:

from gensim.sklearn_api.ldamodel import LdaTransformer
   print("Loading docs for lda input...")
   docs = get_lda_input_from_corpus_folder(CORPUS_PATH)
    print("Topic modeling using LdaTransformer..")
    dictionary = Dictionary(docs)
    corpus = [dictionary.doc2bow(text) for text in docs]
    model =  LdaTransformer(id2word=dictionary, num_topics=n_topics,iterations=lda_n_iter,random_state=n_random)
    model.fit(corpus)
    print("\nTopical words:")
    print("-" * 20)
    topic_word = model.topic_word_
    n_top_words = 8
 for i, topic_dist in enumerate(topic_word):
     topic_words = np.argsort(topic_dist)[:-(n_top_words+1):-1]
     print('Topic {}: {}'.format(i, ' '.join(topic_words)))

我可以使用其他任何方法从该模型中提取单词吗?

0 个答案:

没有答案