Week 4_Assignment 2_Exercise 5_local variable reference

Hello dear friends,

When writing exercise 5, I got this error
“UnboundLocalError: local variable ‘linear_cache’ referenced before assignment”

This is the screenshot of the error

I worked through the logic and couldn’t find anything wrong, and the error message suggests it could be a variable declaration issue? But the variable “linear_cache” is already declared for us, and I suppose we shouldn’t touch the code not inside the blanks?

I suspect it might be a tiny issue I overlooked, but I have spent a whole day and couldn’t figure it out. Could anyone offer some help?

Jason L

Note that relu and “relu” are not the same. Check this thread.

Thank you so much, I totally missed that!

Now I can proceed, and moved onto exercise 9, I encountered this error:

I know the error says the second input into sigmoid_backward is a tuple and it cannot be negated. I think I can somehow modify the tuple into a list, but the instruction specifically tell us how to use the sigmoid_backward function and “activation_cache” is a tuple. How can I work around this?

Your current_cache is not correct. What should be the current_cache for sigmoid? The answer is in the notebook. Read below lines again:

caches -- list of caches containing:
                every cache of linear_activation_forward() with "relu" (it's caches[l], for l in range(L-1) i.e l = 0...L-2)
                the cache of linear_activation_forward() with "sigmoid" (it's caches[L-1])