code: def test_softmax_with_loss(self, n, D, gc, only_loss, dc):
      # n = number of examples, D = |labels|
      # Initialize X and add 1e-2 for numerical stability
      np.random.seed(2603)
      X = np.random.rand(n, D).astype(np.float32)
      X = X + 1e-2
  
      # Initialize label
      label = (np.random.rand(n) * D).astype(np.int32)
  
      # Reference implementation of cross entropy with soft labels
      def label_softmax_crossent(X, label):
          probs = np.zeros((n, D))
          rowmax = np.zeros(n)
          for i in range(n):
              rowmax[i] = max(X[i,])
              # We need to subtract the max to avoid numerical issues
              probs[i] = X[i] - rowmax[i]
              exps = np.exp(probs[i,])
              norm = sum(exps)
              probs[i,] = exps / norm
  
          label_xent = [
              -np.log(max(probs[i][label[i]], 1e-20)) for i in range(n)
          ]
          avgloss = np.sum(label_xent) / float(n)
          return (probs, avgloss)
  
      op = core.CreateOperator(
          "SoftmaxWithLoss",
          ["X", "label"],
          ["probs", "avgloss"],
          only_loss=only_loss,
      )
  
      self.assertReferenceChecks(
          device_option=gc,
          op=op,
          inputs=[X, label],
          reference=label_softmax_crossent,
      )
  
      self.assertGradientChecks(
          gc, op, [X, label], 0, [1], stepsize=1e-4, threshold=1e-2
      )
  
imports: from caffe2.python import core, workspace
  from hypothesis import given, settings
  import caffe2.python.hypothesis_test_util
  import caffe2.python.serialized_test.serialized_test_util
  import hypothesis.strategies
  import numpy
  import unittest
label_desc: Use image node_id 4 for calling the TestSoftmaxOps obj's underlying member method code with example usage: obj.test_softmax_with_loss(n, D, gc, only_loss, dc) and returns: probs,  avgloss