Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions torch_modules/LSTM_LN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ function LSTM.lstm(inputSize, hiddenSize)
local prev_c = nn.Identity()()
local prev_h = nn.Identity()()

function new_input_sum_bias(bias)
function new_input_sum()
-- transforms input
local i2h = nn.Linear(inputSize, hiddenSize)(x)
local i2h = nn.Linear(inputSize, hiddenSize, false)(x) -- no bias
-- transforms previous timestep's output
local h2h = nn.Linear(hiddenSize, hiddenSize)(prev_h)
return nn.CAddTable()({i2h, h2h})
local h2h = nn.Linear(hiddenSize, hiddenSize, false)(prev_h) -- no bias

-- add a bias term here
return nn.Add(hiddenSize)(nn.CAddTable()({i2h, h2h}))
end

local in_gate = nn.Sigmoid()(new_input_sum_bias(0))
local forget_gate = nn.Sigmoid()(new_input_sum_bias(-4.))
local out_gate = nn.Sigmoid()(new_input_sum_bias(0))
local in_transform = nn.Tanh()(new_input_sum_bias(0))
local in_gate = nn.Sigmoid()(new_input_sum())
local forget_gate = nn.Sigmoid()(new_input_sum())
local out_gate = nn.Sigmoid()(new_input_sum())
local in_transform = nn.Tanh()(new_input_sum())

local next_c = nn.CAddTable()({
nn.CMulTable()({forget_gate, prev_c}),
Expand All @@ -34,4 +36,3 @@ function LSTM.lstm(inputSize, hiddenSize)
end

return LSTM