code: def ctc_lambda_loss(
      logits, labels, input_length, label_length, blank_index=0
  ):
      """
      ctc loss function
      psram: logits, (B, T, D)
      psram: input_length,  (B, 1), input length of encoder
      psram: labels, (B, T)
      psram: label_length,  (B, 1), label length for convert dense label to sparse
      returns: loss, scalar
      """
      ilen = tf.cond(
          pred=tf.equal(tf.rank(input_length), 1),
          true_fn=lambda: input_length,
          false_fn=lambda: tf.squeeze(input_length),
      )
      ilen = tf.cast(ilen, tf.int32)
  
      olen = tf.cond(
          pred=tf.equal(tf.rank(label_length), 1),
          true_fn=lambda: label_length,
          false_fn=lambda: tf.squeeze(label_length),
      )
      olen = tf.cast(olen, tf.int32)
  
      deps = [
          tf.assert_rank(labels, 2, name="label_rank_check"),
          tf.assert_rank(logits, 3, name="logits_rank_check"),
          tf.assert_rank(
              ilen, 1, name="src_len_rank_check"
          ),  # input_length
          tf.assert_rank(
              olen, 1, name="tgt_len_rank_check"
          ),  # output_length
      ]
  
      labels, logits = ctc_data_transform(labels, logits, blank_index)
  
      with tf.control_dependencies(deps):
          # (B, 1)
          # blank index is consistent with Espnet, zero
          batch_loss = tf.nn.ctc_loss(
              labels=labels,
              inputs=logits,
              sequence_length=ilen,
              time_major=False,
              preprocess_collapse_repeated=False,
              ctc_merge_repeated=True,
              ignore_longer_outputs_than_inputs=False,
          )
      return batch_loss
  
file_path: delta/delta/utils/loss/loss_utils.py
imports: import math
  import delta.compat
  import tensorflow_addons
  from delta import utils
  from delta.utils import ctc_utils
label_desc: Use image node_id 2 for calling a global function with example usage: ctc_lambda_loss(logits, labels, input_length, label_length, blank_index) and returns: batch_loss