diff options
Diffstat (limited to 'nerv/layer')
-rw-r--r-- | nerv/layer/affine.lua | 4 | ||||
-rw-r--r-- | nerv/layer/lstm_gate.lua | 22 | ||||
-rw-r--r-- | nerv/layer/projection.lua | 8 |
3 files changed, 21 insertions, 13 deletions
diff --git a/nerv/layer/affine.lua b/nerv/layer/affine.lua index 467eac9..16250fd 100644 --- a/nerv/layer/affine.lua +++ b/nerv/layer/affine.lua @@ -108,7 +108,7 @@ function AffineLayer:bind_params() 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] + 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 @@ -125,7 +125,7 @@ function AffineLayer:bind_params() end function AffineLayer:init(batch_size) - if self.ltp.trans:ncol() ~= self.bp.trans:ncol() then + if self.dim_out[1] ~= self.bp.trans:ncol() then nerv.error("mismatching dimensions of linear transform and bias paramter") end for i = 1, #self.dim_in do diff --git a/nerv/layer/lstm_gate.lua b/nerv/layer/lstm_gate.lua index 3bb3cb9..39a3ff7 100644 --- a/nerv/layer/lstm_gate.lua +++ b/nerv/layer/lstm_gate.lua @@ -12,17 +12,20 @@ function LSTMGateLayer: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 - self["ltp" .. i] = self:find_param("ltp" .. i, lconf, self.gconf, + 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]}) if self.param_type[i] == 'D' then self["ltp" .. i].trans:diagonalize() end - local no_update = lconf["no_update_ltp"..i] + 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 self.bp = self:find_param("bp", lconf, self.gconf, nerv.BiasParam, {1, self.dim_out[1]}, nerv.Param.gen_zero) @@ -33,18 +36,17 @@ function LSTMGateLayer:bind_params() end function LSTMGateLayer:init(batch_size) + if self.dim_out[1] ~= self.bp.trans:ncol() then + nerv.error("mismatching dimensions of linear transform and bias paramter") + end for i = 1, #self.dim_in do - if self["ltp" .. i].trans:ncol() ~= self.bp.trans:ncol() then - nerv.error("mismatching dimensions of linear transform and bias paramter") - end if self.dim_in[i] ~= self["ltp" .. i].trans:nrow() then nerv.error("mismatching dimensions of linear transform parameter and input") end - self["ltp"..i]:train_init() - end - - if self.dim_out[1] ~= self.ltp1.trans:ncol() then - nerv.error("mismatching dimensions of linear transform parameter and output") + 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 self.bp:train_init() self.err_bakm = self.mat_type(batch_size, self.dim_out[1]) diff --git a/nerv/layer/projection.lua b/nerv/layer/projection.lua index c0b5638..077125b 100644 --- a/nerv/layer/projection.lua +++ b/nerv/layer/projection.lua @@ -8,12 +8,18 @@ function ProjectionLayer:__init(id, global_conf, layer_conf) 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, self.lconf, self.gconf, + 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 |