Skip to content

Commit

Permalink
Merge pull request #792 from kuke/expose_acoustic_scale
Browse files Browse the repository at this point in the history
Expose acoustic scale in decoder
  • Loading branch information
Yibing Liu authored Mar 29, 2018
2 parents bf38065 + 4a8e399 commit 05f36d8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions fluid/DeepASR/data_utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions fluid/DeepASR/decoder/post_decode_faster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion fluid/DeepASR/decoder/post_decode_faster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fluid/DeepASR/decoder/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PYBIND11_MODULE(post_decode_faster, m) {
m.doc() = "Decoder for Deep ASR model";

py::class_<Decoder>(m, "Decoder")
.def(py::init<std::string, std::string, std::string>())
.def(py::init<std::string, std::string, std::string, kaldi::BaseFloat>())
.def("decode",
(std::vector<std::string> (Decoder::*)(std::string)) &
Decoder::decode,
Expand Down
5 changes: 5 additions & 0 deletions fluid/DeepASR/infer_by_ckpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 05f36d8

Please sign in to comment.