examples/research_projects/xtreme-s/run_xtreme_s.py/SpeechDataCollatorWithPadding/__call__
class SpeechDataCollatorWithPadding:    def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
        # split inputs and labels since they have to be of different lenghts and need
        # different padding methods
        input_features = [{"input_values": feature["input_values"]} for feature in features]

        batch = self.processor.pad(
            input_features,
            padding=self.padding,
            pad_to_multiple_of=self.pad_to_multiple_of,
            return_tensors="pt",
        )

        if self.pad_labels:
            label_features = [{"input_ids": feature["labels"]} for feature in features]
            labels_batch = self.processor.pad(
                labels=label_features,
                padding=self.padding,
                pad_to_multiple_of=self.pad_to_multiple_of_labels,
                return_tensors="pt",
            )

            # replace padding with -100 to ignore loss correctly
            labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)

            # if bos token is appended in previous tokenization step,
            # cut bos token here as it's append later anyways
            if (
                self.decoder_start_token_id is not None
                and (labels[:, 0] == self.decoder_start_token_id).all().cpu().item()
            ):
                labels = labels[:, 1:]

            batch["labels"] = labels
        else:
            batch["labels"] = torch.tensor([feature["labels"] for feature in features])

        return batch