我正在尝试使用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)。help命令也有效(import-dir --)。还安装了Java。还为Mallet和Java.Yet设置了环境变量和path,输出显示以下错误。
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.我已经尝试了在堆栈溢出时对过去此类查询的所有响应,但没有任何改进。
会非常感谢任何人的帮助。
管理
发布于 2020-06-07 18:21:01
如果您使用的是windows,则可能需要执行此操作。
MALLET_PATH = "C:\\mallet-2.0.8\\bin\\mallet"发布于 2020-11-05 18:26:23
确保您安装了Java开发人员工具包().
在安装JDK之后,LDA Mallet的以下代码就像charm一样工作!
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,
)功劳归功于this another answer
https://stackoverflow.com/questions/60988425
复制相似问题