-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes bug in LsiModel that occurs when id2word is a Python 3 dictionary. #1103
Conversation
@@ -298,7 +298,8 @@ def __init__(self, corpus=None, num_topics=200, id2word=None, chunksize=20000, | |||
self.id2word = utils.dict_from_corpus(corpus) | |||
self.num_terms = len(self.id2word) | |||
else: | |||
self.num_terms = 1 + max([-1] + self.id2word.keys()) | |||
self.num_terms = ( | |||
1 + max(self.id2word.keys()) if self.id2word else -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but keep the expression on one line please.
Done. |
@@ -298,8 +298,7 @@ def __init__(self, corpus=None, num_topics=200, id2word=None, chunksize=20000, | |||
self.id2word = utils.dict_from_corpus(corpus) | |||
self.num_terms = len(self.id2word) | |||
else: | |||
self.num_terms = ( | |||
1 + max(self.id2word.keys()) if self.id2word else -1) | |||
self.num_terms = 1 + max(self.id2word.keys()) if self.id2word else -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put brackets around the ternary expression, its reading is a little ambiguous / confusing now (1 +
not included).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks @cvangysel ! CC @tmylk LGTM. |
Thanks for the PR! |
The error message "you cannot concatenate dictionary keys with a list" is thrown when passing dictionary id2word to
gensim.models.lsimodel.LsiModel
in Python 3.