Course2, Week3, cannot compute_cost

Hello, I tried this function serveral times, but it didn’t work.
I referrenced some posts in deeplearning AI, but I could not find the solution.
Please help me.

{moderator edit - solution code removed}

Previous exercises are correct.

There are two things that you are missing in your implementation:

As they say in the instructions, the shapes of the labels and logits are not what the categorical cross entropy function expects. You need to transpose them first.

You are also not specifying the from_logits optional parameter to the loss function, so it assumes that the logits values are activation outputs. But as you can see from the way we built the forward propagation function, they are not: there is no activation function at the output layer. Sorry, I don’t think Prof Ng explains this anywhere or if so I forget, but that’s the way he will always do things from this point forward once we switch to using TF. It is more efficient to omit the activation function on the last layer and then tell the loss function to compute the activation and the loss at the same time. That is what the from_logits parameter is for. You can find more info in the TF documentation for the various cross entropy based loss functions.

Thank you for your service. I have understood your answer and I have solved the issues!