code: def dataio_prepare(hparams):
      """This function prepares the datasets to be used in the brain class.
      It also defines the data processing pipeline through user-defined functions.
      """
  
      # 1. Define datasets:
      csv_folder = hparams["save_folder"] + "/csv"
  
      train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["csv_train"],
          replacements={"data_root": csv_folder},
      )
  
      # We sort training data to speed up training and get better results.
      # When sorting do not shuffle in dataloader ! otherwise is pointless.
      if hparams["sorting"] == "ascending":
          train_data = train_data.filtered_sorted(
              sort_key="duration",
              key_max_value={
                  "duration": hparams["avoid_if_longer_than"]
              },
              key_min_value={
                  "duration": hparams["avoid_if_smaller_than"]
              },
          )
          hparams["dataloader_options"]["shuffle"] = False
      elif hparams["sorting"] == "descending":
          train_data = train_data.filtered_sorted(
              sort_key="duration",
              reverse=True,
              key_max_value={
                  "duration": hparams["avoid_if_longer_than"]
              },
              key_min_value={
                  "duration": hparams["avoid_if_smaller_than"]
              },
          )
          hparams["dataloader_options"]["shuffle"] = False
      elif hparams["sorting"] == "random":
          train_data = train_data.filtered_sorted(
              key_max_value={
                  "duration": hparams["avoid_if_longer_than"]
              },
              key_min_value={
                  "duration": hparams["avoid_if_smaller_than"]
              },
          )
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
  
      # We also sort the validation data so it is faster to validate.
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["csv_valid"],
          replacements={"data_root": csv_folder},
      )
      valid_data = valid_data.filtered_sorted(
          sort_key="duration", reverse=True
      )
  
      # We also sort the test data so it is faster to validate.
      test_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["csv_test"],
          replacements={"data_root": csv_folder},
      )
      test_data = test_data.filtered_sorted(
          sort_key="duration", reverse=True
      )
  
      datasets = [train_data, valid_data, test_data]
  
      label_encoder = sb.dataio.encoder.CTCTextEncoder()
  
      # 2. Define audio pipeline:
      @sb.utils.data_pipeline.takes("wav", "start", "stop")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav, start, stop):
          start = int(float(start) * hparams["sample_rate"])
          stop = int(float(stop) * hparams["sample_rate"])
          speech_segment = {"file": wav, "start": start, "stop": stop}
          sig = sb.dataio.dataio.read_audio(speech_segment)
          return sig
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
  
      # 3. Define text pipeline:
      @sb.utils.data_pipeline.takes("char")
      @sb.utils.data_pipeline.provides("char_list", "char_encoded")
      def text_pipeline(char):
          char_list = char.strip().split()
          yield char_list
          char_encoded = label_encoder.encode_sequence_torch(char_list)
          yield char_encoded
  
      sb.dataio.dataset.add_dynamic_item(datasets, text_pipeline)
  
      # 4. Create a label encoder instead of a tokenizer for our tag list:
      lab_enc_file = hparams["save_folder"] + "/labelencoder.txt"
      label_encoder.load_or_create(
          path=lab_enc_file,
          from_didatasets=[train_data],
          output_key="char_list",
          special_labels={"blank_label": hparams["blank_index"]},
          sequence_input=True,
      )
  
      # 5. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          ["id", "sig", "char_encoded"],
      )
  
      # 6. Make DataLoaders and shuffle if needed:
      dataloader_train = torch.utils.data.DataLoader(
          train_data,
          batch_size=hparams["batch_size"],
          num_workers=hparams["dataloader_options"]["num_workers"],
          collate_fn=PaddedBatch,
          shuffle=hparams["dataloader_options"]["shuffle"],
      )
      dataloader_valid = torch.utils.data.DataLoader(
          valid_data,
          batch_size=hparams["batch_size"],
          num_workers=hparams["dataloader_options"]["num_workers"],
          collate_fn=PaddedBatch,
          shuffle=hparams["dataloader_options"]["shuffle"],
      )
      dataloader_test = torch.utils.data.DataLoader(
          test_data,
          batch_size=hparams["test_batch_size"],
          num_workers=hparams["test_dataloader_options"]["num_workers"],
          collate_fn=PaddedBatch,
      )
  
      return (
          dataloader_train,
          dataloader_valid,
          dataloader_test,
          label_encoder,
      )
  
file_path: speechbrain/recipes/MEDIA/SLU/CTC/train_hf_wav2vec.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.dataio.batch import PaddedBatch
  from speechbrain.utils.distributed import run_on_main
  from media_prepare import prepare_media
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: dataloader_train,  dataloader_valid,  dataloader_test,  label_encoder, sig