python-3.x - Python Gensim槌
问题描述
我正在尝试使用 Python 上的 Gensim 的 Mallet 包装器将 LDA 应用于主题建模。我正在运行的代码如下:
MALLET_PATH = 'C:/mallet-2.0.8/bin/mallet'
lda_mallet = gensim.models.wrappers.LdaMallet(mallet_path=MALLET_PATH, corpus=bow_corpus,
num_topics=TOTAL_TOPICS, id2word=dictionary,
iterations=500, workers=16)
Mallet 安装在 C 盘并在命令提示符 (C:\mallet-2.0.8\bin\mallet) 上运行。帮助命令也有效(import-dir --)。还安装了 Java。还为 Mallet 和 Java 设置了环境变量和路径。但输出显示以下错误。
CalledProcessError: Command 'mallet-2.0.8/bin/mallet import-file --preserve-case --keep-sequence --remove-stopwords --token-regex "\S+" --input C:\Users\imibh\AppData\Local\Temp\a8b7e6_corpus.txt --output C:\Users\imibh\AppData\Local\Temp\a8b7e6_corpus.mallet' returned non-zero exit status 1.
已经尝试了对过去此类堆栈溢出查询的所有响应,但没有任何改进。
非常感谢任何帮助。
马尼特
解决方案
确保您安装了 Java Developers Kit ( JDK )。
安装 JDK 后,LDA Mallet 的以下代码就像魅力一样!
import os
from gensim.models.wrappers import LdaMallet
os.environ.update({'MALLET_HOME':r'C:/mallet/mallet-2.0.8/'})
mallet_path = r'C:/mallet/mallet-2.0.8/bin/mallet.bat'
lda_mallet = LdaMallet(
mallet_path,
corpus = corpus_bow,
num_topics = n_topics,
id2word = dct,
)
这归功于另一个答案
推荐阅读
- java - 如何从 GAE Java 11 调用外部 Web 服务?
- ionic-framework - 下拉列表中带有 *ngFor 的离子项
- java - javax.crypto.BadPaddingException:解密错误:仅从数据库解密到已加密的字符串
- javascript - 猫鼬填充并返回带有路径作为列表的文档
- python-2.7 - 撤消自制程序清理
- python - 与python中的无限限制集成
- javascript - 成功更改 JS 中的不可变或原始数据类型。那么这些是原语还是JS概念错了?
- flutter - 如何优雅地从颤动的超类对象中复制对象?
- html - 媒体查询可以在宽度上使用动态大小吗?
- amazon-web-services - elasticbeanstalk 部署的最新 Go 解决方案堆栈名称是什么?