(logits, labels, input_length, label_length, blank_index=0)
return batch_loss
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
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
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
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
def ctc_lambda_loss ( logits , labels , input_length , label_length , blank_index = 0 ) : 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