def ctc_decode(y_pred, input_length, greedy=True, beam_width=100, top_paths=1):
 y_pred = tf.log((tf.transpose(y_pred, perm=[1, 0, 2]) + 1e-08))
 input_length = tf.to_int32(input_length)
 if greedy:
  (decoded, log_prob) = ctc.ctc_greedy_decoder(inputs=y_pred, sequence_length=input_length)
 else:
  (decoded, log_prob) = ctc.ctc_beam_search_decoder(inputs=y_pred, sequence_length=input_length, beam_width=beam_width, top_paths=top_paths)
 decoded_dense = [tf.sparse_to_dense(st.indices, st.shape, st.values, default_value=(-1)) for st in decoded]
 return (decoded_dense, log_prob)

def ctc_decode ( y_pred , input_length , greedy = True , beam_width = 100 , top_paths = 1 ) : y_pred = tf . log ( ( tf . transpose ( y_pred , perm = [ 1 , 0 , 2 ] ) + 1e-08 ) ) input_length = tf . to_int32 ( input_length ) if greedy : ( decoded , log_prob ) = ctc . ctc_greedy_decoder ( inputs = y_pred , sequence_length = input_length ) else : ( decoded , log_prob ) = ctc . ctc_beam_search_decoder ( inputs = y_pred , sequence_length = input_length , beam_width = beam_width , top_paths = top_paths ) decoded_dense = [ tf . sparse_to_dense ( st . indices , st . shape , st . values , default_value = ( - 1 ) ) for st in decoded ] return ( decoded_dense , log_prob )
decodes the output of a softmax using either greedy or a constrained dictionary search .