class_docstr: Defines metrics/loss among all moment retrieval models.
  
  A model is class with three members: get_metrics_fn, loss_fn, & a flax_model.
  
  get_metrics_fn returns a callable function, metric_fn, that calculates the
  metrics and returns a dictionary. The metric function computes f(logits_i,
  batch_i) on a minibatch, it has API:
    ```metric_fn(logits, batch).```
  
  The trainer will then aggregate and compute the mean across all samples
  evaluated.
  
  loss_fn is a function of API
    loss = loss_fn(logits, batch, model_params=None).
  
  This model class defines two losses, sigmoid cross entropy for classification
  and IoU for boundary regression.
class_docstr_tok: ["Defines","metrics\/loss","among","all","moment","retrieval","models",".","A","model","is","class","with","three","members",":","get_metrics_fn",",","loss_fn",",","&","a","flax_model",".","get_metrics_fn","returns","a","callable","function",",","metric_fn",",","that","calculates","the","metrics","and","returns","a","dictionary",".","The","metric","function","computes","f","(","logits_i",",","batch_i",")","on","a","minibatch",",","it","has","API",":","``","`","metric_fn","(","logits",",","batch",")",".","``","`","The","trainer","will","then","aggregate","and","compute","the","mean","across","all","samples","evaluated",".","loss_fn","is","a","function","of","API","loss","=","loss_fn","(","logits",",","batch",",","model_params=None",")",".","This","model","class","defines","two","losses",",","sigmoid","cross","entropy","for","classification","and","IoU","for","boundary","regression","."]
docstr: Computes classification loss.
docstr_tok: ["Computes","classification","loss","."]
code: def _cls_loss(
      self,
      batch_mask: jnp.ndarray,
      caption_mask: jnp.ndarray,
      frame_mask: jnp.ndarray,
      class_logits: jnp.ndarray,
      label: jnp.ndarray,
  ) -> jnp.ndarray:
      """Computes classification loss."""
      classification_loss_type = self.config.get(
          "classification_loss_type", "sigmoid"
      )
      cls_loss_weights = _cls_loss_weights(
          batch_mask,
          caption_mask,
          frame_mask,
          all_gather_loss=self.config.get("all_gather_loss", True),
      )
      class_logits, label = _adjust_classification_inputs(
          class_logits,
          label,
          all_gather_loss=self.config.get("all_gather_loss", True),
      )
      if classification_loss_type == "focal":
          classification_loss = temporal_localization_base_model.weighted_focal_sigmoid_cross_entropy(
              class_logits,
              label,
              weights=cls_loss_weights,
              label_smoothing=self.config.get("label_smoothing"),
              alpha=self.config.get("focal_loss_alpha", 0.5),
              gamma=self.config.get("focal_loss_gamma", 2.0),
          )
      elif classification_loss_type == "sigmoid":
          classification_loss = (
              model_utils.weighted_sigmoid_cross_entropy(
                  class_logits,
                  label,
                  weights=cls_loss_weights,
                  label_smoothing=self.config.get("label_smoothing"),
              )
          )
      else:
          raise ValueError(
              f"Unknown loss type: {classification_loss_type}."
          )
      return classification_loss
  
imports: import functools
  from typing import Any, Dict, Mapping, Optional, Tuple, Union
  import immutabledict
  import jax.numpy
  import ml_collections
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import model_utils
  from scenic.projects.unloc import temporal_localization_base_model
label_desc: Use image node_id 3 for calling the MomentRetrievalModel obj's underlying member method code with example usage: obj._cls_loss(batch_mask, caption_mask, frame_mask, class_logits, label) and returns: classification_loss