Gensim: Python 3.7.3, gensim 3.8.1: UnboundLocalError: local variable 'doc_no2' referenced before assignment

Created on 7 Nov 2019  路  4Comments  路  Source: RaRe-Technologies/gensim

Client code:
model = LogEntropyModel(corpus=data_corpus, normalize=True)
Referenced code:
https://github.com/RaRe-Technologies/gensim/blob/44ea7931c916349821aa1c717fbf7e90fb138297/gensim/models/logentropy_model.py#L115

Exception thrown:

  File "/anaconda3/lib/python3.7/site-packages/gensim/models/logentropy_model.py", line 76, in __init__
    self.initialize(corpus)
  File "/anaconda3/lib/python3.7/site-packages/gensim/models/logentropy_model.py", line 115, in initialize
    if doc_no2 != doc_no:
UnboundLocalError: local variable 'doc_no2' referenced before assignment

bug difficulty easy impact HIGH reach LOW

Most helpful comment

@paulrigor The existing tests pass.

Can you please add a new unit test to cover the bug you fixed? The test should fail without your change, and pass once your change is in place.

All 4 comments

Looks like a programming bug to me. doc_no2 should be initialized to zero, in case the corpus/generator is empty (which is what this block is actually testing).

Thanks for reporting.

I can try to patch it. I'll update and cut a PR when ready. Cheers!

@piskvorky, Here's the PR for the simple patch:

https://github.com/RaRe-Technologies/gensim/pull/2672

@paulrigor The existing tests pass.

Can you please add a new unit test to cover the bug you fixed? The test should fail without your change, and pass once your change is in place.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sairampillai picture sairampillai  路  3Comments

Jianqiang picture Jianqiang  路  3Comments

franciscojavierarceo picture franciscojavierarceo  路  3Comments

volj1 picture volj1  路  4Comments

vlad17 picture vlad17  路  4Comments