首页 > 解决方案 > Gensim Mallet Wrapper:如何获取所有文档的主题权重?

问题描述

我正在使用 Gensim 的 Mallet 包装器进行主题建模 -

LdaMallet(path_to_mallet_binary, corpus=corpus, num_topics=100, id2word=words, workers=6, random_seed=2)

虽然上述方法工作得非常快,但获取每个文档 (n=40,000) 的主题分布的步骤(见下文)需要很长时间。

#Store topic distributuon for all documents
all_topics=[]
for x in tqdm(range(0, len(doc_list))):
    all_topics.append(lda_model[corpus[x]])

完成 30,000 份文件大约需要 18 个小时。不知道我做错了什么。有没有办法更快地获得所有文档的主题分布?

标签: pythongensimldatopic-modelingmallet

解决方案


事实证明,大部分时间加载 LdaMallet 模型所花费的时间,我能够在 4 分钟内生成 50,000 个主题分布,而我只做了一次,而不是一个一个地做(之前和你做的时间一样) .

corpus = [dictionary.doc2bow(preprocess(unseen_document)) for unseen_documents in unseen_documents] 分布 = mallet_model [语料库]

您可以参考https://github.com/RaRe-Technologies/gensim/issues/3018


推荐阅读