code: def test_make_approx_ndcg_fn(self):
      scores = [[1.4, -2.8, -0.4], [0.0, 1.8, 10.2], [1.0, 1.2, -3.2]]
      labels = [[0.0, 2.0, 1.0], [1.0, 0.0, 3.0], [0.0, 0.0, 0.0]]
      weights = [[2.0], [1.0], [1.0]]
      weights_feature_name = "weights"
      features = {weights_feature_name: weights}
      loss_fn_simple = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          reduction=tf.compat.v1.losses.Reduction.SUM,
      )
      self.assertAlmostEqual(
          loss_fn_simple(labels, scores, features).numpy(),
          -(
              (1 / (3 / ln(2) + 1 / ln(3))) * (3 / ln(4) + 1 / ln(3))
              + (1 / (7 / ln(2) + 1 / ln(3))) * (7 / ln(2) + 1 / ln(4))
          ),
          places=5,
      )
  
      loss_fn_weighted = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          weights_feature_name=weights_feature_name,
          reduction=tf.compat.v1.losses.Reduction.SUM,
      )
      self.assertAlmostEqual(
          loss_fn_weighted(labels, scores, features).numpy(),
          -(
              2
              * (1 / (3 / ln(2) + 1 / ln(3)))
              * (3 / ln(4) + 1 / ln(3))
              + 1
              * (1 / (7 / ln(2) + 1 / ln(3)))
              * (7 / ln(2) + 1 / ln(4))
          ),
          places=5,
      )
  
      # Test different temperature.
      loss_fn_1 = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          params={"temperature": 10},
      )
      loss_fn_2 = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          params={"temperature": 0.01},
      )
      self.assertNotAlmostEqual(
          loss_fn_1(labels, scores, features).numpy(),
          loss_fn_2(labels, scores, features).numpy(),
      )
  
      # Test loss reduction method.
      # Two reduction methods should return different loss values.
      loss_fn_1 = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          reduction=tf.compat.v1.losses.Reduction.SUM,
      )
      loss_fn_2 = ranking_losses.make_loss_fn(
          ranking_losses.RankingLossKey.APPROX_NDCG_LOSS,
          reduction=tf.compat.v1.losses.Reduction.MEAN,
      )
      self.assertNotAlmostEqual(
          loss_fn_1(labels, scores, features).numpy(),
          loss_fn_2(labels, scores, features).numpy(),
      )
  
imports: import math
  import tensorflow
  from tensorflow_ranking.python import losses
  from tensorflow_ranking.python import losses_impl
label_desc: Use image node_id 15 for calling the LossesTest obj's underlying member method code with example usage: obj.test_make_approx_ndcg_fn() without return types