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_data"],
          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_data"],
          replacements={"data_root": data_folder},
      )
      valid_data = valid_data.filtered_sorted(sort_key="duration")
  
      test_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["test_data"],
          replacements={"data_root": data_folder},
      )
      test_data = test_data.filtered_sorted(sort_key="duration")
  
      datasets = [train_data, valid_data, test_data]
  
      # Defining tokenizer and loading it
      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("transcript")
      @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"],
      )
  
      # 5. If Dynamic Batching is used, we instantiate the needed samplers.
      train_batch_sampler = None
      valid_batch_sampler = None
      if hparams["dynamic_batching"]:
          from speechbrain.dataio.sampler import (
              DynamicBatchSampler,
          )  # noqa
  
          dynamic_hparams = hparams["dynamic_batch_sampler"]
  
          train_batch_sampler = DynamicBatchSampler(
              train_data,
              **dynamic_hparams,
              length_func=lambda x: x["duration"],
          )
  
          valid_batch_sampler = DynamicBatchSampler(
              valid_data,
              **dynamic_hparams,
              length_func=lambda x: x["duration"],
          )
  
      return (
          train_data,
          valid_data,
          test_data,
          tokenizer,
          train_batch_sampler,
          valid_batch_sampler,
      )
  
file_path: speechbrain/recipes/AISHELL-1/ASR/seq2seq/train.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.utils.distributed import run_on_main
  from hyperpyyaml import load_hyperpyyaml
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_data,  tokenizer,  train_batch_sampler,  valid_batch_sampler, sig