W-3-- Programming Assignment: TensorFlow Introduction

While computing the cost function, an error occurred after I used the below line.

{Moderator’s Edit: Solution Code Removed}

What’s wrong with my code?

Whats the error showing?

Hey @Ankur_Rai,
You have missed taking the transpose of labels and logits before passing them to the tf.keras.losses.categorical_crossentropy() function.

As mentioned in the markdown cell above this particular code cell, y_pred and y_true are expected to be of shape (number of examples, num_classes) when they are passed to the aforementioned function, but when they are passed in the function as arguments, they are of shape (num_classes, number of examples). So, take the transpose first, and then pass these variables. Let us know if this helps.

P.S. - Posting solution code publicly is against the community guidelines. If a mentor needs to take a look at your code, he/she will ask you to DM it.

Cheers,
Elemento

2 Likes

Yes, it helped. Thank you.

If you still have problems after fixing the transpose issue, you might want to take a look at the meaning of the from_logits parameter to the cost function.

The problem got resolved after fixing the transpose. Thank you for your reply.