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
5 changes: 1 addition & 4 deletions gensim/corpora/textcorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ def sample_texts(self, n, seed=None, length=None):
if not 0 <= n:
raise ValueError("Negative sample size n {0:d}.".format(n))

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

if i == length:
break

Expand All @@ -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


def __len__(self):
if self.length is None:
Expand Down