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.
      """
      data_folder = hparams["data_folder"]
  
      train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["train_csv"],
          replacements={"data_root": data_folder},
      )
  
      if hparams["sorting"] == "ascending":
          # we sort training data to speed up training and get better results.
          train_data = train_data.filtered_sorted(sort_key="duration")
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["train_dataloader_opts"]["shuffle"] = False
  
      elif hparams["sorting"] == "descending":
          train_data = train_data.filtered_sorted(
              sort_key="duration", reverse=True
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["train_dataloader_opts"]["shuffle"] = False
  
      elif hparams["sorting"] == "random":
          pass
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
  
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["valid_csv"],
          replacements={"data_root": data_folder},
      )
      valid_data = valid_data.filtered_sorted(sort_key="duration")
  
      # test is separate
      test_datasets = {}
      for csv_file in hparams["test_csv"]:
          name = Path(csv_file).stem
          test_datasets[
              name
          ] = sb.dataio.dataset.DynamicItemDataset.from_csv(
              csv_path=csv_file, replacements={"data_root": data_folder}
          )
          test_datasets[name] = test_datasets[name].filtered_sorted(
              sort_key="duration"
          )
  
      datasets = [train_data, valid_data] + [
          i for k, i in test_datasets.items()
      ]
  
      # We get the tokenizer as we need it to encode the labels when creating
      # mini-batches.
      tokenizer = hparams["tokenizer"]
  
      # 2. Define audio pipeline:
      @sb.utils.data_pipeline.takes("wav")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav):
          sig = sb.dataio.dataio.read_audio(wav)
          return sig
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
  
      # 3. Define text pipeline:
      @sb.utils.data_pipeline.takes("wrd")
      @sb.utils.data_pipeline.provides(
          "wrd", "tokens_list", "tokens_bos", "tokens_eos", "tokens"
      )
      def text_pipeline(wrd):
          yield wrd
          tokens_list = tokenizer.encode_as_ids(wrd)
          yield tokens_list
          tokens_bos = torch.LongTensor(
              [hparams["bos_index"]] + (tokens_list)
          )
          yield tokens_bos
          tokens_eos = torch.LongTensor(
              tokens_list + [hparams["eos_index"]]
          )
          yield tokens_eos
          tokens = torch.LongTensor(tokens_list)
          yield tokens
  
      sb.dataio.dataset.add_dynamic_item(datasets, text_pipeline)
  
      # 4. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          ["id", "sig", "wrd", "tokens_bos", "tokens_eos", "tokens"],
      )
      train_batch_sampler = None
      valid_batch_sampler = None
      if hparams["dynamic_batching"]:
          from speechbrain.dataio.sampler import (
              DynamicBatchSampler,
          )  # noqa
          from speechbrain.dataio.dataloader import (
              SaveableDataLoader,
          )  # noqa
          from speechbrain.dataio.batch import PaddedBatch  # noqa
  
          dynamic_hparams = hparams["dynamic_batch_sampler"]
          hop_size = hparams["feats_hop_size"]
  
          train_batch_sampler = DynamicBatchSampler(
              train_data,
              length_func=lambda x: x["duration"] * (1 / hop_size),
              **dynamic_hparams,
          )
  
          valid_batch_sampler = DynamicBatchSampler(
              valid_data,
              length_func=lambda x: x["duration"] * (1 / hop_size),
              **dynamic_hparams,
          )
  
      return (
          train_data,
          valid_data,
          test_datasets,
          train_batch_sampler,
          valid_batch_sampler,
      )
  
file_path: speechbrain/recipes/LibriSpeech/ASR/seq2seq/train.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.utils.distributed import run_on_main, if_main_process
  from hyperpyyaml import load_hyperpyyaml
  from pathlib import Path
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: train_data,  valid_data,  test_datasets,  train_batch_sampler,  valid_batch_sampler, sig