-
-
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
Random sample on stream #1444
Random sample on stream #1444
Conversation
gensim/corpora/textcorpus.py
Outdated
for i, sample in enumerate(self.get_texts()): | ||
seen_documents = i + 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.
What is the purpose of introducing this new variable?
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.
Oh I think I see -- you can directly re-use the counter i
from enumerate (just give it a better name, such as seen_documents
).
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.
It may be only my personal opinion, but I do not like this type of "variable leaking" out of the for loop scope.
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.
OK, why not. Then I suggest seen_documents += 1
at least. This pattern is too obscure.
Ping @vlejd, when you finish your PR? |
Thank you @vlejd |
gensim/corpora/textcorpus.py
Outdated
@@ -305,7 +302,7 @@ def sample_texts(self, n, seed=None, length=None): | |||
# This means that length was set to be greater than number of items in corpus | |||
# and we were not able to sample enough documents before the stream ended. | |||
raise ValueError( | |||
"length {0:d} greater than number of documents in corpus {1:d}".format(length, seen_documents)) | |||
"length {0:d} greater than number of documents in corpus {1:d}".format(length, i + 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.
This will fail with an exception if there are no texts (i
will be undefined).
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.
i
undefined if only self.getstream()
is empty
Related to #308.
Fix comments in #1422.