Course 5 Week 1 Assignment 1 Exercise 4: lstm_forward AssertionError length of caches[0][0] must be 10

The expected output of the code is correct for the unit test for lstm_forward BUT the length of caches[0][0] is 6 and not 10 so it generates the AssertionError in the Topic

Given the expected output of two caches and the length of caches are correct, I’m not sure what the AssertionError means and how to address it.

Thanks in advance for any feedback!!

Please post a screen capture image that shows the error message and any assert results.

Thanks! Here’s the output, the AssertionError and the Expected Output:

I’ve added the output, the AssertionError/result, and the Expected Output…thanks!

Your code passes the test that is built-into the notebook, but it does not pass the different test from lstm_forward_test().

This suggests something about your code is specific to the size or shape of the notebook’s unit test data.

Check if your code includes any fixed-size references to the dimensions of any of the variables; hard-coded indices or axes, for example.

Since the error is in the size of the “caches” return value, it’s possible the error is actually in your lstm_cell_forward() function.

You were correct–it was my confusion about the cache contents/size.

Per the lstm_cell_forward() instruction just after the ### END CODE HERE ### and before the return statement, the cache contents needed for backward propagation are listed: my “problem” code in lstm_forward had only 6 of the 10 items for the # Append the cache code, hence the error message.

Thanks for the pointer!

1 Like