【问题标题】:Python topic modelling error in mallet槌中的Python主题建模错误
【发布时间】:2018-06-07 13:05:47
【问题描述】:

您好,我正在使用 gensim 进行主题建模,并且正在使用 Mallet 并正在执行此代码,我在 C 驱动器中解压缩了 mallet,如图所示,还设置了环境 MALLET_HOME 命令。我正在执行的代码是

mallet_path = r'c:/mallet-2.0.8/bin/mallet'
ldamallet = gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, 
num_topics=20, id2word=id2word)

这给了我这样的错误

CalledProcessError                        Traceback (most recent call last)
<ipython-input-58-6e0dbb876ee6> in <module>()
----> 1 ldamallet = gensim.models.wrappers.LdaMallet(mallet_path, 
corpus=corpus, 
   num_topics=20, id2word=id2word)

~\AppData\Local\Continuum\anaconda3\lib\site- 
packages\gensim\models\wrappers\ldamallet.py in __init__(self, mallet_path, 
corpus, num_topics, alpha, id2word, workers, prefix, optimize_interval, 
iterations, topic_threshold)
124         self.iterations = iterations
125         if corpus is not None:
--> 126             self.train(corpus)
127 
128     def finferencer(self):

~\AppData\Local\Continuum\anaconda3\lib\site- 
packages\gensim\models\wrappers\ldamallet.py in train(self, corpus)
265 
266         """
--> 267         self.convert_input(corpus, infer=False)
268         cmd = self.mallet_path + ' train-topics --input %s --num-topics 
%s  --alpha %s --optimize-interval %s '\
269             '--num-threads %s --output-state %s --output-doc-topics %s - 
-output-topic-keys %s '\

~\AppData\Local\Continuum\anaconda3\lib\site- 
packages\gensim\models\wrappers\ldamallet.py in convert_input(self, corpus, 
infer, serialize_corpus)
254             cmd = cmd % (self.fcorpustxt(), self.fcorpusmallet())
255         logger.info("converting temporary corpus to MALLET format with 
%s", cmd)
--> 256         check_output(args=cmd, shell=True)
257 
258     def train(self, corpus):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\utils.py in 
check_output(stdout, *popenargs, **kwargs)
1804             error = subprocess.CalledProcessError(retcode, cmd)
1805             error.output = output
-> 1806             raise error
1807         return output
1808     except KeyboardInterrupt:`

CalledProcessError: Command 'c:\mallet-2.0.8\bin\mallet import-file -- 
preserve-case --keep-sequence --remove-stopwords --token-regex "\S+" --input 
C:\Users\apath009\AppData\Local\Temp\d186ea_corpus.txt --output 
C:\Users\apath009\AppData\Local\Temp\d186ea_corpus.mallet' returned non-zero 
exit status 1.

请帮忙!!!

【问题讨论】:

    标签: python-3.x topic-modeling mallet


    【解决方案1】:

    我也有这个错误,但现在它正在工作。我不确定我做了什么让它开始工作,但我会详细说明我所做的一切。

    首先,我遵循此链接中的所有内容,通过 3 个步骤获得答案(粘贴在下面): Error when implementing gensim.LdaMallet

    1. 确保设置了MALLET_HOME

    2. 在 Python 中设置 mallet_path 时转义斜线

      mallet_path = 'c:\\mallet-2.0.8\\bin\\mallet'
      LDA_model = gensim.models.LdaMallet(mallet_path, ...
      
    3. 另外,修改Python\Lib\site-packages\gensim\models\ldamallet.py:中的第142行更改--token-regex '\S+' to --token-regex \"\S+\"可能会有用

    但我仍然收到错误消息。接下来,我的电脑是双启动的,所以我启动了 lubuntu,安装了 java、python3、gensim,并将 mallet 文件夹复制到 lubuntu 分区。我使用与 windows 相同的代码运行了一个测试 python 文件,但使用来自 lubuntu 终端的新槌目录/home/Desktop/mallet-2.0.8/bin/mallet。有效。然后我重新启动到 Windows,突然它也可以在 Windows 上运行。

    【讨论】:

      【解决方案2】:

      检查您是否已正确安装 Java,并且您已设置 JAVA_HOME 系统变量,并且您已将 %JAVA_HOME%\bin 添加到 PATH 全局系统变量中。

      完成后重新启动计算机以使更改生效。

      这对我有用。

      【讨论】:

        猜你喜欢
        • 2011-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-14
        • 1970-01-01
        • 2015-01-02
        相关资源
        最近更新 更多