W1A1 unq_c2: Wrong values for a

I get the value error a and I don’t understand why. I have checked a couple times, but I still don’t understand the problem. I have also tried avoiding passing by reference by using 1.0*var when passing things into functions, but that doesn’t change the outcome.

Can somebody help?

1 Like

It would be better to share the exercise number and full error.

Sorry, I don’t see the number. This is the name of the notebook ’ Building your Recurrent Neural Network - Step by Step’.

1 Like

In the table of contents it is question 1.2, but also I have the same problem in 2.2.

1 Like

This is the output:

a[4][1] =
[-0.93013738 0.991315 -0.98694298 -0.99723276]
a.shape =
(5, 10, 4)
y_pred[1][3] =
[0.0440187 0.41032346 0.01401205 0.42558194]
y_pred.shape =
(2, 10, 4)
caches[1][1][3] =
[-1.1425182 -0.34934272 -0.20889423 0.58662319]
len(caches) =
2


AssertionError Traceback (most recent call last)
in
18
19 #UNIT TEST
—> 20 rnn_forward_test(rnn_forward)

~/work/W1A1/public_tests.py in rnn_forward_test(target)
78 assert len(caches[0]) == T_x, f"len(cache) must be T_x = {T_x}"
79
—> 80 assert np.allclose(a[5, 2, 2:6], [0.99999291, 0.99332189, 0.9921928, 0.99503445]), “Wrong values for a”
81 assert np.allclose(y_pred[2, 1, 1: 5], [0.19428, 0.14292, 0.24993, 0.00119], atol=1e-4), “Wrong values for y_pred”
82 assert np.allclose(caches[1], x_tmp), f"Fail check: cache[1] != x_tmp"

AssertionError: Wrong values for a

1 Like

This is the expected output:

Expected Output:

a[4][1] = 
 [-0.99999375  0.77911235 -0.99861469 -0.99833267]
a.shape = 
 (5, 10, 4)
y_pred[1][3] =
 [ 0.79560373  0.86224861  0.11118257  0.81515947]
y_pred.shape = 
 (2, 10, 4)
caches[1][1][3] =
 [-1.1425182  -0.34934272 -0.20889423  0.58662319]
len(caches) = 
 2
1 Like

Hi @julia8 ,

The rnn_forward() function calls rnn_cell_forward() to calculate the values of ‘a’. Did your code for rnn_cell_forward() pass the unit test? If not, the error will propagate to the rnn_forward() function. Please check the rnn_cell_forward() function, making sure your code follows the formula given in the instructions.

2 Likes

If your rnn_cell_forward is correct, then the next thing to check is how you initialize a_next in rnn_forward before you start the main loop. One common mistake is to initialize it to zeros of the appropriate shape, but notice that one of the arguments to rnn_forward is a0.

Here’s what I get if I make that mistake on purpose:

a[4][1] = 
 [-0.93013738  0.991315   -0.98694298 -0.99723276]
a.shape = 
 (5, 10, 4)
y_pred[1][3] =
 [0.0440187  0.41032346 0.01401205 0.42558194]
y_pred.shape = 
 (2, 10, 4)
caches[1][1][3] =
 [-1.1425182  -0.34934272 -0.20889423  0.58662319]
len(caches) = 
 2

Hmmmmm. That looks pretty close to your values. :nerd_face:

4 Likes

It did pass.

1 Like

Thanks, that fixed it. I had read this in another post before, but somehow didn’t get it. Now I got it. Thanks again.

3 Likes