Code problem in course 5 - week 1 - Assignment 1


In course 5 - week 1 - Assignment 1, in the def rnn_forward(x, a0, parameters), for the following code, I wrote a-prev first in the def parenthesis, but I got an arror, then I changed it to a-next , and it run well. Unfortunately I do not understand why we should write a-next?

Doesn’t it take the previous cell value? So it should be a-prev

for t in range(T_x):
a_next, yt_pred, cache = rnn_cell_forward(x[:,:,t], a_next, parameters)

Hi @simamn,

The diagram, Fig 3, clearly shows there are two input into a RNN cell, a and x, where a is the output of the hidden state from previous cell and x is the input data for the current time step. Hence, the output of the hidden state from one Rnn cell, becomes the input of the hidden state for the next cell. For the first RNN cell, a_next is initialised to a0.

1 Like