class_docstr: Pure Python implementation of TDT loss (https://arxiv.org/pdf/2304.06795.pdf)
class_docstr_tok: ["Pure","Python","implementation","of","TDT","loss","(","https",":","\/\/arxiv.org\/pdf\/2304.06795.pdf",")"]
code: def forward(self, acts, labels, act_lens, label_lens):
      label_acts = acts[:, :, :, : -self.n_durations]
      duration_acts = acts[:, :, :, -self.n_durations :]
  
      # the - self.sigma here is for logit-undernormalization. Check the paper for details.
      label_acts = torch.log_softmax(label_acts, -1) - self.sigma
  
      duration_acts = torch.log_softmax(duration_acts, -1)
  
      forward_logprob, _ = self.compute_forward_prob(
          label_acts, duration_acts, labels, act_lens, label_lens
      )
      losses = -forward_logprob
      if self.reduction == "mean_batch":
          losses = losses.mean()  # global batch size average
      elif self.reduction == "mean":
          losses = torch.div(losses, label_lens).mean()
      elif self.reduction == "sum":
          losses = losses.sum()
      elif self.reduction == "mean_volume":
          losses = (
              losses.sum() / label_lens.sum()
          )  # same as above but longer samples weigh more
  
      return losses
  
imports: from typing import List
  import torch
  from nemo.core.classes import Loss
  from nemo.core.neural_types import LabelsType, LengthsType, LogprobsType, LossType, NeuralType
label_desc: Use image node_id 4 for calling the TDTLossPytorch obj's underlying member method code with example usage: obj.forward(acts, labels, act_lens, label_lens) and returns: losses