Problem with cost function

Hello everybody, really happy to have you here,
I’ve passed all tests of week 3 assignments, but the last graded exercise (cost function) gives me the wrong answer, although I think I followed the rules,

the error said “Did you get the mean of cost function”
and I’ve passed the cost into tf.reduce_mean() function

I was having the same, error!!

In the hints they gave this:

( are expected to be of shape (number of examples, num_classes).

So after inspecting, I got to know that, our inputs logits and labels are of the shape, (num_classes, examples).

So transposing them to the shape - (number of examples, num_classes) worked for me. TensorFlow function used - tf.transpose()

Hope it works for you too!!


Hello Saransh, Thank you for devoting time and reading my problem. yes, you are right, I solved my problem with the use of your help thank you mate.


Hi, I have the same problem and I tried to use tf.transpose() but it didn’t give me the expected output. I got this output after using tf.transpose()
tf.Tensor(0.8071431, shape=(), dtype=float32)

Before using the tf.transpose() I got this, which is also not the expected output:
tf.Tensor(0.147125, shape=(), dtype=float32)

This is my implementation:

[Removed solution code]

Hey, I got the same. I was wondering if you sorted it out please. Thank you.