class_docstr: Joint loss over labels and length of sequences for non-autoregressive modeling.
docstr: label_logits: (B x T) x V_1
  label_targets: (B x T)
  length_logits: B x V_2
  length_targets: B
docstr_tok: ["label_logits",":","(","B","x","T",")","x","V_1","label_targets",":","(","B","x","T",")","length_logits",":","B","x","V_2","length_targets",":","B"]
code: def __call__(
      self,
      label_logits,
      label_targets,
      length_logits,
      length_targets,
      reduce=True,
  ):
      """
      label_logits: (B x T) x V_1
      label_targets: (B x T)
      length_logits: B x V_2
      length_targets: B
      """
  
      label_logits = maybe_log_normalize(
          logits=label_logits, logits_type=self.label_type, dim=-1
      )
      length_logits = maybe_log_normalize(
          logits=length_logits, logits_type=self.length_type, dim=-1
      )
  
      max_supported_dim = length_logits.size(1)
      length_targets = length_targets.unsqueeze(-1)  # (B x T) x 1
  
      if self.assert_valid_targets:
          if torch.any(length_targets >= max_supported_dim):
              total_violations = str(
                  length_targets[length_targets >= max_supported_dim]
                  .flatten()
                  .tolist()
              )
              raise RuntimeError(
                  f"max_supported_dim: {max_supported_dim}, "
                  f"total violations: {total_violations}"
              )
      else:
          length_targets[length_targets >= max_supported_dim] = (
              max_supported_dim - 1
          )
  
      label_loss = self.label_loss_fn(
          label_logits, label_targets, reduce
      )
      length_loss = self.length_loss_fn(
          length_logits, length_targets.squeeze(-1), reduce
      )
  
      if self.disable_label_loss:
          # disable the label loss and only optimize length
          # loss
          label_loss = label_loss * 0
  
      loss = label_loss + self.beta * length_loss
  
      return (
          loss,
          {
              "label_loss": label_loss,
              "length_loss": length_loss,
              "label_label_loss": self.label_loss_fn.label_loss,
              "label_smoothing_loss": self.label_loss_fn.smoothing_loss,
              "length_label_loss": self.length_loss_fn.label_loss,
              "length_smoothing_loss": self.length_loss_fn.smoothing_loss,
          },
      )
  
imports: from typing import Union
  import torch
  from pytext.config import ConfigBase
  from pytext.config.component import create_loss
  from .loss import HingeLoss, Loss, maybe_log_normalize, NLLLoss, SourceType
  from .regularizer import AdaptiveRegularizer, EntropyRegularizer, UniformRegularizer
  from .structured_loss import StructuredLoss, StructuredMarginLoss
label_desc: Use image node_id 2 for calling the NARSequenceLoss obj's underlying member method code with example usage: obj.__call__(label_logits, label_targets, length_logits, length_targets, reduce) and returns: loss,  dict