class_docstr: Dense video captioning model with a video encoder and a text decoder.
docstr: Returns negative loglikelihood (NLL) of the target sentence with an L2 penalty on the weights.
  
  Args:
    logits: Output of model in shape [batch, length, num_voca].
    batch: Batch of data that has 'decoder_target_tokens'.
    model_params: Parameters of the model, for optionally applying
      regularization.
  
  Returns:
    Total loss.
docstr_tok: ["Returns","negative","loglikelihood","(","NLL",")","of","the","target","sentence","with","an","L2","penalty","on","the","weights",".","Args",":","logits",":","Output","of","model","in","shape","[","batch",",","length",",","num_voca","]",".","batch",":","Batch","of","data","that","has","'decoder_target_tokens","'",".","model_params",":","Parameters","of","the","model",",","for","optionally","applying","regularization",".","Returns",":","Total","loss","."]
code: def loss_function(  # pytype: disable=signature-mismatch  # jax-ndarray
      self,
      logits: jnp.ndarray,
      batch: Batch,
      model_params: Optional[Dict[str, jnp.ndarray]] = None,
  ) -> float:
      """Returns negative loglikelihood (NLL) of the target sentence with an L2 penalty on the weights.
  
      Args:
        logits: Output of model in shape [batch, length, num_voca].
        batch: Batch of data that has 'decoder_target_tokens'.
        model_params: Parameters of the model, for optionally applying
          regularization.
  
      Returns:
        Total loss.
      """
      targets = batch["decoder_inputs"]["decoder_target_tokens"]
  
      if logits.ndim != targets.ndim + 1:
          raise ValueError(
              "Incorrect shapes. Got shape %s logits and %s targets"
              % (str(logits.shape), str(targets.shape))
          )
  
      target_masks = targets > 0
      vocab_size = logits.shape[-1]
      onehot_targets = common_utils.onehot(targets, vocab_size)
  
      sent_nll_loss = base_model_utils.weighted_softmax_cross_entropy(
          logits,
          onehot_targets,
          target_masks,
          label_smoothing=self.config.get("label_smoothing"),
      )
  
      if self.config.get("l2_decay_factor") is None:
          total_loss = sent_nll_loss
      else:
          l2_loss = base_model_utils.l2_regularization(model_params)
          total_loss = (
              sent_nll_loss + self.config.l2_decay_factor * l2_loss
          )
  
      return total_loss
  
imports: import functools
  from typing import Any, Dict, Mapping, Optional, Tuple
  from absl import logging
  import flax.linen
  from flax.training import common_utils
  import jax
  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.baselines import vit
  from scenic.projects.t5 import layers
  from scenic.projects.t5 import model
  from t5x import decoding
  from t5x.models import DecodeFnCallable
label_desc: Use image node_id 2 for calling the DenseVideoCaptioningModel obj's underlying member method code with example usage: obj.loss_function(logits, batch, model_params) and returns: total_loss