convert decoding results to unicode in DS2

pull/2/head
Yibing Liu 7 years ago
parent 511c454008
commit 2c63f3413f

@ -35,7 +35,8 @@ def ctc_greedy_decoder(probs_seq, vocabulary):
:return: Decoding result string. :return: Decoding result string.
:rtype: basestring :rtype: basestring
""" """
return swig_decoders.ctc_greedy_decoder(probs_seq.tolist(), vocabulary) result = swig_decoders.ctc_greedy_decoder(probs_seq.tolist(), vocabulary)
return result.decode('utf-8')
def ctc_beam_search_decoder(probs_seq, def ctc_beam_search_decoder(probs_seq,
@ -69,9 +70,11 @@ def ctc_beam_search_decoder(probs_seq,
results, in descending order of the probability. results, in descending order of the probability.
:rtype: list :rtype: list
""" """
return swig_decoders.ctc_beam_search_decoder(probs_seq.tolist(), vocabulary, beam_results = swig_decoders.ctc_beam_search_decoder(
beam_size, cutoff_prob, probs_seq.tolist(), vocabulary, beam_size, cutoff_prob, cutoff_top_n,
cutoff_top_n, ext_scoring_func) ext_scoring_func)
beam_results = [(res[0], res[1].decode('utf-8')) for res in beam_results]
return beam_results
def ctc_beam_search_decoder_batch(probs_split, def ctc_beam_search_decoder_batch(probs_split,
@ -111,6 +114,11 @@ def ctc_beam_search_decoder_batch(probs_split,
""" """
probs_split = [probs_seq.tolist() for probs_seq in probs_split] probs_split = [probs_seq.tolist() for probs_seq in probs_split]
return swig_decoders.ctc_beam_search_decoder_batch( batch_beam_results = swig_decoders.ctc_beam_search_decoder_batch(
probs_split, vocabulary, beam_size, num_processes, cutoff_prob, probs_split, vocabulary, beam_size, num_processes, cutoff_prob,
cutoff_top_n, ext_scoring_func) cutoff_top_n, ext_scoring_func)
batch_beam_results = [
[(res[0], res[1].decode("utf-8")) for res in beam_results]
for beam_results in batch_beam_results
]
return batch_beam_results

@ -33,7 +33,7 @@ python -u train.py \
--shuffle_method='batch_shuffle_clipped' --shuffle_method='batch_shuffle_clipped'
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Fail to do inference!" echo "Fail in training!"
exit 1 exit 1
fi fi

Loading…
Cancel
Save