torchsig.utils.data_loading.metadata_padding_collate_fn¶
- torchsig.utils.data_loading.metadata_padding_collate_fn(batch)[source]¶
Collate a batch of (data, metadata_list) pairs, padding metadata to equal lengths.
- Metadata for each sample is a list of dicts. This function:
Finds the maximum metadata-list length in the batch.
Pads shorter metadata lists with default values.
Stacks data tensors and metadata fields into batched tensors.
- Parameters:
batch – A list where each element is a tuple of: - x: any object convertible to a NumPy array (e.g., tensor, array). - y: a list of metadata dicts, where each dict shares the same set of keys.
- Returns:
data_tensor: stacked torch.Tensor of all x values, shape (batch_size, …).
metadata_tensors: dict mapping each metadata key to a Tensor of shape (batch_size, max_sequence_length).
- Return type:
A tuple containing
- Raises:
ValueError – if any element in batch is not a tuple of length 2.