diff options
author | Ted Yin <[email protected]> | 2015-10-12 09:26:53 +0800 |
---|---|---|
committer | Ted Yin <[email protected]> | 2015-10-12 09:26:53 +0800 |
commit | 0dba4c998fcccb4bae29582b7d8be94de476dd0b (patch) | |
tree | b8529d4f0c2ea0a91ee4b7a4b21a14c0616fc081 /kaldi_seq/layer/mmi.lua | |
parent | 7acd14eca701deaffb2d16262528da37ee23263a (diff) | |
parent | e39fb231f64ddc8b79a6eb5434f529aadb3165fe (diff) |
Merge pull request #6 from yimmon/master
add kaldi_seq
Diffstat (limited to 'kaldi_seq/layer/mmi.lua')
-rw-r--r-- | kaldi_seq/layer/mmi.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/kaldi_seq/layer/mmi.lua b/kaldi_seq/layer/mmi.lua new file mode 100644 index 0000000..ecc7f48 --- /dev/null +++ b/kaldi_seq/layer/mmi.lua @@ -0,0 +1,50 @@ +require 'libkaldiseq' +local MMILayer = nerv.class("nerv.MMILayer", "nerv.Layer") + +function MMILayer:__init(id, global_conf, layer_conf) + self.id = id + self.gconf = global_conf + self.dim_in = layer_conf.dim_in + self.dim_out = layer_conf.dim_out + self.arg = layer_conf.cmd.arg + self.mdl = layer_conf.cmd.mdl + self.lat = layer_conf.cmd.lat + self.ali = layer_conf.cmd.ali + self:check_dim_len(2, -1) -- two inputs: nn output and utt key +end + +function MMILayer:init(batch_size) + self.total_frames = 0 + self.kaldi_mmi = nerv.KaldiMMI(self.arg, self.mdl, self.lat, self.ali) + if self.kaldi_mmi == nil then + nerv.error("kaldi arguments is expected: %s %s %s %s", self.arg, + self.mdl, self.lat, self.ali) + end +end + +function MMILayer:batch_resize(batch_size) + -- do nothing +end + +function MMILayer:update(bp_err, input, output) + -- no params, therefore do nothing +end + +function MMILayer:propagate(input, output) + self.valid = false + self.valid = self.kaldi_mmi:check(input[1], input[2]) + return self.valid +end + +function MMILayer:back_propagate(bp_err, next_bp_err, input, output) + if self.valid ~= true then + nerv.error("kaldi sequence training back_propagate fail") + end + local mmat = input[1]:new_to_host() + next_bp_err[1]:copy_fromh(self.kaldi_mmi:calc_diff(mmat, input[2])) + self.total_frames = self.total_frames + self.kaldi_mmi:get_num_frames() +end + +function MMILayer:get_params() + return nerv.ParamRepo({}) +end |