C5 : W1 : A1 : Exercise 2 - rnn_forward "Wrong values for a"


When the tests run my implementation ofrnn_forward, they print:

a[4][1] = 
 [-0.93013738  0.991315   -0.98694298 -0.99723276]

, which doesn’t match the expected output.
… and indeed there’s this assertion error: AssertionError: Wrong values for a.

Below is how I’ve implemented rnn_forward. I’ve looked over it many times, and read related threads, but I’m not seeing what I’m doing wrong.

Please tell me what I’m doing wrong, DMing me if you can’t share it here.


PS. One thing I’m finding a bit confusing, is that:

  • in the diagram, xt is 1-indexed (while at is 0-indexed);
  • but when I call rnn_cell_forward inside rnn_forward, I use x[:,:,t] as the first argument (so, x[:,:,0] during the loop’s first iteration), and , a_next as the second argument (which is a[:, :, 0] on the loops’ during the loop’s first iteration). i.e. I’m using the same number of index into both x and a, without an offset, which seems wrong.
  • But if I usex[:,:,t + 1] as the first argument, t + 1 gets out of bound (error: index 4 is out of bounds for axis 2 with size 4).

How I’ve implemented rnn_forward

    ### START CODE HERE ###
    # moderator edit: code removed

    ### END CODE HERE ###

1 Like

Please use the “pencil” icon in the thread title to move your thread to the correct course.

Your question is about RNN’s, which are in Course 5. You’ve posted in the CNN area, which is Course 4.

Stand by for a reply to your topic.

1 Like
  1. Please do not post your code on the forum. That’s not allowed by the Code of Conduct. If a mentor needs to see your code, we’ll contact you with instructions.

  2. The issue you report could be caused by your rnn_cell_forward() function.

  3. It would be helpful if you post a screen capture image that shows any error messages or asserts.

1 Like

Thanks for the guidelines. I’ll make sure I follow them.

Here’s the screenshot of the error message I’m struggling with on rnn_forward:

Here are the values that get printed when I run rnn_cell_forward:

I think this is not correct. a_next should be initialized to a0, which is one of the input parameters.

Do not use t+1, that is incorrect.

Do not use t+1, that is incorrect.


I think this is not correct. a_next should be initialized to a0, which is one of the input parameters.

To clarify: I did initialise a_next to a[:, :, 0] before passing it to rnn_cell_forward as the second argument. I’m not sure what / where the issue is.

That is not correct.

Oh, thanks a lot. That solves it. I should have looked at the function’s signature better.

1 Like