From 89a3fa93d571f446bcd1fa69ddd35257d975c239 Mon Sep 17 00:00:00 2001 From: Qi Liu Date: Mon, 9 May 2016 17:57:30 +0800 Subject: merge affine & lstm_gate & projection layer --- nerv/layer/projection.lua | 70 ----------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 nerv/layer/projection.lua (limited to 'nerv/layer/projection.lua') diff --git a/nerv/layer/projection.lua b/nerv/layer/projection.lua deleted file mode 100644 index 077125b..0000000 --- a/nerv/layer/projection.lua +++ /dev/null @@ -1,70 +0,0 @@ -local ProjectionLayer = nerv.class('nerv.ProjectionLayer', 'nerv.Layer') - ---- The constructor. -function ProjectionLayer:__init(id, global_conf, layer_conf) - nerv.Layer.__init(self, id, global_conf, layer_conf) - self:check_dim_len(-1, 1) -- exactly one output, allow multiple inputs - self:bind_params() -end - -function ProjectionLayer:bind_params() - local lconf = self.lconf - lconf.no_update_ltp1 = lconf.no_update_ltp1 or lconf.no_update_ltp - for i = 1, #self.dim_in do - local pid = "ltp" .. i - local pid_list = i == 1 and {pid, "ltp"} or pid - self["ltp" .. i] = self:find_param(pid_list, lconf, self.gconf, - nerv.LinearTransParam, - {self.dim_in[i], self.dim_out[1]}) - local no_update = lconf["no_update_ltp" .. i] - if (no_update ~= nil) and no_update or lconf.no_update_all then - self["ltp" .. i].no_update = true - end - end - self.ltp = self.ltp1 -- alias of ltp1 -end - -function ProjectionLayer:init(batch_size) - for i = 1, #self.dim_in do - if self.dim_in[i] ~= self["ltp" .. i].trans:nrow() then - nerv.error("mismatching dimensions of linear transform parameter and input") - end - if self.dim_out[1] ~= self["ltp" .. i].trans:ncol() then - nerv.error("mismatching dimensions of linear transform parameter and output") - end - self["ltp" .. i]:train_init() - end -end - -function ProjectionLayer:batch_resize(batch_size) - -- do nothing -end - -function ProjectionLayer:update() - for i = 1, #self.dim_in do - self["ltp" .. i]:update_by_err_input() - end -end - -function ProjectionLayer:propagate(input, output) - -- apply linear transform - output[1]:mul(input[1], self.ltp1.trans, 1.0, 0.0, 'N', 'N') - for i = 2, #self.dim_in do - output[1]:mul(input[i], self["ltp" .. i].trans, 1.0, 1.0, 'N', 'N') - end -end - -function ProjectionLayer:back_propagate(bp_err, next_bp_err, input, output) - for i = 1, #self.dim_in do - next_bp_err[i]:mul(bp_err[1], self["ltp" .. i].trans, 1.0, 0.0, 'N', 'T') - self["ltp" .. i]:back_propagate_by_err_input(bp_err[1], input[i]) - end -end - -function ProjectionLayer:get_params() - local pr = nerv.ParamRepo({self.ltp1}, self.loc_type) - for i = 2, #self.dim_in do - pr:add(self["ltp" .. i]) - end - return pr -end -- cgit v1.2.3