# mlx.nn.losses.cross_entropy — MLX 0.0.7 documentation

Skip to main content
`Ctrl`+`K`

# mlx.nn.losses.cross_entropy

class mlx.nn.losses.cross_entropy(logits: array, targets: array, weights: Optional [ array ] = None, axis: int = - 1, label_smoothing: float = 0.0, reduction: str = 'none')

  Computes the cross entropy loss.

  Parameters:

    - logits (array) – The unnormalized predicted logits.

    - targets (array) – The target values, as class indices.

    - weights (array , optional) – Weights for each target. Default: `None`.

    - axis (int , optional) – The axis over which to compute softmax. Default: `-1`.

    - label_smoothing (float , optional) – Label smoothing factor. Default: `0`.

    - reduction (str , optional) – Specifies the reduction to apply to the output: `'none'` | `'mean'` | `'sum'`. Default: `'none'`.

  Returns:

    The computed cross entropy loss.

  Return type:

    array