oa::ml::loss::cross_entropy

Compute mean cross-entropy over rank-two FP32 logits and U32 or I32 class targets. logits has shape [N, C], targets has shape [N], and the returned matrix is an FP32 scalar. I32 targets must be non-negative; any negative or out-of-range target produces NaN without an out-of-bounds access. Errors Returns an error when ranks, shapes, dtypes, ownership, allocation, or runtime recording are invalid.

FnRust public API

Function Documentation

pub fn cross_entropy( logits: &Matrix, targets: &Matrix ) -> Result<Matrix>
Compute mean cross-entropy over rank-two FP32 logits and U32 or I32 class targets. logits has shape [N, C], targets has shape [N], and the returned matrix is an FP32 scalar. I32 targets must be non-negative; any negative or out-of-range target produces NaN without an out-of-bounds access. Errors Returns an error when ranks, shapes, dtypes, ownership, allocation, or runtime recording are invalid.