eazygrad.cross_entropy_loss

eazygrad.cross_entropy_loss(predicted: _Tensor, target: _Tensor) _Tensor[source]

Compute cross-entropy loss from class logits.

Parameters:
  • predicted (_Tensor) – Logits of shape (N, C).

  • target (_Tensor) – Targets of shape (N,) for integer class indices or shape (N, C) for soft targets.

Returns:

_Tensor – Scalar loss tensor.

Notes

The loss is computed with a numerically stable log-sum-exp formulation.