Skip to content

HdpModel gets into infinite loop on empty input corpus #2563

@leftvalue

Description

@leftvalue

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestIssues marked for hacktoberfestbugIssue described a bugimpact LOWLow impact on affected usersreach LOWAffects only niche use-case users

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions