aboutsummaryrefslogtreecommitdiff
path: root/nerv/layer/lstmp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/layer/lstmp.lua')
-rw-r--r--nerv/layer/lstmp.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/nerv/layer/lstmp.lua b/nerv/layer/lstmp.lua
index 49c9516..c16dbd4 100644
--- a/nerv/layer/lstmp.lua
+++ b/nerv/layer/lstmp.lua
@@ -25,13 +25,13 @@ function LSTMPLayer:__init(id, global_conf, layer_conf)
cellDup = {dim_in = {dcell}, dim_out = {dcell, dcell, dcell, dcell, dcell}},
},
['nerv.AffineLayer'] = {
- mainAffine = {dim_in = table.connect({dout}, din), dim_out = {dcell}, pr = pr},
- forgetGate = {dim_in = table.connect({dout, dcell}, din), dim_out = {dcell},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
- inputGate = {dim_in = table.connect({dout, dcell}, din), dim_out = {dcell},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
- outputGate = {dim_in = table.connect({dout, dcell}, din), dim_out = {dcell},
- param_type = table.connect({'N', 'D'}, table.vector(#din, 'N')), pr = pr, activation = nerv.SigmoidLayer},
+ mainAffine = {dim_in = table.connect(din, {dout}), dim_out = {dcell}, pr = pr},
+ forgetGate = {dim_in = table.connect(din, {dout, dcell}), dim_out = {dcell},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
+ inputGate = {dim_in = table.connect(din, {dout, dcell}), dim_out = {dcell},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
+ outputGate = {dim_in = table.connect(din, {dout, dcell}), dim_out = {dcell},
+ param_type = table.connect(table.vector(#din, 'N'), {'N', 'D'}), pr = pr, activation = nerv.SigmoidLayer},
projection = {dim_in = {dcell}, dim_out = {dout}, pr = pr, no_bias = true},
},
['nerv.TanhLayer'] = {
@@ -53,20 +53,20 @@ function LSTMPLayer:__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},
@@ -75,9 +75,9 @@ function LSTMPLayer:__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},
@@ -89,10 +89,10 @@ function LSTMPLayer:__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)