【发布时间】:2017-10-24 02:10:53
【问题描述】:
标题几乎说明了一切。下面是一些测试代码:
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 中运行那个确切的命令时,没有错误,代码运行得很好!我什至可以测试返回码: “回声$?”在 cygwin 中返回 0。非常感谢任何帮助!
【问题讨论】:
标签: python subprocess gensim lda mallet