SparseCategoricalCrossentropy
classin packageklyn.math.nn.losses
public class SparseCategoricalCrossentropy<T extends AbstractFloat = Float> implements ClassificationLoss<T>
SparseCategoricalCrossentropy
All Implemented Interfaces: ClassificationLoss

Mean multiclass cross-entropy from logits or normalized probabilities and integer labels. Log-sum-exp is evaluated after subtracting each row maximum. No one-hot tensor or softmax Jacobian is materialized. Reduction is performed in FP64.

Example

loss = SparseCategoricalCrossentropy<Float>().compute(logits, labels)

Properties
Modifier and Type Member Description
public readonly property fromLogits
fromLogits as Boolean
Whether inputs are unnormalized logits rather than probabilities.
Constructors
Modifier and Type Member Description
public SparseCategoricalCrossentropy Selects stable log-sum-exp mode or probability mode.
Methods
Modifier and Type Member Description
public override compute
compute(logits as NDArray<T>, labels as NDArray<Int>, gradientScale as Double = 1.0) as LossResult<T>
Computes the mean loss and its mean-reduced input gradient.