hi, there,
I am trying to work out the ungraded exercise 3.1, I can run the code but result is wrong.
I believe my mistake shall be the initiation of da_prevt. What I am doing now is:
assign da_prevt with da[: , : , T_x-1] to pick the last array,
when t reverse loop T_x, call function ‘gradients’ with parameters:
“da_prevt” and caches[t]
May I have some guidance about what am I doing wrong? Many thanks!
When we compute gradients for a step in rnn_backward, the gradients depend on da which is upstream gradients (from the loss backward to a), and da_prevt which is actually gradients from subsequent rnn cell. Note that, da and da_prevt are different.
Hence, in rnn_cell_backward function, you should include both da of current step and da_prevt of previous backward step.
If you still get stuck, my additional hint is to try da[:, :, t] + da_prevt for rnn_cell_backward. Note that da_prevt for the first backward step is zeros because it is the last cell.
Hope this helps.
many thanks for the reply. Sorry I didn’t explain my issue clearly.
I have past the “rnn_cell_backward” and the result is same of expected. I am actually stuck at “rnn_backward” part.
I can run the code, but the result is different from expected, as below:
You should re-read the answer by @kienmn because he basically spelled it out. But, again, to summarize… You should initialize da_prevt = np.zeros((n_a, m)) like every other gradient. Then, within the loop, call rnn_backward with da[:, :, t] + da_prevt