# Exercise 9 - L_model_backward dA_prev referenced before

hi ,
i got an error:
local variable ‘dA_prev’ referenced before assignment
i don’t know what this mean,

i just did input “dAL, current_cache = caches[L-1]” for sigmoid to function linear_activation_backward as guided

and input “grads[“dA” + str(l + 1)], current_cache = caches[l]” to function linear_activation_backward for relu as guided

Hi Lucy,

## hi Rashmi,

UnboundLocalError Traceback (most recent call last)
in
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads[‘dA0’]))
5 print("dA1 = " + str(grads[‘dA1’]))

in L_model_backward(AL, Y, caches)
41 # YOUR CODE STARTS HERE
42 current_cache = caches[L-1]
—> 43 dA_prev_temp, dW_temp, db_temp =linear_activation_backward(dAL, current_cache, activation=“sigmod”)
45 grads[“dW” + str(L)] = dW_temp

in linear_activation_backward(dA, cache, activation)
35 # YOUR CODE ENDS HERE
36
—> 37 return dA_prev, dW, db

UnboundLocalError: local variable ‘dA_prev’ referenced before assignment

Hi Lucy,

You are misspelling ‘sigmoid’. Please make the changes and pass the test.

If that doesn’t work, let me know

Happy Learning!

I think this is one of big gaps between educational contents and real-world implementations.

Lucy dug a good point. A template for linear_activation_backward() only considers two strings for activations, i.e., “relu” and “sigmoid”. No “leaky relu”, “tanh”, “softmax” and so on. That’s absolutely OK. But, in the real world implementations, we usually add “otherwise/else” to avoid from falling into unpredictable conditions. I’m from the industry side, and feel that some programming examples are only focusing on features/functions that are being focused, and not caring about coding conventions and best practices. If this is a real world system, then, Lucy will get an error message to say “an activation function sigmod is not supported”, which definitely help Lucy’s debugging.

1 Like

You are very true Nobu! This unbound local error should have specified what you pointed out.

That’s why I kept looking for other errors, but I then zeroed down to the misspelled word ‘sigmoid’ to see if that works or not