import tensorflow as tf


@tf.function
def ctc_decode(inputs, batch_size, seq_length, blank_index, def_val, shift, beam_width=10):
  """Perform ctc decoding"""
  # Decode uses time major
  inputs = tf.transpose(a=inputs, perm=[1, 0, 2])
  seq_lengths = tf.fill([batch_size], seq_length)
  # Perform beam search
  indices, values, shape, indices_u, values_u, shape_u, log_probs = ctc_ext_beam_search_decoder(
    inputs=inputs, sequence_length=seq_lengths,
    beam_width=beam_width, blank_index=blank_index, top_paths=1,
    blank_label=0)
