diff options
author | txh18 <cloudygooseg@gmail.com> | 2015-10-27 16:24:55 +0800 |
---|---|---|
committer | txh18 <cloudygooseg@gmail.com> | 2015-10-27 16:24:55 +0800 |
commit | 7c95640c95f1cc1d84b4d49fa97fd922748b88a7 (patch) | |
tree | e78fc611b8768ddf6e9191d597bf667e83b3353b /nerv/examples | |
parent | ba8a1c9d5366c22b0b631f26ae1de7c5da2cbaeb (diff) |
added update_select_rows for select_linear:update speed-up
Diffstat (limited to 'nerv/examples')
-rw-r--r-- | nerv/examples/lmptb/lmptb/layer/select_linear.lua | 13 | ||||
-rw-r--r-- | nerv/examples/lmptb/main.lua | 3 |
2 files changed, 10 insertions, 6 deletions
diff --git a/nerv/examples/lmptb/lmptb/layer/select_linear.lua b/nerv/examples/lmptb/lmptb/layer/select_linear.lua index e4afac4..d4cff0b 100644 --- a/nerv/examples/lmptb/lmptb/layer/select_linear.lua +++ b/nerv/examples/lmptb/lmptb/layer/select_linear.lua @@ -30,12 +30,13 @@ function SL:init(batch_size) end function SL:update(bp_err, input, output) - for i = 1, input[1]:ncol(), 1 do - if (input[1][0][i - 1] ~= 0) then - local word_vec = self.ltp.trans[input[1][0][i - 1]] - word_vec:add(word_vec, bp_err[1][i - 1], 1, - self.gconf.lrate / self.gconf.batch_size) - end - end + --for i = 1, input[1]:ncol(), 1 do + -- if (input[1][0][i - 1] ~= 0) then + -- local word_vec = self.ltp.trans[input[1][0][i - 1]] + --word_vec:add(word_vec, bp_err[1][i - 1], 1, - self.gconf.lrate / self.gconf.batch_size) + -- end + --end + self.ltp.trans:update_select_rows(bp_err[1], input[1], - self.gconf.lrate / self.gconf.batch_size, 0) end function SL:propagate(input, output) diff --git a/nerv/examples/lmptb/main.lua b/nerv/examples/lmptb/main.lua index 13d610e..d505456 100644 --- a/nerv/examples/lmptb/main.lua +++ b/nerv/examples/lmptb/main.lua @@ -17,6 +17,7 @@ function prepare_parameters(global_conf, first_time) ltp_ih = nerv.LinearTransParam("ltp_ih", global_conf) ltp_ih.trans = global_conf.cumat_type(global_conf.vocab:size() + 1, global_conf.hidden_size) --index 0 is for zero, others correspond to vocab index(starting from 1) ltp_ih.trans:generate(global_conf.param_random) + ltp_ih.trans[0]:fill(0) ltp_hh = nerv.LinearTransParam("ltp_hh", global_conf) ltp_hh.trans = global_conf.cumat_type(global_conf.hidden_size, global_conf.hidden_size) @@ -153,6 +154,7 @@ function propagateFile(global_conf, dagL, fn, config) local token_store = {} local hidden_store = {} local sigmoidL_ref = dagL.layers["sigmoidL1"] + local inputL_ref = dagL.layers["selectL1"] token_store[tnow] = feeder:get_batch() for i = 1, global_conf.bptt + 1 do @@ -209,6 +211,7 @@ function propagateFile(global_conf, dagL, fn, config) global_conf.timer:tic("dagL-update") dagL:update(dagL_err, dagL_input, dagL_output) global_conf.timer:toc("dagL-update") + inputL_ref.layer.ltp.trans[0]:fill(0) --afraid that this will be updated in select_linear:update end for i = 1, global_conf.batch_size, 1 do |