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 assess in DynamicTimeSeriesBucket when max_total_size is used #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion lazy_dataset/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,13 @@ def is_completed(self):

def assess(self, example):
seq_len = self.len_key(example)
return self.lower_bound <= seq_len <= self.upper_bound
return (
(self.lower_bound <= seq_len <= self.upper_bound)
and (
(self.max_total_size is None)
or ((len(self.data) + 1) * max(self.max_len, seq_len) <= self.max_total_size)
)
)

def _append(self, example):
super()._append(example)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ def test_bucket():
assert dynamic_batched_buckets == [
[10, 5], [7, 8], [1, 2], [4, 3], [6, 9], [20], [1]
]


def test_max_total_size():
examples = [6, 7, 9, 5, 6, 3, 7, 4]
examples = {str(j): i for j, i in enumerate(examples)}
ds = lazy_dataset.new(examples)

dynamic_batched_buckets = list(ds.batch_dynamic_time_series_bucket(
batch_size=3, len_key=lambda x: x, max_padding_rate=0.9, max_total_size=21,
))
assert dynamic_batched_buckets == [
[6, 7, 5], [9, 6], [3, 7, 4]
]
Loading