public override 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. In logit mode Softmax is integrated into the loss and must not be applied first.
| Parameter | Description |
|---|---|
logits | Matrix [samples, classes] of finite logits or probabilities. |
gradientScale | Positive finite multiplier for the derivative; loss remains unscaled. |
labels | One-dimensional Int array; values are in [0, classes). |
Loss and derivative with respect to the supplied inputs (logits or probabilities).
result = SparseCategoricalCrossentropy<Float>().compute(logits, labels)