code: def apply_sort(hparams, dataset):
      if hparams["sort"]:
          dataset = dataset.filtered_sorted(sort_key=hparams["sort"])
      if hparams["batch_shuffle"]:
          dataset = dataset.batch_shuffle(hparams["batch_size"])
      return dataset
  
imports: import logging
  import sys
  import torch
  import speechbrain
  import os
  from collections import namedtuple
  from audiomnist_prepare import prepare_audiomnist
  from hyperpyyaml import load_hyperpyyaml
  from torchaudio import functional
  from speechbrain.dataio.dataio import length_to_mask, write_audio
  from speechbrain.dataio.dataset import apply_overfit_test
  from speechbrain.utils import data_utils
  from speechbrain.utils.train_logger import plot_spectrogram
  from enum import Enum
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.utils.data_utils import dict_value_combinations, dist_stats, masked_mean, masked_min, masked_max, masked_std, match_shape
label_desc: Use image node_id 2 for calling a global function with example usage: apply_sort(hparams, dataset) and returns: dataset