Course 2 Week 2 Exercise 6.1: Running Model Produces Error

I am getting an error when running the first training cell in section 6.1. All previous cells have the “All tests passed” clearance. Image of the problem below. I’m gonna debug on the side in the possible chance I have an exceptionally sinister bug that made it through the checks in the mini-batch section–but maybe the problem has already come up. Thanks

Yes, it does look like perhaps your minibatch logic is returning incorrectly shaped results. One possibility is that you “hard-coded” the implementation to match the particular test case there. That could include referencing global variables from within the random_mini_batches code …

I’ll check this, but my code in the function cell is pretty general only relying on the inputs and the function scope. I don’t think I can post the code here (right?).
'Tis a tricky one

Ahhh, I found the error. In my minibatch function, after doing the num iterations and handling the remainder examples I had an error for appending the last minibatch.
i.e. minibactch_Y = …
Instead of correctly appending the final batch it used the previously defined minibatch.

Idk if this is worth putting a test case but that is a pretty sneaky bug.

Thanks for following up here. Just to make sure I understand the point you’re making (so that I can advise them about how to update the test cases), my interpretation is that the mistake is that you did not correctly handle the last partial minibatch, but only for the Y labels. It sounds like you used the last full batch in that case. Do I have that right?


That’s correct. My Y-variable had a type in the variable name. So I created an extra variable for the partial batch and the function updated the correct Y-variable with a duplicate from the last whole batch.

I’m surprised the tests didn’t catch this. But looking at this test cases I think only the X mini batches are tested and not the Y mini batches.

I purposefully broke the function for the Y mini batch to test and get the all clear (image below)

Thanks very much for the thorough response here. Based on that, it should be pretty straightforward for them beef up the tests to catch this. I’ll file the bug!