aboutsummaryrefslogtreecommitdiff
path: root/nerv/layer/lstm.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/layer/lstm.lua')
-rw-r--r--nerv/layer/lstm.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/nerv/layer/lstm.lua b/nerv/layer/lstm.lua
index 5d73ad2..d6437e5 100644
--- a/nerv/layer/lstm.lua
+++ b/nerv/layer/lstm.lua
@@ -24,13 +24,13 @@ function LSTMLayer:__init(id, global_conf, layer_conf)
cellDup = {dim_in = {dout}, dim_out = {dout, dout, dout, dout, dout}},
},
['nerv.AffineLayer'] = {
- mainAffine = {dim_in = table.connect({dout}, din), dim_out = {dout}, pr = pr},
- forgetGate = {dim_in = table.connect({dout, dout}, din), dim_out = {dout},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
- inputGate = {dim_in = table.connect({dout, dout}, din), dim_out = {dout},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
- outputGate = {dim_in = table.connect({dout, dout}, din), dim_out = {dout},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
+ mainAffine = {dim_in = table.connect(din, {dout}), dim_out = {dout}, pr = pr},
+ forgetGate = {dim_in = table.connect(din, {dout, dout}), dim_out = {dout},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
+ inputGate = {dim_in = table.connect(din, {dout, dout}), dim_out = {dout},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
+ outputGate = {dim_in = table.connect(din, {dout, dout}), dim_out = {dout},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
},
['nerv.TanhLayer'] = {
mainTanh = {dim_in = {dout}, dim_out = {dout}},
@@ -51,20 +51,20 @@ function LSTMLayer:__init(id, global_conf, layer_conf)
--{'<input>[1 .. n]', 'inputDup(1 .. n)[1]', 0},
-- input gate
- {'outputDup[1]', 'inputGate[1]', 1},
- {'cellDup[1]', 'inputGate[2]', 1},
- --{'inputDup(1 .. n)[1]', 'inputGate[3 .. n + 2]', 0},
+ {'outputDup[1]', 'inputGate[' .. (#din + 1) .. ']', 1},
+ {'cellDup[1]', 'inputGate[' .. (#din + 2) .. ']', 1},
+ --{'inputDup(1 .. n)[1]', 'inputGate[1 .. n]', 0},
-- forget gate
- {'outputDup[2]', 'forgetGate[1]', 1},
- {'cellDup[2]', 'forgetGate[2]', 1},
- --{'inputDup(1 .. n)[2]', 'forgetGate[3 .. n + 2]', 0},
+ {'outputDup[2]', 'forgetGate[' .. (#din + 1) .. ']', 1},
+ {'cellDup[2]', 'forgetGate[' .. (#din + 2) .. ']', 1},
+ --{'inputDup(1 .. n)[2]', 'forgetGate[1 .. n]', 0},
-- lstm cell
{'forgetGate[1]', 'forgetGateMul[1]', 0},
{'cellDup[3]', 'forgetGateMul[2]', 1},
- {'outputDup[3]', 'mainAffine[1]', 1},
- --{'inputDup(1 .. n)[3]', 'mainAffine[2 .. n + 1]', 0},
+ {'outputDup[3]', 'mainAffine[' .. (#din + 1) .. ']', 1},
+ --{'inputDup(1 .. n)[3]', 'mainAffine[1 .. n]', 0},
{'mainAffine[1]', 'mainTanh[1]', 0},
{'inputGate[1]', 'inputGateMul[1]', 0},
{'mainTanh[1]', 'inputGateMul[2]', 0},
@@ -73,9 +73,9 @@ function LSTMLayer:__init(id, global_conf, layer_conf)
{'mainCombine[1]', 'cellDup[1]', 0},
-- forget gate
- {'outputDup[4]', 'outputGate[1]', 1},
- {'cellDup[4]', 'outputGate[2]', 0},
- --{'inputDup(1 .. n)[4]', 'outputGate[2 .. n + 1]', 0},
+ {'outputDup[4]', 'outputGate[' .. (#din + 1) .. ']', 1},
+ {'cellDup[4]', 'outputGate[' .. (#din + 2) .. ']', 0},
+ --{'inputDup(1 .. n)[4]', 'outputGate[1 .. n]', 0},
-- lstm output
{'cellDup[5]', 'outputTanh[1]', 0},
@@ -86,10 +86,10 @@ function LSTMLayer:__init(id, global_conf, layer_conf)
}
for i = 1, #din do
table.insert(connections, {'<input>[' .. i .. ']', 'inputDup' .. i .. '[1]', 0})
- table.insert(connections, {'inputDup' .. i .. '[1]', 'inputGate[' .. (i + 2) .. ']', 0})
- table.insert(connections, {'inputDup' .. i .. '[2]', 'forgetGate[' .. (i + 2) .. ']', 0})
- table.insert(connections, {'inputDup' .. i .. '[3]', 'mainAffine[' .. (i + 1) .. ']', 0})
- table.insert(connections, {'inputDup' .. i .. '[4]', 'outputGate[' .. (i + 2) .. ']', 0})
+ table.insert(connections, {'inputDup' .. i .. '[1]', 'inputGate[' .. i .. ']', 0})
+ table.insert(connections, {'inputDup' .. i .. '[2]', 'forgetGate[' .. i .. ']', 0})
+ table.insert(connections, {'inputDup' .. i .. '[3]', 'mainAffine[' .. i .. ']', 0})
+ table.insert(connections, {'inputDup' .. i .. '[4]', 'outputGate[' .. i .. ']', 0})
end
self:add_prefix(layers, connections)