DLS 1, week 4, Step by Step programming assignment

On week 4 on first DLS, first programming assignment ( Ex. 4), I kept having this mistake which I do not understand.

Code: Screenshot - 496c57491e97e74736ddaa508724c98f - Gyazo
Error: Screenshot - 3e8a9144bb4e8e31f520136678a121e6 - Gyazo

It kept saying “cache” was referenced before assignment. Meanwhile the “cache” variable was not even my code. It’s been 3 days and this looks trivial but I am unable to figure it out.

That type of error typically means you passed the wrong value for the activation argument, which has the result that you don’t take either of the branches in the subroutine you are calling. Just because the error is thrown in code you didn’t write, it does not mean it’s not your fault. What it means is that you passed bad arguments down to that subroutine.

Wrong activation argument huh! Still trying to figure it out. You mean the “activation” argument to the linear_activation_argument function, right?. I might sound dumb but I am not very good with these stuff. Sorry!
Thank you by the way!
Let me get to it and see what I can do.

Oh, actually, that’s not the cause. If you look at your code, you changed the indentation so that the assignment to the variable cache is part of the “if” clause for the “relu” case. So in the “sigmoid” case, it does not get executed. Note that indentation is part of the syntax in python, so you have to be careful about that. The line at issue here was part of the template code, so you shouldn’t have needed to change it. Here’s what the template code looks like:

Do you see how that differs from your version?

Yes, it worked perfectly. Thank you so much

1 Like