class_docstr: The loss function maker.
docstr: Makes the loss function.
  
  Returns:
    A function _loss_fn(). See `_loss_fn()` for its signature.
  
  Raises:
    ValueError: If `reduction` is invalid.
    ValueError: If `loss_keys` is None or empty.
    ValueError: If `loss_keys` and `loss_weights` have different sizes.
docstr_tok: ["Makes","the","loss","function",".","Returns",":","A","function","_loss_fn","(",")",".","See","`","_loss_fn","(",")","`","for","its","signature",".","Raises",":","ValueError",":","If","`","reduction","`","is","invalid",".","ValueError",":","If","`","loss_keys","`","is","None","or","empty",".","ValueError",":","If","`","loss_keys","`","and","`","loss_weights","`","have","different","sizes","."]
code: def make(self) -> utils.LossFunction:
      """Makes the loss function.
  
      Returns:
        A function _loss_fn(). See `_loss_fn()` for its signature.
  
      Raises:
        ValueError: If `reduction` is invalid.
        ValueError: If `loss_keys` is None or empty.
        ValueError: If `loss_keys` and `loss_weights` have different sizes.
      """
  
      if (
          self.reduction not in tf.compat.v1.losses.Reduction.all()
          or self.reduction == tf.compat.v1.losses.Reduction.NONE
      ):
          raise ValueError(f"Invalid reduction: {self.reduction}")
  
      if not self.loss_keys:
          raise ValueError("loss_keys cannot be None or empty.")
  
      if not isinstance(self.loss_keys, list):
          self.loss_keys = [self.loss_keys]
  
      if self.loss_weights:
          if len(self.loss_keys) != len(self.loss_weights):
              raise ValueError(
                  "loss_keys and loss_weights must have the same size."
              )
  
      gumbel_sampler = losses_impl.GumbelSampler(**self.gumbel_params)
  
      def _loss_fn(
          labels: utils.TensorLike,
          logits: utils.TensorLike,
          features: Dict[str, utils.TensorLike],
      ) -> tf.Tensor:
          """Computes a single loss or weighted combination of losses.
  
          Args:
            labels: A `Tensor` of the same shape as `logits` representing relevance.
            logits: A `Tensor` with shape [batch_size, list_size]. Each value is the
              ranking score of the corresponding item.
            features: Dict of Tensors of shape [batch_size, list_size, ...] for
              per-example features and shape [batch_size, ...] for non-example
              context features.
  
          Returns:
            An op for a single loss or weighted combination of multiple losses.
  
          Raises:
            ValueError: If `loss_keys` is invalid.
          """
          weights = None
          if self.weights_feature_name:
              weights = tf.convert_to_tensor(
                  value=features[self.weights_feature_name]
              )
              # Convert weights to a 2-D Tensor.
              weights = utils.reshape_to_2d(weights)
  
          gbl_labels, gbl_logits, gbl_weights = gumbel_sampler.sample(
              labels, logits, weights=weights
          )
  
          loss_kwargs = {
              "labels": labels,
              "logits": logits,
              "weights": weights,
              "reduction": self.reduction,
              "name": self.name,
          }
          gbl_loss_kwargs = {
              "labels": gbl_labels,
              "logits": gbl_logits,
              "weights": gbl_weights,
              "reduction": self.reduction,
              "name": self.name,
          }
          loss_kwargs.update(self.params)
          gbl_loss_kwargs.update(self.params)
          if self.lambda_weight is not None:
              gbl_loss_kwargs["lambda_weight"] = self.lambda_weight
  
          loss_kwargs_with_lambda_weight = loss_kwargs.copy()
          loss_kwargs_with_lambda_weight[
              "lambda_weight"
          ] = self.lambda_weight
  
          key_to_fn = self.build_key_to_loss_fn_mapping(
              loss_kwargs,
              loss_kwargs_with_lambda_weight,
              gbl_loss_kwargs,
          )
  
          # Obtain the list of loss ops.
          loss_ops = []
          for loss_key in self.loss_keys:
              if loss_key not in key_to_fn:
                  raise ValueError(f"Invalid loss_key: {loss_key}.")
              loss_fn, kwargs = key_to_fn[loss_key]
              loss_ops.append(loss_fn(**kwargs))
  
          # Compute weighted combination of losses.
          if self.loss_weights:
              weighted_losses = []
              for loss_op, loss_weight in zip(
                  loss_ops, self.loss_weights
              ):
                  weighted_losses.append(
                      tf.multiply(loss_op, loss_weight)
                  )
          else:
              weighted_losses = loss_ops
  
          return tf.add_n(weighted_losses)
  
      return _loss_fn
  
imports: from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union
  import tensorflow
  from tensorflow_ranking.python import losses_impl
  from tensorflow_ranking.python import utils
label_desc: Use image node_id 3 for calling the _LossFunctionMaker obj's underlying member method code with example usage: obj.make() and returns: _loss_fn, tf