code: def _extract_type_spec_recursively(value):
      """Return (collection of) TypeSpec(s) for `value` if it includes `Tensor`s.
  
      If `value` is a `Tensor` or `CompositeTensor`, return its `TypeSpec`. If
      `value` is a collection containing `Tensor` values, recursively supplant them
      with their respective `TypeSpec`s in a collection of parallel stucture.
  
      If `value` is none of the above, return it unchanged.
  
      Args:
        value: a Python `object` to (possibly) turn into a (collection of)
        `tf.TypeSpec`(s).
  
      Returns:
        spec: the `TypeSpec` or collection of `TypeSpec`s corresponding to `value`;
        `value`, if no `Tensor`s are found; or `None` to indicate that `value` is
        registered as a JAX pytree.
      """
      if isinstance(value, composite_tensor.CompositeTensor):
          return value._type_spec  # pylint: disable=protected-access
      if isinstance(value, tf.Variable):
          return resource_variable_ops.VariableSpec(
              value.shape, dtype=value.dtype, trainable=value.trainable
          )
      if tf.is_tensor(value):
          return tf.TensorSpec(value.shape, value.dtype)
      if tf.nest.is_nested(value):
          specs = tf.nest.map_structure(
              _extract_type_spec_recursively, value
          )
          was_tensor = tf.nest.flatten(
              tf.nest.map_structure(
                  lambda a, b: a is not b, value, specs
              )
          )
          has_tensors = any(was_tensor)
          has_only_tensors = all(was_tensor)
          if has_tensors:
              if has_tensors != has_only_tensors:
                  raise NotImplementedError(
                      "Found `{}` with both Tensor and non-Tensor parts: {}".format(
                          type(value), value
                      )
                  )
              return specs
      elif JAX_MODE:  # Handle custom pytrees.
          from jax import (
              tree_util,
          )  # pylint: disable=g-import-not-at-top
  
          treedef = tree_util.tree_structure(value)
          # Return None so that the object identity comparison in
          # `_AutoCompositeTensorTypeSpec.from_instance` is False, indicating that
          # `value` should be treated as a "Tensor" param.
          if not tree_util.treedef_is_leaf(treedef):
              return None
      return value
  
imports: import contextlib
  import functools
  import threading
  import numpy
  import tensorflow.compat.v2
  from tensorflow.python.framework import composite_tensor
  from tensorflow.python.framework import type_spec
  from tensorflow.python.framework import type_spec_registry
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.util import tf_inspect
  from tensorflow.python.util import variable_utils
label_desc: Use image node_id 6 for calling a global function with example usage: _extract_type_spec_recursively(value) and returns: value, value, resource_variable_ops, tf, specs, None