code: def test_weighted_category_cross_entropy(self):
      layer = tl.WeightedCategoryCrossEntropy()
      targets = np.array([0, 1])
      weights = np.array([30, 10])
  
      # Near-perfect prediction (for both items in batch).
      model_outputs = np.array(
          [[9.0, 2.0, 0.0, -2.0], [2.0, 9.0, 0.0, -2.0]]
      )
      loss = layer([model_outputs, targets, weights])
      self.assertAlmostEqual(loss, 0.001, places=3)
  
      # More right than wrong (for both items in batch).
      model_outputs = np.array(
          [[2.2, 2.0, 0.0, -2.0], [2.0, 2.2, 0.0, -2.0]]
      )
      loss = layer([model_outputs, targets, weights])
      self.assertAlmostEqual(loss, 0.665, places=3)
  
      # First item (with 75% weight) near perfect, second more right than wrong.
      model_outputs = np.array(
          [[9.0, 2.0, 0.0, -2.0], [2.0, 2.2, 0.0, -2.0]]
      )
      loss = layer([model_outputs, targets, weights])
      self.assertAlmostEqual(loss, 0.167, places=3)
  
imports: from absl.testing import absltest
  import numpy
  import trax.layers
label_desc: Use image node_id 6 for calling the MetricsTest obj's underlying member method code with example usage: obj.test_weighted_category_cross_entropy() without return types