diff options
author | Determinant <[email protected]> | 2016-03-17 19:39:44 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2016-03-17 19:39:44 +0800 |
commit | 53332ce64662c7836296bdafa25deec9a24020eb (patch) | |
tree | 9d26b4901bc939a5f043dabf298de06e64ddcc49 /nerv/examples/gen_global_transf.lua | |
parent | 49d62c459c27791b08fff318f4b70958fc4e6542 (diff) |
do not chdir while training
Diffstat (limited to 'nerv/examples/gen_global_transf.lua')
-rw-r--r-- | nerv/examples/gen_global_transf.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/nerv/examples/gen_global_transf.lua b/nerv/examples/gen_global_transf.lua new file mode 100644 index 0000000..c4a3b42 --- /dev/null +++ b/nerv/examples/gen_global_transf.lua @@ -0,0 +1,62 @@ +if #arg < 1 then + return +end + +dofile(arg[1]) + +gconf.mmat_type = nerv.MMatrixFloat +gconf.cumat_type = nerv.CuMatrixFloat +local scp_file = gconf.tr_scp +local loc_type = nerv.ParamRepo.LOC_TYPES.ON_HOST +local reader_spec = make_readers(scp_file)[1] +local reader = reader_spec.reader +local width = reader_spec.data['main_scp'] +local mean = gconf.mmat_type(1, width) +local std = gconf.mmat_type(1, width) +local colsum = gconf.mmat_type(1, width) +local total = 0.0 +local EPS = 1e-7 + +mean:fill(0) +std:fill(0) + +local cnt = 0 +while (true) do + ret = reader:get_data() + if ret == nil then + break + end + + local utt = ret['main_scp'] + colsum = utt:colsum() + mean:add(mean, colsum, 1, 1) + + utt:mul_elem(utt, utt) + colsum = utt:colsum() + std:add(std, colsum, 1, 1) + + total = total + utt:nrow() + cnt = cnt + 1 + if cnt == 1000 then + nerv.info("accumulated %d utterances", cnt) + cnt = 0 + end +end + +local bparam = nerv.BiasParam("bias0", gconf) +bparam.trans = gconf.mmat_type(1, width) +mean:add(mean,mean, -1.0 / total, 0) -- -E(X) +bparam.trans:copy_fromh(mean) + +mean:mul_elem(mean, mean) -- E^2(X) +std:add(std, mean, 1 / total, -1) -- sigma ^ 2 + +for i = 0, width - 1 do + std[0][i] = math.sqrt(std[0][i] + EPS) + std[0][i] = 1 / (std[0][i] + EPS) +end + +local wparam = nerv.BiasParam("window0", gconf) +wparam.trans = std +local pr = nerv.ParamRepo({bparam, wparam}, loc_type) +pr:export("global_transf.nerv", nil) |