code: def sample_spec_nest(
      structure, seed=None, outer_dims=(), minimum=None, maximum=None
  ):
      """Samples the given nest of specs.
  
      Args:
        structure: A nest of `TensorSpec`.
        seed: A seed used for sampling ops
        outer_dims: An optional `Tensor` specifying outer dimensions to add to the
          spec shape before sampling.
        minimum: An optional numeric value. If set, numeric specs within the nest
          (both bounded and unbounded) will be restricted to this minimum.
        maximum: Similar to the above but with maximums.
  
      Returns:
        A nest of sampled values following the ArraySpec definition.
  
      Raises:
        TypeError: If `spec` is an unknown type.
        NotImplementedError: If `outer_dims` is not statically known but nest
          contains a `SparseTensorSpec`.
      """
      seed_stream = tfp.util.SeedStream(
          seed=seed, salt="sample_spec_nest"
      )
  
      def sample_fn(spec):
          """Return a composite tensor sample given `spec`.
  
          Args:
            spec: A TensorSpec, SparseTensorSpec, etc.
  
          Returns:
            A tensor or SparseTensor.
  
          Raises:
            NotImplementedError: If `outer_dims` is not statically known and a
              SparseTensor is requested.
          """
          if isinstance(spec, tf.SparseTensorSpec):
              outer_shape = tf.get_static_value(outer_dims)
              if outer_dims is not None and outer_shape is None:
                  raise NotImplementedError(
                      "outer_dims must be statically known, got: {}".format(
                          outer_dims
                      )
                  )
              shape = tf.TensorShape(outer_shape or []).concatenate(
                  spec.shape
              )
  
              if (
                  shape.num_elements() == 0
                  or tf.compat.dimension_value(shape[0]) == 0
              ):
                  return tf.SparseTensor(
                      indices=tf.zeros([0, shape.rank], dtype=tf.int64),
                      values=tf.zeros([0], dtype=spec.dtype),
                      dense_shape=shape,
                  )
  
              indices_spec = BoundedTensorSpec(
                  dtype=tf.int64,
                  shape=[7, shape.rank],
                  minimum=[0] * shape.rank,
                  maximum=[x - 1 for x in shape.as_list()],
              )
              values_dtype = (
                  tf.int32 if spec.dtype == tf.string else spec.dtype
              )
              values_spec = BoundedTensorSpec(
                  dtype=values_dtype,
                  shape=[7],
                  minimum=0,
                  maximum=shape.as_list()[-1] - 1,
              )
              values_sample = sample_bounded_spec(
                  values_spec, seed=seed_stream()
              )
              if spec.dtype == tf.string:
                  values_sample = tf.as_string(values_sample)
              return tf.sparse.reorder(
                  tf.SparseTensor(
                      indices=sample_bounded_spec(
                          indices_spec, seed=seed_stream()
                      ),
                      values=values_sample,
                      dense_shape=shape,
                  )
              )
          elif isinstance(spec, (TensorSpec, BoundedTensorSpec)):
              if spec.dtype == tf.string:
                  sample_spec = BoundedTensorSpec(
                      spec.shape, tf.int32, minimum=0, maximum=10
                  )
                  return tf.as_string(
                      sample_bounded_spec(
                          sample_spec,
                          outer_dims=outer_dims,
                          seed=seed_stream(),
                      )
                  )
              elif spec.dtype == tf.bool:
                  sample_spec = BoundedTensorSpec(
                      spec.shape, tf.int32, minimum=0, maximum=1
                  )
                  return tf.cast(
                      sample_bounded_spec(
                          sample_spec,
                          outer_dims=outer_dims,
                          seed=seed_stream(),
                      ),
                      tf.bool,
                  )
              else:
                  bounded_spec = BoundedTensorSpec.from_spec(spec)
  
                  spec_max = bounded_spec.maximum
                  if maximum is not None:
                      spec_max = min(maximum, spec_max)
  
                  spec_min = bounded_spec.minimum
                  if minimum is not None:
                      spec_min = max(minimum, spec_min)
                  bounded_spec = BoundedTensorSpec(
                      shape=bounded_spec.shape,
                      dtype=bounded_spec.dtype,
                      minimum=spec_min,
                      maximum=spec_max,
                  )
                  return sample_bounded_spec(
                      bounded_spec,
                      outer_dims=outer_dims,
                      seed=seed_stream(),
                  )
          else:
              raise TypeError(
                  "Spec type not supported: '{}'".format(spec)
              )
  
      return tf.nest.map_structure(sample_fn, structure)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from typing import Union
  import numpy
  import tensorflow
  import tensorflow_probability
  from tf_agents.specs import array_spec
  from tf_agents.typing import types
  from google.protobuf import text_format
  from tensorflow.core.protobuf import struct_pb2
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.saved_model import nested_structure_coder
label_desc: Use image node_id 12 for calling a global function with example usage: sample_spec_nest(structure, seed, outer_dims, minimum, maximum) and returns: tf, tf, tf, tf, tf, sample_bounded_spec