code: def margin_logit_loss(model_logits, label, nb_classes=10):
      """Computes difference between logit for `label` and next highest logit.
  
      The loss is high when `label` is unlikely (targeted by default). This follows the same interface
      as `loss_fn` for projected_optimization, i.e. it returns a batch of loss values.
      """
  
      if "int" in str(label.dtype):
          logit_mask = tf.one_hot(label, depth=nb_classes, axis=-1)
      else:
          logit_mask = label
      if "int" in str(logit_mask.dtype):
          logit_mask = tf.cast(logit_mask, dtype=tf.float32)
      try:
          label_logits = tf.reduce_sum(
              logit_mask * model_logits, axis=-1
          )
      except TypeError:
          raise TypeError(
              "Could not take row-wise dot product between logit mask, of dtype "
              + str(logit_mask.dtype)
              + " and model_logits, of dtype "
              + str(model_logits.dtype)
          )
      logits_with_target_label_neg_inf = (
          model_logits - logit_mask * 99999
      )
      highest_nonlabel_logits = tf.reduce_max(
          logits_with_target_label_neg_inf, axis=-1
      )
      loss = highest_nonlabel_logits - label_logits
      return loss
  
file_path: cleverhans/cleverhans/tf2/attacks/spsa.py
imports: import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: margin_logit_loss(model_logits, label, nb_classes) and returns: loss