C5 W1 Assignment 1

Cannot figure out the error of the function rnn_forward:

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

If your previous rnn_cell_forward function passes the tests, then it must be that you are invoking it incorrectly. At each timestep, you pass in the x value for the current timestep and the a value from the previous timestep (which is a0 for the first timestep). Are you sure you’ve checked your logic for those points?

Not sure it’s much help, but for reference here are my output values from that section:

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
All tests passed

I see. I should use the initialized variable. This applies to the function lstm_cell_forward.

Thanks!!

The instructions are pretty clear. But I thought you were asking about rnn_forward. lstm_cell_forward is a different function, but it also has detailed instructions.