code: def testNpXent(self):
      # We create 2 batches of logits for testing.
      # batch 0 is the boring uniform distribution: 1, 1, 1, 1, with target 3.
      # batch 1 has a bit of difference: 1, 2, 3, 4, with soft targets (1, 2).
      logits = [[1.0, 1.0, 1.0, 1.0], [1.0, 2.0, 3.0, 4.0]]
      labels = [[0.0, 0.0, 0.0, 1.0], [0.0, 0.5, 0.5, 0.0]]
  
      # For batch 0, we expect the uniform distribution: 0.25, 0.25, 0.25, 0.25
      # With a hard target 3, the gradient is [0.25, 0.25, 0.25, -0.75]
      # The loss for this batch is -log(0.25) = 1.386
      #
      # For batch 1, we have:
      # exp(0) = 1
      # exp(1) = 2.718
      # exp(2) = 7.389
      # exp(3) = 20.085
      # SUM = 31.192
      # So we have as probabilities:
      # exp(0) / SUM = 0.032
      # exp(1) / SUM = 0.087
      # exp(2) / SUM = 0.237
      # exp(3) / SUM = 0.644
      # With a soft target (1, 2), the gradient is
      # [0.032, 0.087 - 0.5 = -0.413, 0.237 - 0.5 = -0.263, 0.644]
      # The loss for this batch is [0.5 * -log(0.087), 0.5 * -log(0.237)]
      # = [1.3862, 1.9401]
      np_loss, np_gradient = self._npXent(
          np.array(labels), np.array(logits)
      )
      self.assertAllClose(
          np.array(
              [
                  [0.25, 0.25, 0.25, -0.75],
                  [0.0321, -0.4129, -0.2632, 0.6439],
              ]
          ),
          np_gradient,
          rtol=1.0e-3,
          atol=1.0e-3,
      )
      self.assertAllClose(
          np.array([1.3862, 1.9401]), np_loss, rtol=1.0e-3, atol=1.0e-3
      )
  
imports: import numpy
  from tensorflow.python.eager import backprop
  from tensorflow.python.framework import config
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gradient_checker
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops.nn_grad import _SoftmaxCrossEntropyWithLogitsGrad
  from tensorflow.python.platform import test
label_desc: Use image node_id 7 for calling the XentOpTestBase obj's underlying member method code with example usage: obj.testNpXent() without return types