# Help needed in Building your RNN Step by Step

Hello,

For the function lstm_cell_backward(da_next, dc_next, cache), I tried to calculate da_prev by using
“np.dot(Wf[:, :n_a].T, dft) + np.dot(Wc[:, :n_a].T, dcct) + np.dot(Wi[:, :n_a].T, dit) + np.dot(Wo[:, :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.

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 = np.dot(dWf[:, :n_a].T, dft) + np.dot(dWc[:, :n_a].T, dcct) + np.dot(dWi[:, :n_a].T, dit) + np.dot(dWo[:, :n_a].T, dot)
dc_prev = (da_next * ot * (1 - np.tanh(c_next) ** 2) + dc_next) * ft
dxt = np.dot(dWf[:, n_a:].T, dft) + np.dot(dWc[:, n_a:].T, dcct) + np.dot(dWi[:, n_a:].T, dit) + np.dot(dWo[:, 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

2 Likes

Hi @atharvap998 ,
Thanks for the info, this works