piskvorky/gensim

HdpModel gets into infinite loop on empty input corpus

Open

#2,563 opened on Jul 28, 2019

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Python (4,349 forks)batch import
Hacktoberfestbugimpact LOWreach LOW

Repository metrics

Stars
 (15,144 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Problem description

Hi ~ I find that when I give a empty array as corpus to the constructor of HdpModel, it would never ends,the program got an endless loop.

I know I really should check the corpus to make sure it cannot be an empty array,but perhaps the HdpModel constructor should raise an Exception at once instead of endless-loop without any message(which perhaps make some new learner confused )

Steps/code/corpus to reproduce

You can repeat the problem I found before


# _*_ coding=utf-8 _*_
from gensim import corpora
from gensim.models import HdpModel

if __name__ == '__main__':
    dic = corpora.Dictionary([])
    print(1)
   m = HdpModel(corpus=[], id2word=dic, alpha=1, T=500)
    print('this will never be print')

in actually, when the corpus is [](an empty list),the HdpModel's constructor call the

 if corpus is not None:
            self.update(corpus)

and in the update function, when the corpus is empty array, the "while True" loop will never ends .It just because of that "utils.grouper(corpus, self.chunksize)" in "while True" is an empty generator too, " for chunk in utils.grouper" will never happen, caused the while-True loop never ends.

That's very nice of you to see the issue, I am not a native English speaker,so please forgive my pool English .If you have any question, just communicate with me .

Contributor guide