code: def collate_factory(model_length_function, transforms=None):
      if transforms is None:
          transforms = torch.nn.Sequential()
  
      def collate_fn(batch):
          tensors = [transforms(b[0]) for b in batch if b]
  
          tensors_lengths = torch.tensor(
              [model_length_function(t) for t in tensors],
              dtype=torch.long,
              device=tensors[0].device,
          )
  
          tensors = torch.nn.utils.rnn.pad_sequence(
              tensors, batch_first=True
          )
          tensors = tensors.transpose(1, -1)
  
          targets = [b[1] for b in batch if b]
          target_lengths = torch.tensor(
              [target.shape[0] for target in targets],
              dtype=torch.long,
              device=tensors.device,
          )
          targets = torch.nn.utils.rnn.pad_sequence(
              targets, batch_first=True
          )
  
          return tensors, targets, tensors_lengths, target_lengths
  
      return collate_fn
  
file_path: audio/examples/pipeline_wav2letter/datasets.py
imports: import torch
  from torchaudio.datasets import LIBRISPEECH
label_desc: Use image node_id 2 for calling a global function with example usage: collate_factory(model_length_function, transforms) and returns: collate_fn, tensors,  targets,  tensors_lengths,  target_lengths