code: def data_prep(data_folder, hparams):
      "Creates the datasets and their data processing pipelines."
  
      # 1. Declarations:
      train_data = sb.dataio.dataset.DynamicItemDataset.from_json(
          json_path=data_folder / "../annotation/ASR_train.json",
          replacements={"data_root": data_folder},
      )
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_json(
          json_path=data_folder / "../annotation/ASR_dev.json",
          replacements={"data_root": data_folder},
      )
      datasets = [train_data, valid_data]
      char_encoder = sb.dataio.encoder.TextEncoder()
      phn_encoder = sb.dataio.encoder.TextEncoder()
  
      # 2. Define char pipeline:
      @sb.utils.data_pipeline.takes("char")
      @sb.utils.data_pipeline.provides("char_list", "char_encoded")
      def char_pipeline(char):
          char_list = char.strip().split()
          yield char_list
          char_encoded = char_encoder.encode_sequence_torch(char_list)
          yield char_encoded
  
      sb.dataio.dataset.add_dynamic_item(datasets, char_pipeline)
  
      # 3. Fit encoder:
      # NOTE: In this minimal example, also update from valid data
      char_encoder.insert_bos_eos(bos_index=hparams["bos_index"])
      char_encoder.update_from_didataset(
          train_data, output_key="char_list"
      )
      char_encoder.update_from_didataset(
          valid_data, output_key="char_list"
      )
      char_encoder.expect_len(hparams["num_chars"])
  
      # 4. Define char pipeline:
      @sb.utils.data_pipeline.takes("phn")
      @sb.utils.data_pipeline.provides(
          "phn_list", "phn_encoded_bos", "phn_encoded_eos"
      )
      def phn_pipeline(phn):
          phn_list = phn.strip().split()
          yield phn_list
          phn_encoded = phn_encoder.encode_sequence_torch(phn_list)
          phn_encoded_bos = phn_encoder.prepend_bos_index(
              phn_encoded
          ).long()
          yield phn_encoded_bos
          phn_encoded_eos = phn_encoder.append_eos_index(
              phn_encoded
          ).long()
          yield phn_encoded_eos
  
      sb.dataio.dataset.add_dynamic_item(datasets, phn_pipeline)
  
      # 5. Fit encoder:
      # NOTE: In this minimal example, also update from valid data
      phn_encoder.insert_bos_eos(bos_index=hparams["bos_index"])
      phn_encoder.update_from_didataset(
          train_data, output_key="phn_list"
      )
      phn_encoder.update_from_didataset(
          valid_data, output_key="phn_list"
      )
      phn_encoder.expect_len(hparams["num_phns"])
  
      # 6. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          ["id", "char_encoded", "phn_encoded_eos", "phn_encoded_bos"],
      )
      return train_data, valid_data
  
file_path: speechbrain/tests/integration/G2P/example_g2p.py
imports: import pathlib
  import speechbrain
  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