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

fix the total number of returned lines in setup_iter func in RawTextIterableDataset #1142

Merged
merged 2 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/data/test_builtin_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def test_text_classification(self):
self._helper_test_func(len(test_iter), 7600, next(iter(test_iter))[1][:25], 'Fears for T N pension aft')
del train_iter, test_iter

def test_num_lines_of_setup_iter_dataset(self):
train_iter, test_iter = torchtext.experimental.datasets.raw.AG_NEWS()
train_iter.setup_iter(start=10, num_lines=100)
_data = [item for item in train_iter]
self.assertEqual(len(_data), 100)

def test_imdb(self):
from torchtext.experimental.datasets import IMDB
from torchtext.vocab import Vocab
Expand Down
2 changes: 1 addition & 1 deletion torchtext/experimental/datasets/raw/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __iter__(self):
for i, item in enumerate(self._iterator):
if i < self.start:
continue
if self.num_lines and i > (self.start + self.num_lines):
if self.num_lines and i >= (self.start + self.num_lines):
break
yield item

Expand Down