Welcome to our Support Center



Computes the crossentropy metric between the labels and predictions. Type : polymorphic.



Input parameters


 y_pred : array, predicted values (if from_logits = true then one hot logits for example, [0.1, 0.8, 0.9] else one hot probabilities for example, [0.1, 0.3, 0.6] for 3-class problem).
 y_true : array, true values.
from_logits : boolean, whether output is expected to be a logits tensor.
axis : integer, the dimension along which entropy is computed.


Output parameters


sparse_categorical_crossentropy : float, result.

Use cases

The SparseCategoricalCrossentropy metric is commonly used in machine learning, specifically in multiclass classification problems where the labels are integers, not one-hot vectors. It is often used as a loss function to train models, as it measures the distance between the probability distribution predicted by the model and the actual probability distribution.

Here are some examples of specific areas where SparseCategoricalCrossentropy can be used :

    • Image recognition : in image recognition problems where there are more than two image categories to predict, SparseCategoricalCrossentropy is often used. For example, in a problem where you’re trying to predict whether an image is a cat, a dog, or a horse, you could use SparseCategoricalCrossentropy as a loss function to train your model.
    • Natural Language Processing (NLP) : SparseCategoricalCrossentropy is also commonly used in NLP tasks, such as text classification, where class labels are often provided as integers.
    • Recommender systems : in recommender systems, SparseCategoricalCrossentropy can be used to train models that predict the ranking of various items.



Use this crossentropy metric when there are two or more label classes. We expect labels to be provided as integers. If you want to provide labels using one-hot representation, please use CategoricalCrossentropy metric.


All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install HAIBAL library to run it).

Easy to use

Table of Contents