From 44facf189a62205917ae61bad0720bdcdfb8a5c9 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Thu, 29 Mar 2018 05:58:53 -0700 Subject: [PATCH 1/2] Expose the acoustic scale in decoder --- fluid/DeepASR/decoder/post_decode_faster.cc | 5 +++-- fluid/DeepASR/decoder/post_decode_faster.h | 3 ++- fluid/DeepASR/decoder/pybind.cc | 2 +- fluid/DeepASR/infer_by_ckpt.py | 5 +++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fluid/DeepASR/decoder/post_decode_faster.cc b/fluid/DeepASR/decoder/post_decode_faster.cc index d7f1d1ab34..ce2b45bc6c 100644 --- a/fluid/DeepASR/decoder/post_decode_faster.cc +++ b/fluid/DeepASR/decoder/post_decode_faster.cc @@ -21,14 +21,15 @@ using fst::StdArc; Decoder::Decoder(std::string word_syms_filename, std::string fst_in_filename, - std::string logprior_rxfilename) { + std::string logprior_rxfilename, + kaldi::BaseFloat acoustic_scale) { const char* usage = "Decode, reading log-likelihoods (of transition-ids or whatever symbol " "is on the graph) as matrices."; kaldi::ParseOptions po(usage); binary = true; - acoustic_scale = 1.5; + this->acoustic_scale = acoustic_scale; allow_partial = true; kaldi::FasterDecoderOptions decoder_opts; decoder_opts.Register(&po, true); // true == include obscure settings. diff --git a/fluid/DeepASR/decoder/post_decode_faster.h b/fluid/DeepASR/decoder/post_decode_faster.h index 2e31a1c19e..8bade8d698 100644 --- a/fluid/DeepASR/decoder/post_decode_faster.h +++ b/fluid/DeepASR/decoder/post_decode_faster.h @@ -29,7 +29,8 @@ class Decoder { public: Decoder(std::string word_syms_filename, std::string fst_in_filename, - std::string logprior_rxfilename); + std::string logprior_rxfilename, + kaldi::BaseFloat acoustic_scale); ~Decoder(); // Interface to accept the scores read from specifier and return diff --git a/fluid/DeepASR/decoder/pybind.cc b/fluid/DeepASR/decoder/pybind.cc index 56439d1802..90ea38ffb5 100644 --- a/fluid/DeepASR/decoder/pybind.cc +++ b/fluid/DeepASR/decoder/pybind.cc @@ -23,7 +23,7 @@ PYBIND11_MODULE(post_decode_faster, m) { m.doc() = "Decoder for Deep ASR model"; py::class_(m, "Decoder") - .def(py::init()) + .def(py::init()) .def("decode", (std::vector (Decoder::*)(std::string)) & Decoder::decode, diff --git a/fluid/DeepASR/infer_by_ckpt.py b/fluid/DeepASR/infer_by_ckpt.py index 572a9e9a01..224f1b0373 100644 --- a/fluid/DeepASR/infer_by_ckpt.py +++ b/fluid/DeepASR/infer_by_ckpt.py @@ -106,6 +106,11 @@ def parse_args(): type=str, default="./decoder/logprior", help="The log prior probs for training data. (default: %(default)s)") + parser.add_argument( + '--acoustic_scale', + type=float, + default=0.2, + help="Scaling factor for acoustic likelihoods. (default: %(default)f)") args = parser.parse_args() return args From 4a8e399f6750ad2917841ff4285bb4e8fb8759d7 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Thu, 29 Mar 2018 06:03:57 -0700 Subject: [PATCH 2/2] Add back one wrong removed function --- fluid/DeepASR/data_utils/util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fluid/DeepASR/data_utils/util.py b/fluid/DeepASR/data_utils/util.py index 2670240a78..0a48f46965 100644 --- a/fluid/DeepASR/data_utils/util.py +++ b/fluid/DeepASR/data_utils/util.py @@ -35,6 +35,13 @@ def lodtensor_to_ndarray(lod_tensor): return ret, lod_tensor.lod() +def split_infer_result(infer_seq, lod): + infer_batch = [] + for i in xrange(0, len(lod[0]) - 1): + infer_batch.append(infer_seq[lod[0][i]:lod[0][i + 1]]) + return infer_batch + + class CriticalException(Exception): pass