Course 5 Week 1 Assignment 1 Where is dc_next for lstm_backwards

Hi everyone,

I’m finishing the assignment, and in the optional lstm_backward function we have to do:

gradients = lstm_cell_backward(da_next, dc_next, caches[t]):

My question is: how do I initialize da_prevt and dc_prevt, and should they be the parameters to lstm_cell_backward (for da_next and dc_next) ?


To be more precise, I do not understand whezre to take the dc_next from since it’s not passed as a parameter. If this clarifies my question.

1 Like

Hi Barb,

Note that lstm_cell_backward returns a gradient dictionary that contains dc_prev, which makes sense as you are doing backpropagation. When you start backpropagation you have to initialize dc_prevt, i.e., create a numpy array of the right size containing zeros. This is the variable you start with. I guess the confusing thing is the name of the parameters of the lstm_cell_backward function.

Hi Barb,

Think about the value you want to pass as the first parameter to the lstm_cell_backward function. How is this value calculated?

For inspiration you can look at how you implemented the rnn_backward function. The comment above that function states:

“Note that this notebook does not implement the backward path from the Loss ‘J’ backwards to ‘a’. This would have included the dense layer and softmax which are a part of the forward path. This is assumed to be calculated elsewhere and the result passed to rnn_backward in ‘da’. You must combine this with the loss from the previous stages when calling rnn_cell_backward”.

Do you see how you should adjust the first value to pass to lstm_cell_backward?

Good luck and please delete your code once you’ve solved this issue.

Hello @reinoudbosch,

Thanks for the advice of looking up rnn_backward, I realized I was missing something.

I don’t know why I can’t edit my post so I just deleted it.

Thanks !

1 Like