gensim LdaMallet引发CalledProcessError,但在命令行运行mallet时没有错误

时间:2017-05-23 23:03:42

标签: python subprocess gensim lda mallet

标题几乎说明了一切。这是一些测试代码:

import os
os.environ.update({'MALLET_HOME': r'C:/Users/somebody/a/place/LDA/mallet-2.0.8/',
                  'JAVA_HOME': r'C:/Program Files/Java/jdk1.8.0_131/'})

from gensim.corpora import mmcorpus, Dictionary
texts = [['human', 'interface', 'computer'],
 ['survey', 'user', 'computer', 'system', 'response', 'time'],
 ['eps', 'user', 'interface', 'system'],
 ['system', 'human', 'system', 'eps'],
 ['user', 'response', 'time'],
 ['trees'],
 ['graph', 'trees'],
 ['graph', 'minors', 'trees'],
 ['graph', 'minors', 'survey']]
dictionary = Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]

import gensim

mallet_path = r'C:\Users\somebody\a\place\LDA\mallet-2.0.\bin\mallet'
gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, id2word=dictionary, num_topics=5, alpha=1)

这引发了以下错误(截断,因为大多数是不相关的堆栈信息):

CalledProcessError                        Traceback (most recent call last)
<ipython-input-99-7343c192afd1> in <module>()
      5 mallet_path = r'C:\Users\somebody\a\place\LDA\mallet-2.0.8\bin\mallet'
----> 6 gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, id2word=dictionary, num_topics=5, alpha=1)
.
.
.
CalledProcessError: Command 'C:\Users\somebody\a\place\LDA\mallet-2.0.8\bin\mallet import-file --preserve-case --keep-sequence --remove-stopwords --token-regex "\S+" --input C:\Users\somebody\AppData\Local\Temp\33b805_corpus.txt --output C:\Users\somebody\AppData\Local\Temp\33b805_corpus.mallet' returned non-zero exit status 1.

很好,超级,但是当我在cmd.exe或cygwin中运行那个确切的命令时,没有错误,代码运行得很好!我甚至可以测试返回代码: “echo $?”在cygwin中返回0.任何帮助非常感谢!

1 个答案:

答案 0 :(得分:0)

在bin目录中,使用文本编辑器打开槌文件,然后更改MEMORY限制。