code: def testCtcLossV2(self):
      random_seed.set_random_seed(5)
  
      batch_size = 8
      num_labels = 6
      max_label_length = 5
      num_frames = 12
  
      labels = random_ops.random_uniform(
          [batch_size, max_label_length],
          minval=1,
          maxval=num_labels,
          dtype=dtypes.int64,
      )
      logits = random_ops.random_uniform(
          [num_frames, batch_size, num_labels]
      )
  
      label_length = random_ops.random_uniform(
          [batch_size],
          minval=2,
          maxval=max_label_length,
          dtype=dtypes.int64,
      )
      label_mask = array_ops.sequence_mask(
          label_length,
          maxlen=max_label_length,
          dtype=label_length.dtype,
      )
      labels *= label_mask
      logit_length = [num_frames] * batch_size
  
      with backprop.GradientTape() as t:
          t.watch(logits)
          ref_loss = ctc_ops.ctc_loss_v2(
              labels=labels,
              logits=logits,
              label_length=label_length,
              logit_length=logit_length,
          )
      ref_grad = t.gradient(ref_loss, [logits])
  
      sparse_labels = ctc_ops.dense_labels_to_sparse(
          labels, label_length
      )
  
      def assert_same_loss_and_grads(loss):
          if context.executing_eagerly():
              return
          with self.cached_session():
              self.assertAllClose(*self.evaluate([loss, ref_loss]))
              grad = gradients_impl.gradients(loss, [logits])
              self.assertAllClose(
                  *self.evaluate([grad, ref_grad]),
                  rtol=2e-06,
                  atol=2e-06,
              )
  
      assert_same_loss_and_grads(
          ctc_ops.ctc_loss_v2(
              labels=sparse_labels,
              logits=logits,
              label_length=label_length,
              logit_length=logit_length,
              blank_index=0,
          )
      )
  
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.python.eager import backprop
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import ctc_ops
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the CTCLossTestV2 obj's underlying member method code with example usage: obj.testCtcLossV2() without return types