Help needed in Building your RNN Step by Step


For the function lstm_cell_backward(da_next, dc_next, cache), I tried to calculate da_prev by using
“[:, :n_a].T, dft) +[:, :n_a].T, dcct) +[:, :n_a].T, dit) +[:, :n_a].T, dot)” but it shows an error that “The name Wf is not defined”. I cannot resolve this issue can anybody help me?
I also tried using dWf but its giving me an incorrect output.

Thanks in advance

Hi @atharvap998,

The variable should be dWf, not Wf.
dwf is the gradient of the weight matrix of the forget gate with respect to time step t, computed with equation 11.

Hi @Kic I encountered the same problem as well.
I notice that in the equation it explicitly mentions Wf, not dWf

I used dWf but the output produced is wrong for dxt and da_prev. Here are my codes:

da_prev =[:, :n_a].T, dft) +[:, :n_a].T, dcct) +[:, :n_a].T, dit) +[:, :n_a].T, dot)
dc_prev = (da_next * ot * (1 - np.tanh(c_next) ** 2) + dc_next) * ft
dxt =[:, n_a:].T, dft) +[:, n_a:].T, dcct) +[:, n_a:].T, dit) +[:, n_a:].T, dot)

Below is the result. Other than those two, the other answer seems to be correct

Hello Michael,
I resolved that error. Unpack the values “Wf, Wi, Wc, Wo” from parameters before you use these values.
For e.g. Wf = parameters[“Wf”]
This worked for me


Hi @atharvap998 ,
Thanks for the info, this works :+1: