DLS course2 week 3 exercise 6(compute total loss)


logits=tf.reshape(logits, shape=(logits.shape[1],logits.shape[0]))
labels=tf.reshape(labels, shape=(labels.shape[1],labels.shape[0]))

total_loss = tf.reduce_sum(tf.keras.losses.categorical_crossentropy(logits,labels,from_logits=True))

Im facing error even after reshaping the inputs

Hi @Atharva_Kumbhakarn ,

A first note is: review the way you are using the loss function. The link provided above the cell will take you to the documentation. In particular, check this out:

tf.keras.metrics.categorical_crossentropy(    y_true, y_pred, from_logits=False, label_smoothing=0.0, axis=-1)

See that the order of the parameters is y_true, y_pred…

Also, check the shapes expected by the function versus the shapes you are producing. May be there’s another way to get the needed shape? think about using the available Transpose function, for example.