tf.keras.losses.categorical_generalized_cross_entropy
Stay organized with collections
Save and categorize content based on your preferences.
Computes the Generalized Cross Entropy loss.
tf.keras.losses.categorical_generalized_cross_entropy(
y_true, y_pred, q
)
Generalized Cross Entropy (GCE) is a noise-robust loss function that
provides better robustness against noisy labels than standard cross entropy.
It generalizes both cross entropy and mean absolute error through
the parameter q, where values closer to 1 make the loss more robust
to noisy labels.
loss = (1 - p**q) / q
where p is the predicted probability for the true class and q
is the noise parameter.
Args |
y_true
|
Ground truth labels. Expected to contain integer class indices
with shape [batch_size] or [batch_size, 1].
|
y_pred
|
The predicted class probabilities, with shape
[batch_size, num_classes].
|
q
|
Float in range (0, 1). It is the noise parameter.
Controls the behavior of the loss:
- As
q approaches 0: Behaves more like cross entropy
- As
q approaches 1: Behaves more like mean absolute error
|
Returns |
GCE loss values with shape [batch_size].
|
<!-- Tabular view -->
<table class="responsive fixed orange">
<colgroup><col width="214px"><col></colgroup>
<tr><th colspan="2"><h2 class="add-link">References</h2></th></tr>
<tr class="alt">
<td colspan="2">
- [Zhang, Sabuncu, 2018](https://arxiv.org/abs/1805.07836)
("Generalized Cross Entropy Loss for Training
Deep Neural Networks with Noisy Labels")
</td>
</tr>
</table>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]