class_docstr: Video Transformer model for multi-class classification.
class_docstr_tok: ["Video","Transformer","model","for","multi-class","classification","."]
docstr: Returns sigmoid cross entropy loss with an L2 penalty on the weights.
  
  Args:
    logits: Output of model in shape [batch, length, num_classes]. Optionally,
      this can also be a dictionary with logits for individual modalities.
    batch: Batch of data that has 'label' and optionally 'batch_mask'.
    model_params: Parameters of the model, for optionally applying
      regularization.
  
  Returns:
    Total loss.
docstr_tok: ["Returns","sigmoid","cross","entropy","loss","with","an","L2","penalty","on","the","weights",".","Args",":","logits",":","Output","of","model","in","shape","[","batch",",","length",",","num_classes","]",".","Optionally",",","this","can","also","be","a","dictionary","with","logits","for","individual","modalities",".","batch",":","Batch","of","data","that","has","'label","'","and","optionally","'batch_mask","'",".","model_params",":","Parameters","of","the","model",",","for","optionally","applying","regularization",".","Returns",":","Total","loss","."]
code: def loss_function(
      self,
      logits: jnp.ndarray,
      batch: base_model.Batch,
      model_params: Optional[jnp.ndarray] = None,
  ) -> float:
      """Returns sigmoid cross entropy loss with an L2 penalty on the weights.
  
      Args:
        logits: Output of model in shape [batch, length, num_classes]. Optionally,
          this can also be a dictionary with logits for individual modalities.
        batch: Batch of data that has 'label' and optionally 'batch_mask'.
        model_params: Parameters of the model, for optionally applying
          regularization.
  
      Returns:
        Total loss.
      """
      weights = batch.get("batch_mask")
      labels = batch["label"]
  
      assert self.dataset_meta_data.get("target_is_onehot", False)
  
      label_weights = self.dataset_meta_data.get("class_weights", None)
  
      if isinstance(logits, dict):
          sig_ce_loss = []
          for modality in logits:
              sig_ce_loss.append(
                  base_model_utils.weighted_sigmoid_cross_entropy(
                      logits[modality],
                      labels[modality],
                      weights,
                      label_weights=label_weights,
                      label_smoothing=self.config.get(
                          "label_smoothing"
                      ),
                  )
              )
          sig_ce_loss = jnp.mean(jnp.array(sig_ce_loss))
      else:
          if isinstance(labels, dict):
              assert "all" in labels, "mixmod must be turned off."
              labels = labels["all"]
          sig_ce_loss = base_model_utils.weighted_sigmoid_cross_entropy(
              logits,
              labels,
              weights,
              label_weights=label_weights,
              label_smoothing=self.config.get("label_smoothing"),
          )
      if self.config.get("l2_decay_factor") is None:
          total_loss = sig_ce_loss
      else:
          l2_loss = base_model_utils.l2_regularization(model_params)
          total_loss = (
              sig_ce_loss + 0.5 * self.config.l2_decay_factor * l2_loss
          )
      return total_loss
  
imports: import functools
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple
  from absl import logging
  import flax.linen
  from flax.linen.linear import default_kernel_init
  from immutabledict import immutabledict
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import classification_model
  from scenic.model_lib.base_models import model_utils
  from scenic.model_lib.base_models.classification_model import ClassificationModel
  from scenic.model_lib.layers import attention_layers
  from scenic.model_lib.layers import nn_layers
  from scenic.projects.baselines import vit
  from scenic.projects.mbt import model_utils
label_desc: Use image node_id 3 for calling the MBTMultilabelClassificationModel obj's underlying member method code with example usage: obj.loss_function(logits, batch, model_params) and returns: total_loss