code: def test_categorical_encoder_from_dataset():
      from speechbrain.dataio.encoder import CategoricalEncoder
      from speechbrain.dataio.dataset import DynamicItemDataset
  
      encoder = CategoricalEncoder()
      data = {
          "utt1": {"foo": -1, "bar": 0, "text": "hello world"},
          "utt2": {"foo": 1, "bar": 2, "text": "how are you world"},
          "utt3": {"foo": 3, "bar": 4, "text": "where are you world"},
          "utt4": {"foo": 5, "bar": 6, "text": "hello nation"},
      }
      dynamic_items = [
          {
              "func": lambda x: x.split(),
              "takes": ["text"],
              "provides": "words",
          },
          {
              "func": encoder.encode_sequence,
              "takes": ["words"],
              "provides": "words_t",
          },
      ]
      output_keys = ["words_t"]
      dataset = DynamicItemDataset(data, dynamic_items, output_keys)
      encoder.update_from_didataset(
          dataset, "words", sequence_input=True
      )
      encoder.expect_len(7)
      assert dataset[0]["words_t"] == [0, 1]
      assert encoder.decode_ndim(dataset[0]["words_t"]) == [
          "hello",
          "world",
      ]
  
imports: import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: test_categorical_encoder_from_dataset() without return types