code: def _dict_to_tf_example(
      example_dict: Mapping[str, Any],
      tensor_info_dict: Mapping[str, feature_lib.TensorInfo],
  ) -> tf_example_pb2.Example:
      """Builds tf.train.Example from (string -> int/float/str list) dictionary.
  
      Args:
        example_dict: `dict`, dict of values, tensor,...
        tensor_info_dict: `dict` of `tfds.features.TensorInfo`
  
      Returns:
        example_proto: `tf.train.Example`, the encoded example proto.
      """
  
      def run_with_reraise(fn, k, example_data, tensor_info):
          try:
              return fn(example_data, tensor_info)
          except Exception as e:  # pylint: disable=broad-except
              utils.reraise(
                  e,
                  f"Error while serializing feature `{k}`: `{tensor_info}`: ",
              )
  
      # Add the RaggedTensor fields for the nested sequences
      # Nested sequences are encoded as {'flat_values':, 'row_lengths':}, so need
      # to flatten the example nested dict again.
      # Ex:
      # Input: {'objects/tokens': [[0, 1, 2], [], [3, 4]]}
      # Output: {
      #     'objects/tokens/flat_values': [0, 1, 2, 3, 4],
      #     'objects/tokens/row_lengths_0': [3, 0, 2],
      # }
      features = utils.flatten_nest_dict(
          {
              k: run_with_reraise(
                  _add_ragged_fields, k, example_dict[k], tensor_info
              )
              for k, tensor_info in tensor_info_dict.items()
          }
      )
      features = {
          k: run_with_reraise(_item_to_tf_feature, k, item, tensor_info)
          for k, (item, tensor_info) in features.items()
      }
      return tf_example_pb2.Example(
          features=tf_feature_pb2.Features(feature=features)
      )
  
imports: from __future__ import annotations
  import abc
  import collections
  import dataclasses
  from typing import Any, Mapping, Union
  import numpy
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.features import feature
  from tensorflow_datasets.core.utils import dtype_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  from tensorflow_datasets.proto import tf_example_pb2
  from tensorflow_datasets.proto import tf_feature_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: _dict_to_tf_example(example_dict, tensor_info_dict) and returns: tf_example_pb2, fn