python - 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 个小时。不知道我做错了什么。有没有办法更快地获得所有文档的主题分布?
解决方案
事实证明,大部分时间加载 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
推荐阅读
- docker - Docker patch command substitution
- c# - WebAPI - 基于实体修饰属性的通用搜索服务
- node.js - 我什么时候会在页面中看到“404”?
- javascript - 如何更改侦听器内 Google Maps 圆形标记图标的笔触颜色?
- codeblocks - 如何在 CodeBlocks 中创建工作区?
- php - 根据一系列单选按钮问题显示结果?
- oracle - How to pass a very long list in jdbcTemplate spring-boot
- javascript - 用于自动更新滚动列表的 jQuery 插件
- python - 如何让 pytorch 在 Jupyterhub 中工作?
- javascript - 如何在 EJS 中为编辑路线填充复选框?