class_docstr: The collate class for HuBERT pre-training and fine-tuning.
  Args:
      feature_type (str): The type of features for KMeans clustering.
          Options: [``mfcc``, ``hubert``].
      pad (bool): If ``True``, the waveforms and labels will be padded to the
          max length in the mini-batch. If ``pad`` is False, the waveforms
          and labels will be cropped to the minimum length in the mini-batch.
          (Default: False)
      rand_crop (bool): if ``True``, the starting index of the waveform
          and label is random if the length is longer than the minimum
          length in the mini-batch.
docstr: Args:
      batch (List[Tuple(Tensor, Tensor, int)]):
          The list of tuples that contains the waveforms, labels, and audio lengths.
  
  Returns:
      Dictionary
          "input": Tuple of waveforms and lengths.
              waveforms Tensor with dimensions `(batch, time)`.
              lengths Tensor with dimension `(batch,)`.
          "label": Tuple of label Tensor with dimensions `(batch, seq)`.
docstr_tok: ["Args",":","batch","(","List","[","Tuple","(","Tensor",",","Tensor",",","int",")","]",")",":","The","list","of","tuples","that","contains","the","waveforms",",","labels",",","and","audio","lengths",".","Returns",":","Dictionary","``","input","''",":","Tuple","of","waveforms","and","lengths",".","waveforms","Tensor","with","dimensions","`","(","batch",",","time",")","`",".","lengths","Tensor","with","dimension","`","(","batch",",",")","`",".","``","label","''",":","Tuple","of","label","Tensor","with","dimensions","`","(","batch",",","seq",")","`","."]
code: def __call__(self, batch: List[Tuple[Tensor, Tensor, int]]) -> Dict:
      """
      Args:
          batch (List[Tuple(Tensor, Tensor, int)]):
              The list of tuples that contains the waveforms, labels, and audio lengths.
  
      Returns:
          Dictionary
              "input": Tuple of waveforms and lengths.
                  waveforms Tensor with dimensions `(batch, time)`.
                  lengths Tensor with dimension `(batch,)`.
              "label": Tuple of label Tensor with dimensions `(batch, seq)`.
      """
      if self.pad:
          num_frames = max([sample[0].shape[1] for sample in batch])
      else:
          num_frames = min([sample[0].shape[1] for sample in batch])
      waveforms, labels, lengths = [], [], []
      for sample in batch:
          waveform, label, length = sample
          # The MFCC feature is 10ms per frame, while the HuBERT's transformer output
          # is 20ms per frame. Downsample the KMeans label if it's generated by MFCC features.
          if self.feature_type == "mfcc":
              label = label[::2]
          waveform, label, length = _crop_audio_label(
              waveform, label, length, num_frames, self.rand_crop
          )
          waveforms.append(waveform)
          lengths.append(length)
          labels.append(label)
      # make sure the shapes are the same if not apply zero-padding
      if not self.pad:
          assert all(
              [
                  waveform.shape[0] == waveforms[0].shape[0]
                  for waveform in waveforms
              ]
          ), "The dimensions of the waveforms should be identical in the same batch."
          assert all(
              [label.shape[0] == labels[0].shape[0] for label in labels]
          ), "The dimensions of the labels should be identical in the same batch."
      waveforms = torch.nn.utils.rnn.pad_sequence(
          waveforms, batch_first=True
      )
      labels = torch.nn.utils.rnn.pad_sequence(labels, batch_first=True)
      lengths = torch.tensor(lengths)
      batch = Batch((waveforms, labels, lengths), (labels,))
      return batch
  
imports: import math
  from pathlib import Path
  from typing import Dict, Iterator, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.distributed
  import torchaudio
  from torch import Tensor
  from torch.utils.data import BatchSampler, Dataset, DistributedSampler
  from ..lightning_modules import Batch
label_desc: Use image node_id 2 for calling the CollateFnHubert obj's underlying member method code with example usage: obj.__call__(batch) and returns: batch