When I try to train Neuron Network with loss=“sparse_categorical_crossentropy”, my notebook returned an error. I don’t know how to fix it. I checked my code again and figured out that if I changed loss=“categorical_crossentropy”, my code still worked.
Can anyone help me? Thanks in advance.
Here is my notebook link:
Hi @Trung_Nguyen, the loss used is sparse_categorical_crossentropy, and the labels (y_train & y_test) are one hot encoded, which triggers the error.
-
The
categorical_crossentropy
is used as the loss when the labels are one hot encoded.
Example for a 3-class classification: [1,0,0] , [0,1,0], [0,0,1] -
The
sparse_categorical_crossentropy
is used as the loss when the labels are integers.
Example for a 3-class classification problem: [1] , [2], [3]
For more information, please go through this reference. Thank you!