Categorical Cross Entropy vs Sparse Categorical Cross Entropy

I was looking for a loss function when browsing through Keras documentation I found two loss functions. The first one categorical_cross_entropy was familiar, however I saw something I had never used before it was sparsed_categorical_cross_entropy.

The difference : Depends on the structure of your targets !

If your targets are one-hot encoded, you have to use categorical_crossentropy. Examples of one-hot encoding:


But if your targets are integers, use sparse_categorical_crossentropy. Examples of integer encodings (for the sake of completion):


Credits :

comments powered by Disqus