code: def testCtcLossDenseIsSameAsCtcLoss(self):
      with ops.device(
          "/GPU:0" if test.is_gpu_available() else "/CPU:0"
      ):
          random_seed.set_random_seed(5)
  
          batch_size = 8
          num_labels = 6
          label_length = 5
          minimum_logits_length = 10
          num_frames = minimum_logits_length + batch_size
          logits = random_ops.random_uniform(
              [num_frames, batch_size, num_labels]
          )
          labels = random_ops.random_uniform(
              [batch_size, label_length],
              minval=1,
              maxval=num_labels,
              dtype=dtypes.int64,
          )
  
          label_lengths = random_ops.random_uniform(
              [batch_size],
              minval=2,
              maxval=label_length,
              dtype=dtypes.int64,
          )
          label_mask = array_ops.sequence_mask(
              label_lengths,
              maxlen=label_length,
              dtype=label_lengths.dtype,
          )
          labels *= label_mask
  
          logit_lengths = (
              math_ops.range(batch_size) + minimum_logits_length
          )
  
          ctc_loss = ctc_ops.ctc_loss_dense(
              labels=labels,
              logits=logits,
              label_length=label_lengths,
              logit_length=logit_lengths,
          )
          ctc_loss_grads = gradients_impl.gradients(ctc_loss, [logits])[
              0
          ]
  
          # Shift labels down by one (move blank from 0 to num_labels -1)
          tf_ctc_loss_labels = math_ops.cast(labels, dtypes.int32) - 1
          tf_nn_ctc_logits = array_ops.concat(
              [
                  logits[:, :, 1:],
                  logits[:, :, 0:1],
              ],
              axis=2,
          )
  
          tf_ctc_loss_labels = ctc_ops.dense_labels_to_sparse(
              tf_ctc_loss_labels, label_lengths
          )
  
          tf_nn_ctc_loss = ctc_ops.ctc_loss(
              labels=tf_ctc_loss_labels,
              inputs=tf_nn_ctc_logits,
              sequence_length=logit_lengths,
              time_major=True,
          )
          tf_nn_ctc_grads = gradients_impl.gradients(
              tf_nn_ctc_loss, [logits]
          )[0]
  
          with self.cached_session() as sess:
              for _ in range(32):
                  self.assertAllClose(
                      *self.evaluate([ctc_loss, tf_nn_ctc_loss])
                  )
                  self.assertAllClose(
                      *self.evaluate([ctc_loss_grads, tf_nn_ctc_grads]),
                      rtol=4e-06,
                      atol=4e-06,
                  )
  
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 2 for calling the CTCLossTestV2 obj's underlying member method code with example usage: obj.testCtcLossDenseIsSameAsCtcLoss() without return types