Skip to content
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

Merged
merged 10 commits into from
Aug 24, 2017

Conversation

vlejd
Copy link
Contributor

@vlejd vlejd commented Jun 22, 2017

Related to #308.

Fix comments in #1422.

for i, sample in enumerate(self.get_texts()):
seen_documents = i + 1
Copy link
Owner

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?

Copy link
Owner

@piskvorky piskvorky Jun 23, 2017

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).

Copy link
Contributor Author

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.

Copy link
Owner

@piskvorky piskvorky Jul 5, 2017

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.

@piskvorky piskvorky changed the title 308 random sample on stream Random sample on stream Jul 2, 2017
@menshikh-iv
Copy link
Contributor

Ping @vlejd, when you finish your PR?

@menshikh-iv
Copy link
Contributor

Thank you @vlejd

@menshikh-iv menshikh-iv merged commit 164b8b0 into piskvorky:develop Aug 24, 2017
@@ -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))
Copy link
Owner

@piskvorky piskvorky Aug 24, 2017

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).

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants