class_docstr: Tests for DP-enabled multiclass heads.
docstr: Tests loss() returns per-example losses.
docstr_tok: ["Tests","loss","(",")","returns","per-example","losses","."]
code: def testLoss(self):
      """Tests loss() returns per-example losses."""
  
      head = multi_class_head.DPMultiClassHead(3)
      features = {"feature_a": np.full((4), 1.0)}
      labels = np.array([[2], [1], [1], [0]])
      logits = np.array(
          [
              [2.0, 1.5, 4.1],
              [2.0, 1.5, 4.1],
              [2.0, 1.5, 4.1],
              [2.0, 1.5, 4.1],
          ]
      )
  
      actual_loss = head.loss(labels, logits, features)
      expected_loss = tf.expand_dims(
          tf.compat.v1.losses.sparse_softmax_cross_entropy(
              labels=labels,
              logits=logits,
              reduction=tf.keras.losses.Reduction.NONE,
          ),
          -1,
      )
  
      self.assertEqual(actual_loss.shape, [4, 1])
  
      if tf.executing_eagerly():
          self.assertEqual(actual_loss.shape, [4, 1])
          self.assertAllClose(actual_loss, expected_loss)
          return
  
      self.assertAllClose(expected_loss, self.evaluate(actual_loss))
  
file_path: privacy/tensorflow_privacy/privacy/estimators/multi_class_head_test.py
imports: import numpy
  import tensorflow
  from tensorflow_privacy.privacy.estimators import multi_class_head
  from tensorflow_privacy.privacy.estimators import test_utils
  from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasSGDOptimizer
  from tensorflow_estimator.python.estimator import estimator
label_desc: Use image node_id 1 for calling the DPMultiClassHeadTest obj's underlying member method code with example usage: obj.testLoss() without return types