code: def multilabel_bce_loss(
      labels: np.ndarray,
      pred: np.ndarray,
      sample_weight: Optional[np.ndarray] = None,
      from_logits=False,
      small_value=1e-8,
  ) -> np.ndarray:
      """Computes the per-multi-label-example cross entropy loss.
  
      Args:
        labels: numpy array of shape (num_samples, num_classes). labels[i] is the
          true multi-hot encoded label (vector) of the i-th sample and each element
          of the vector is one of {0, 1}.
        pred: numpy array of shape (num_samples, num_classes).  pred[i] is the
          logits or probability vector of the i-th sample.
        sample_weight: a vector of weights of shape (num_samples, ) that are
          assigned to individual samples. If not provided, then each sample is
          given unit weight. Only the LogisticRegressionAttacker and the
          RandomForestAttacker support sample weights.
        from_logits: whether `pred` is logits or probability vector.
        small_value: a scalar. np.log can become -inf if the probability is too
          close to 0, so the probability is clipped below by small_value.
  
      Returns:
        the cross-entropy loss of each sample for each class.
      """
      # Check arrays.
      if labels.shape[0] != pred.shape[0]:
          raise ValueError(
              "labels and pred should have the same number of examples,",
              f"but got {labels.shape[0]} and {pred.shape[0]}.",
          )
      if not ((labels == 0) | (labels == 1)).all():
          raise ValueError(
              "labels should be in {0, 1}. For multi-label classification the labels "
              "should be multihot encoded."
          )
      # Check if labels vectors are multi-label.
      summed_labels = np.sum(labels, axis=1)
      if ((summed_labels == 0) | (summed_labels == 1)).all():
          logging.info(
              (
                  "Labels are one-hot encoded single label. Every sample has at most one"
                  " positive label."
              )
          )
      if not from_logits and ((pred < 0.0) | (pred > 1.0)).any():
          raise ValueError(
              (
                  "Prediction probabilities are not in [0, 1] and "
                  "`from_logits` is set to False."
              )
          )
      if sample_weight is None:
          # If sample weights are not provided, set them to 1.0.
          sample_weight = 1.0
      if isinstance(sample_weight, list):
          sample_weight = np.asarray(sample_weight)
      if isinstance(sample_weight, np.ndarray) and (
          sample_weight.ndim == 1
      ):
          # NOMUTANTS--np.reshape(X, (-1, 1)) == np.reshape(X, (-N, 1)), N >=1.
          sample_weight = np.reshape(sample_weight, (-1, 1))
  
      # Multi-class multi-label binary cross entropy loss
      if from_logits:
          pred = special.expit(pred)
      bce = labels * np.log(pred + small_value)
      bce += (1 - labels) * np.log(1 - pred + small_value)
      return -bce * sample_weight
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/utils.py
imports: import enum
  import logging
  import numbers
  from typing import Callable, Iterable, Optional, Union
  import numpy
  from scipy import special
label_desc: Use image node_id 3 for calling a global function with example usage: multilabel_bce_loss(labels, pred, sample_weight, from_logits, small_value) and returns: unknown