Categorical Cross Entropy Loss¶
cce_loss_type
cce_loss_type()
Categorical Cross Entropy (CCE) loss measures the performance of a classification model with multiple classes where each sample belongs to exactly one class.
\[L = -\frac{1}{N} \sum_{i=1}^{N} \sum_{c=1}^{C} y_{i,c} \log(\hat{y}_{i,c})\]
where: - \(y_{i,c}\) is 1 if sample \(i\) belongs to class \(c\), 0 otherwise - \(\hat{y}_{i,c}\) is the predicted probability for class \(c\) - \(N\) is the number of samples - \(C\) is the number of classes
Use Cases¶
Multi-class classification (mutually exclusive classes)
Image classification
Text categorisation
Any problem where each sample has one true class
Example¶
use athena__loss
type(cce_loss_type) :: loss
type(array_type), dimension(:,:) :: predicted, expected
type(array_type), pointer :: loss_value
! Initialise loss function
loss = cce_loss_type()
! Compute loss (expected should be one-hot encoded)
loss_value => loss%compute(predicted, expected)
Notes¶
Expects one-hot encoded labels
Typically used with softmax output activation
Uses small epsilon (1e-10) to prevent log(0) errors
Sum of predicted probabilities should equal 1 for each sample