无法运行Gensim LDA

时间:2016-03-09 19:33:31

标签: python numpy lda gensim

我正在尝试运行分布式LDA示例,如下所述:

https://radimrehurek.com/gensim/dist_lda.html

我按照以下教程创建了一组文档:

https://radimrehurek.com/gensim/dist_lsi.html

通过“将文件扩展到1M文档,通过重复其文档”并建议

我正在使用python 3.3和numpy 1.9.2 我一直收到以下错误:

Exception in thread oneway-call:
Traceback (most recent call last):
  File "/usr/lib64/python3.3/threading.py", line 901, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.3/site-packages/Pyro4/core.py", line 1484, in run
    super(_OnewayCallThread, self).run()
  File "/usr/lib64/python3.3/threading.py", line 858, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib64/python3.3/site-packages/gensim/models/lda_worker.py", line 71, in requestjob
    self.processjob(job)
  File "/usr/lib64/python3.3/site-packages/gensim/utils.py", line 98, in _synchronizer
    result = func(self, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/gensim/models/lda_worker.py", line 80, in processjob
    self.model.do_estep(job)
  File "/usr/lib64/python3.3/site-packages/gensim/models/ldamodel.py", line 480, in do_estep
    gamma, sstats = self.inference(chunk, collect_sstats=True)
  File "/usr/lib64/python3.3/site-packages/gensim/models/ldamodel.py", line 423, in inference
    if doc and not isinstance(doc[0][0], six.integer_types):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我运行了分布式lsi示例并且运行正常,但由于某种原因我似乎无法让lda工作。

我尝试将/usr/lib64/python3.3/site-packages/gensim/models/ldamodel.py中的第423行更改为:

if doc is not None and not isinstance(doc[0][0], six.integer_types):

错误消失了,但我收到了警告

FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.

有人可以解释我做错了什么吗?我对此文件的更改是否正确?或者我应该以不同的方式运行LDA?

1 个答案:

答案 0 :(得分:0)

这是gensim中的一个bug here

编辑 - 此问题现已在this pull request中解决。