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.
  
  
      Arguments
      ---------
      hparams : dict
          This dictionary is loaded from the `train.yaml` file, and it includes
          all the hyperparameters needed for dataset construction and loading.
  
      Returns
      -------
      datasets : dict
          Dictionary containing "train", "valid", and "test" keys that correspond
          to the DynamicItemDataset objects.
      """
  
      # Define audio pipeline. In this case, we simply read the path contained
      # in the variable wav with the audio reader.
      @sb.utils.data_pipeline.takes("wav")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav):
          """Load the audio signal. This is done on the CPU in the `collate_fn`."""
          sig = sb.dataio.dataio.read_audio(wav)
          return sig
  
      # Define text processing pipeline. We start from the raw text and then
      # encode it using the tokenizer. The tokens with BOS are used for feeding
      # decoder during training, the tokens with EOS for computing the cost function.
      # The tokens without BOS or EOS is for computing CTC loss.
      @sb.utils.data_pipeline.takes("words")
      @sb.utils.data_pipeline.provides(
          "words", "tokens_list", "tokens_bos", "tokens_eos", "tokens"
      )
      def text_pipeline(words):
          """Processes the transcriptions to generate proper labels"""
          yield words
          tokens_list = hparams["tokenizer"].encode_as_ids(words)
          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
  
      # Define datasets from json data manifest file
      # Define datasets sorted by ascending lengths for efficiency
      datasets = {}
      data_folder = hparams["data_folder"]
      data_info = {
          "train": hparams["train_annotation"],
          "valid": hparams["valid_annotation"],
          "test": hparams["test_annotation"],
      }
  
      for dataset in data_info:
          datasets[
              dataset
          ] = sb.dataio.dataset.DynamicItemDataset.from_json(
              json_path=data_info[dataset],
              replacements={"data_root": data_folder},
              dynamic_items=[audio_pipeline, text_pipeline],
              output_keys=[
                  "id",
                  "sig",
                  "words",
                  "tokens_bos",
                  "tokens_eos",
                  "tokens",
              ],
          )
          hparams[f"{dataset}_dataloader_opts"]["shuffle"] = False
  
      # Sorting training data with ascending order makes the code  much
      # faster  because we minimize zero-padding. In most of the cases, this
      # does not harm the performance.
      if hparams["sorting"] == "ascending":
          datasets["train"] = datasets["train"].filtered_sorted(
              sort_key="length"
          )
          hparams["train_dataloader_opts"]["shuffle"] = False
  
      elif hparams["sorting"] == "descending":
          datasets["train"] = datasets["train"].filtered_sorted(
              sort_key="length", reverse=True
          )
          hparams["train_dataloader_opts"]["shuffle"] = False
  
      elif hparams["sorting"] == "random":
          hparams["train_dataloader_opts"]["shuffle"] = True
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
      return datasets
  
file_path: orion/examples/speechbrain_tutorial/train.py
imports: import logging
  import sys
  import speechbrain
  import torch
  from hyperpyyaml import load_hyperpyyaml
  from mini_librispeech_prepare import prepare_mini_librispeech
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: datasets, sig