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

Skip to main content
`Ctrl`+`K`

# mlx.nn.losses.binary_cross_entropy

class mlx.nn.losses.binary_cross_entropy(logits: array, targets: array, reduction: str = 'none')

  Computes the binary cross entropy loss.

  Parameters:

    - logits (array) – The unnormalized (pre-sigmoid) predicted logits.

    - targets (array) – The binary target values in {0, 1}.

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

  Returns:

    The computed binary cross entropy loss.

  Return type:

    array

  Examples

      >>> import mlx.core as mx
      >>> import mlx.nn as nn
      >>> inputs = mx.array([0.105361, 0.223144, 1.20397, 0.916291])
      >>> targets = mx.array([0, 0, 1, 1])
      >>> loss = nn.losses.binary_cross_entropy(inputs, targets, "mean")
      >>> loss
      array([0.612192], dtype=float32)