C2_W1_Assignment: my_dense_v function outputs tensor type


In:C2_W1_Assignment, can someone explain why my_dense_v output is TensorFlow?

I’d guess that the sigmoid() activation function is outputting a tensor.
I have not checked that specifically though. It depends on what sigmoid function is being called.

No I checked that. The sigmoid function doesn’t output a tensor. I was hoping one of the teaching assistants would clarify.

I did some quick tests, and I think the sigmoid() function that is in autils.py is not what’s being used in the assignment. I can remove that function from the utility package entirely and the code still runs.

I think the sigmoid being used is from the tf package, so that’s why it returns a tensor.

If you add a call to sigmoid() inside the my_dense_v() function, and give it an invalid argument (like a scalar), you’ll get an error message from the tf package. So it’s using the tf sigmoid function.

Sorry, it took me a while to get back to this. I looked at what you mentioned above and i was thinking that if the sigmoid function is from the tf package, then in the code, he would have referenced it as tf.math.sigmoid. But in the code, he just calls it “Sigmoid” which is how it’s defined in the autils.py.


So in the first block, he is importing all the functions from that file by running this line:

from autils import *

Which allows him to use “sigmoid” function as is.

I know you mentioned that you deleted autils.py and ran the code without it. Did you actually download all the files and ran the code locally on your machine without autils.py?

Hello @Mo_Okasha,

The autils.sigmoid is overriden by tensorflow.keras.activations.sigmoid when we execute the line from public_tests import *.You may examine the sigmoid before and after calling that line.


1 Like

That makes sense. Thank you.