code: def padding_to_length(padding):
    
    non_padding = 1.0 - padding
    return tf.to_int32(tf.reduce_sum(non_padding, axis=-1))
docs: Calculate the length of mask based on padding.
  
    Args:
      padding: a Tensor with shape [..., length].
    Returns:
      a Tensor with shape [...].