code: def _validate_transition(
      value: trajectory.Transition,
      transition_spec: trajectory.Transition,
      num_outer_dims: int,
  ):
      """Checks the given Transition for batch and time outer dimensions."""
  
      if value.action_step.state:
          # When state is not (), it does not have time dimension, therefore it needs
          # to be validated separately.
          _validate_state(
              value.action_step.state, transition_spec.action_step.state
          )
          action_step_without_state = value.action_step._replace(
              state=()
          )
          value_to_validate = value._replace(
              action_step=action_step_without_state
          )
          action_spec_without_state = (
              transition_spec.action_step._replace(state=())
          )
          spec_to_validate = transition_spec._replace(
              action_step=action_spec_without_state
          )
      else:
          value_to_validate = value
          spec_to_validate = transition_spec
  
      if not nest_utils.is_batched_nested_tensors(
          value_to_validate,
          spec_to_validate,
          num_outer_dims=num_outer_dims,
          allow_extra_fields=True,
      ):
          debug_str_1 = tf.nest.map_structure(
              lambda tp: tp.shape, value_to_validate
          )
          debug_str_2 = tf.nest.map_structure(
              lambda spec: spec.shape, spec_to_validate
          )
          raise ValueError(
              "All of the Tensors in `value` must have a single outer (batch size) "
              "dimension. Specifically, tensors must have {} outer dimensions."
              "\nFull shapes of value tensors:\n  {}.\n"
              "Expected shapes (excluding the outer dimensions):\n  {}.".format(
                  num_outer_dims, debug_str_1, debug_str_2
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import typing
  import tensorflow
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import composite
  from tf_agents.utils import nest_utils
  import typing_extensions
label_desc: Use image node_id 5 for calling a global function with example usage: _validate_transition(value, transition_spec, num_outer_dims) without return types