oa::ml::loss::cross_entropy_masked

Compute mean cross-entropy over the rows selected by a floating FP32 mask. logits has shape [N, C]; targets and mask have shape [N]. A zero mask value excludes its row and produces an exact-zero logits adjoint. valid_count is the caller-provided normalization denominator and must be in 1..=N; it is not read back or recomputed from device storage. Reverse mode differentiates only logits. Errors Returns an error when ranks, shapes, dtypes, ownership, valid_count, allocation, or runtime recording are invalid.

FnRust public API

Function Documentation

pub fn cross_entropy_masked( logits: &Matrix, targets: &Matrix, mask: &Matrix, valid_count: usize ) -> Result<Matrix>
Compute mean cross-entropy over the rows selected by a floating FP32 mask. logits has shape [N, C]; targets and mask have shape [N]. A zero mask value excludes its row and produces an exact-zero logits adjoint. valid_count is the caller-provided normalization denominator and must be in 1..=N; it is not read back or recomputed from device storage. Reverse mode differentiates only logits. Errors Returns an error when ranks, shapes, dtypes, ownership, valid_count, allocation, or runtime recording are invalid.