From 02750731bc356a710e3ce80f1e7332bb85bcd25b Mon Sep 17 00:00:00 2001 From: SilverNexus Date: Sun, 5 Aug 2018 15:38:01 -0400 Subject: [PATCH] Forego the offset loop that was meant to slide values around with another unpack statement. --- train.lua | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/train.lua b/train.lua index 2aa26f42..9bd72887 100644 --- a/train.lua +++ b/train.lua @@ -287,14 +287,9 @@ function feval(x) local doutput_t = clones.criterion[t]:backward(predictions[t], y[t]) drnn_state[t][#drnn_state[t]+1] = doutput_t local dlst = clones.rnn[t]:backward({x[t], unpack(rnn_state[t-1])}, drnn_state[t]) - drnn_state[t-1] = {} - for k,v in pairs(dlst) do - if k > 1 then -- k == 1 is gradient on x, which we dont need - -- note we do k-1 because first item is dembeddings, and then follow the - -- derivatives of the state, starting at index 2. I know... - drnn_state[t-1][k-1] = v - end - end + -- dlst[1] is the gradient on x, which we don't need + -- using unpack should slide the values into the correct indexes, allowing us to forego a loop. + drnn_state[t-1] = {unpack(dlst, 2)} end ------------------------ misc ---------------------- -- transfer final state to initial state (BPTT)