Week 4 Assignment 2, Exercise 6 - train_step

Hi !

I would like some help with the train step. From what I can tell, the changes needed for the train step is pretty straight forward. But when I try to run the code, I seem to get the following error:

"AssertionError: Unexpected cost for epoch 0: -464959296.0 != 25629.055"

Below is the code I did for the train_step.

 # moderator edit: code removed

I am not sure if my bug is in the ‘train_step’ or is the bug in computing cost for style or content? All the tests in the previous sections passed - which makes me think, the bug may not be in computing costs. But again, the train step seems too easy to be buggy :slight_smile: … Please help.

Notice that your cost value turns out to be negative, which should never happen by definition. I would be suspicious about your previous cost logic. Maybe the test cases for the earlier functions don’t catch all possible bugs. Here’s a thread about one way to get negative cost values in this case, although that particular issue would cause the unit tests to fail earlier.

Thank you so much for the pointer. I bumped into the thread after posting my question. Indeed my issue was exactly the same as the one pointed by you. May be, we could add this as another “extra hint” in the exercise for future users?

I’m glad to hear that you found the solution. It’s a good point that we should request better hints and even a better test case to catch this in the unit tests, rather than failing mysteriously later. I’ll file a request about that.