code: def test_encoding(self):
      f = feature_lib.Sequence(
          {
              "a": feature_lib.Sequence({"c": np.int64}),
              "b": np.int64,
          }
      )
  
      # Different combinaison of list of dict/dict of list to encode the same
      # nested sequence
      ex1 = f.encode_example(
          [
              {"a": {"c": [1, 1, 1]}, "b": 1},
              {"a": {"c": []}, "b": 2},
              {"a": {"c": [3, 3]}, "b": 3},
          ]
      )
  
      ex2 = f.encode_example(
          [
              {"a": [{"c": 1}, {"c": 1}, {"c": 1}], "b": 1},
              {"a": [], "b": 2},
              {"a": [{"c": 3}, {"c": 3}], "b": 3},
          ]
      )
  
      ex3 = f.encode_example(
          {
              "a": [
                  [{"c": 1}, {"c": 1}, {"c": 1}],
                  [],
                  [{"c": 3}, {"c": 3}],
              ],
              "b": [1, 2, 3],
          }
      )
  
      ex4 = f.encode_example(
          {
              "a": {"c": [[1, 1, 1], [], [3, 3]]},
              "b": [1, 2, 3],
          }
      )
  
      out = {
          "a": {
              "c": tf.ragged.constant(
                  [
                      [1, 1, 1],
                      [],
                      [3, 3],
                  ]
              )
          },
          "b": [1, 2, 3],
      }
  
      def to_ragged(ex):
          ex["a"]["c"] = tf.ragged.constant(ex["a"]["c"])
          return ex
  
      self.assertAllEqualNested(to_ragged(ex1), out)
      self.assertAllEqualNested(to_ragged(ex2), out)
      self.assertAllEqualNested(to_ragged(ex3), out)
      self.assertAllEqualNested(to_ragged(ex4), out)
  
      # Should raise error if two sequences do not have the same length.
      with self.assertRaisesWithPredicateMatch(
          ValueError, "length of all elements"
      ):
          f.encode_example(
              {
                  "a": {"c": [[1, 1, 1], []]},
                  "b": [1, 2, 3],
              }
          )
  
      # Empty sequence should create the correct number of dimension
      ex2 = f.encode_example([])
      self.assertAllEqualNested(
          ex2,
          {
              "a": {"c": np.zeros((0, 0), np.int64)},
              "b": np.zeros((0,), np.int64),
          },
      )
  
imports: import numpy
  import tensorflow
  from tensorflow_datasets import testing
  from tensorflow_datasets.core import features
label_desc: Use image node_id 4 for calling the SequenceDictFeatureTest obj's underlying member method code with example usage: obj.test_encoding() and returns: ex