本文整理汇总了Python中gensim.models.LdaModel.inference方法的典型用法代码示例。如果您正苦于以下问题:Python LdaModel.inference方法的具体用法?Python LdaModel.inference怎么用?Python LdaModel.inference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gensim.models.LdaModel
的用法示例。
在下文中一共展示了LdaModel.inference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perform_lda
# 需要导入模块: from gensim.models import LdaModel [as 别名]
# 或者: from gensim.models.LdaModel import inference [as 别名]
def perform_lda(dictionary, corpus, num_topics, wiki_path=None, passes=1, iterations=50, chunksize=200):
"""
:param dictionary:
:param corpus:
:param wiki_path:
:param num_topics:
:param passes:
:param iterations:
:param chunksize:
:return:
"""
if wiki_path is not None:
logging.info('Generating wiki corpus...')
wikis = unpickle(wiki_path)
wiki_corpus = [dictionary.doc2bow(wiki) for wiki in wikis]
logging.info('Combining original corpus and wiki corpus...')
corpus = corpus + wiki_corpus # wiki_corpus is merged after the original corpus
lda_model = LdaModel(corpus=corpus, id2word=dictionary, num_topics=num_topics, passes=passes,
iterations=iterations, alpha='auto', chunksize=chunksize)
corpus_ids = get_corpus_ids(dictionary.corpus_id2orig_id)
# doc_vector_ids = dictionary.corpus_id2orig_id[corpus_ids]
doc_vector_ids = [dictionary.corpus_id2orig_id[corpus_id] for corpus_id in corpus_ids]
doc_vectors = lda_model.inference(corpus)[0]
doc_vectors = doc_vectors[corpus_ids, :]
doc_vectors = doc_vectors / doc_vectors.sum(axis=1).reshape(doc_vectors.shape[0], 1)
return lda_model, doc_vectors, doc_vector_ids