code: def data_prep(data_folder, hparams):
      "Creates the datasets and their data processing pipelines."
  
      train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=data_folder / "annotation/dev-clean.csv",
          replacements={"data_root": data_folder},
      )
  
      # start: sorting impact
      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",
              # key_max_value={"duration": hparams["avoid_if_longer_than"]},
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["dataloader_options"]["shuffle"] = False
          # hparams["dataloader_options"]["drop_last"] = True  # drops last entry which is out of order
  
      elif hparams["sorting"] == "descending":
          train_data = train_data.filtered_sorted(
              sort_key="duration",
              reverse=True,
              # key_max_value={"duration": hparams["avoid_if_longer_than"]},
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["dataloader_options"]["shuffle"] = False
          # hparams["dataloader_options"]["drop_last"] = True  # drops last entry which is out of order
  
      elif hparams["sorting"] == "random":
          # hparams["dataloader_options"]["drop_last"] = True  # reduced length from 99 to 80
          pass
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
      # end: sorting impact
  
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=data_folder / "annotation/dev-clean.csv",
          replacements={"data_root": data_folder},
      )
  
      datasets = [train_data, valid_data]
  
      # 1. Define audio pipeline:
      @sb.utils.data_pipeline.takes("duration")
      @sb.utils.data_pipeline.provides("duration")
      def audio_pipeline(duration):
          return duration
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
  
      # 3. Set output:
      sb.dataio.dataset.set_output_keys(datasets, ["id", "duration"])
  
      return train_data, valid_data
  
file_path: speechbrain/tests/integration/sampling/example_sorting.py
imports: import os
  import torch
  import pickle
  import pathlib
  import itertools
  import speechbrain
  import torch.multiprocessing
  from hyperpyyaml import load_hyperpyyaml
label_desc: Use image node_id 1 for calling a global function with example usage: data_prep(data_folder, hparams) and returns: train_data,  valid_data, duration