class_docstr: TopologicalViT model for classification task.
class_docstr_tok: ["TopologicalViT","model","for","classification","task","."]
docstr: Returns softmax cross entropy loss with an L2 penalty on the weights.
  
  The function overwrites/modifies loss_function of ClassificationModel.
  Args:
    logits: Output of model in shape [batch, length, num_classes].
    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","softmax","cross","entropy","loss","with","an","L2","penalty","on","the","weights",".","The","function","overwrites\/modifies","loss_function","of","ClassificationModel",".","Args",":","logits",":","Output","of","model","in","shape","[","batch",",","length",",","num_classes","]",".","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 softmax cross entropy loss with an L2 penalty on the weights.
  
      The function overwrites/modifies loss_function of ClassificationModel.
      Args:
        logits: Output of model in shape [batch, length, num_classes].
        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")
  
      if self.dataset_meta_data.get("target_is_onehot", False):
          one_hot_targets = batch["label"]
      else:
          one_hot_targets = common_utils.onehot(
              batch["label"], logits.shape[-1]
          )
      if self.config.get("class_balancing"):
          sof_ce_loss = model_utils.weighted_softmax_cross_entropy(
              logits,
              one_hot_targets,
              weights,
              label_weights=self.get_label_weights(),
              label_smoothing=self.config.get("label_smoothing"),
          )
      else:
          sof_ce_loss = model_utils.weighted_softmax_cross_entropy(
              logits,
              one_hot_targets,
              weights,
              label_smoothing=self.config.get("label_smoothing"),
          )
      if self.config.get("l2_decay_factor") is None:
          total_loss = sof_ce_loss
      else:
          l2_loss = model_utils.l2_regularization(model_params)
          total_loss = (
              sof_ce_loss + 0.5 * self.config.l2_decay_factor * l2_loss
          )
      return total_loss
  
file_path: scenic/scenic/projects/tasseo/vit.py
imports: from typing import Optional
  from flax.training import common_utils
  import jax.numpy
  import numpy
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import model_utils
  from scenic.model_lib.base_models.classification_model import ClassificationModel
  from scenic.projects.baselines import vit
  from topological_transformer.images import topvit
label_desc: Use image node_id 3 for calling the TopologicalViTClassificationModel obj's underlying member method code with example usage: obj.loss_function(logits, batch, model_params) and returns: total_loss