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

extend DummyDatasetMultipleSequenceLength #492

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions returnn/datasets/generating.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def __init__(self, input_dim, output_dim, num_seqs, seq_len=None,
"""
if seq_len is None:
seq_len = {'data': 10, 'classes': 20}
self._seq_order = None # type: typing.Optional[typing.List[int]]
super(DummyDatasetMultipleSequenceLength, self).__init__(
input_dim=input_dim,
output_dim=output_dim,
Expand Down Expand Up @@ -756,6 +757,34 @@ def generate_seq(self, seq_idx):
for i in range(i1, i2)])
return DatasetSeq(seq_idx=seq_idx, features=features, targets=targets)

def get_all_tags(self):
"""
:rtype: list[str]
"""
return ["seq-%i" % i for i in range(self._num_seqs)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._num_seqs might be inf. It should handle that correctly (fall back to the default behavior).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default behaviour?

Does it even make sense for a dummy dataset to be initialized with num_seqs=inf?
In GeneratingDataset it is per default inf but here it has to be set by the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default behaviour?

Whatever super of this function does. Just check the code.

Does it even make sense for a dummy dataset to be initialized with num_seqs=inf?

Yes it does. Why not? It's usually only used for testing. In any case, this is explicitly supported.


def init_seq_order(self, epoch=None, seq_list=None, seq_order=None):
"""
If random_shuffle_epoch1, for epoch 1 with "random" ordering, we leave the given order as is.
Otherwise, this is mostly the default behavior.

:param int|None epoch:
:param list[str]|None seq_list: List of sequence tags, to set a predefined order.
:param list[int]|None seq_order: List of corpus sequence indices, to set a predefined order.
:rtype: bool
:returns whether the order changed (True is always safe to return)
"""
super(DummyDatasetMultipleSequenceLength, self).init_seq_order(epoch=epoch, seq_list=seq_list, seq_order=seq_order)

def get_seq_len(i):
return self.seq_len['data']

self._seq_order = self.get_seq_order_for_epoch(epoch, self._num_seqs, get_seq_len=get_seq_len)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this makes sense to support for this dataset.
Also you are not using it, i.e. ignoring it (but maybe just because it's incomplete so far).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self._seq_order you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By support, I mean init_seq_order in general.
By use, I mean _seq_order.

self._num_seqs = len(self._seq_order)

def get_current_seq_order(self):
return self._seq_order


class DummyDatasetMultipleDataKeys(DummyDataset):
"""
Expand Down