class_docstr: Forwardsum loss described at https://openreview.net/forum?id=0NQwnnwAORi
class_docstr_tok: ["Forwardsum","loss","described","at","https",":","\/\/openreview.net\/forum","?","id=0NQwnnwAORi"]
docstr: Calculate forward propagation.
  
  Args:
      log_p_attn (Tensor): Batch of log probability of attention matrix
          (B, T_feats, T_text).
      ilens (Tensor): Batch of the lengths of each input (B,).
      olens (Tensor): Batch of the lengths of each target (B,).
      blank_prob (float): Blank symbol probability.
  
  Returns:
      Tensor: forwardsum loss value.
docstr_tok: ["Calculate","forward","propagation",".","Args",":","log_p_attn","(","Tensor",")",":","Batch","of","log","probability","of","attention","matrix","(","B",",","T_feats",",","T_text",")",".","ilens","(","Tensor",")",":","Batch","of","the","lengths","of","each","input","(","B",",",")",".","olens","(","Tensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","blank_prob","(","float",")",":","Blank","symbol","probability",".","Returns",":","Tensor",":","forwardsum","loss","value","."]
code: def forward(
      self,
      log_p_attn: torch.Tensor,
      ilens: torch.Tensor,
      olens: torch.Tensor,
      blank_prob: float = np.e**-1,
  ) -> torch.Tensor:
      """Calculate forward propagation.
  
      Args:
          log_p_attn (Tensor): Batch of log probability of attention matrix
              (B, T_feats, T_text).
          ilens (Tensor): Batch of the lengths of each input (B,).
          olens (Tensor): Batch of the lengths of each target (B,).
          blank_prob (float): Blank symbol probability.
  
      Returns:
          Tensor: forwardsum loss value.
  
      """
      B = log_p_attn.size(0)
  
      # a row must be added to the attention matrix to account for
      #    blank token of CTC loss
      # (B,T_feats,T_text+1)
      log_p_attn_pd = F.pad(
          log_p_attn, (1, 0, 0, 0, 0, 0), value=np.log(blank_prob)
      )
  
      loss = 0
      for bidx in range(B):
          # construct target sequnece.
          # Every text token is mapped to a unique sequnece number.
          target_seq = torch.arange(1, ilens[bidx] + 1).unsqueeze(0)
          cur_log_p_attn_pd = log_p_attn_pd[
              bidx, : olens[bidx], : ilens[bidx] + 1
          ].unsqueeze(
              1
          )  # (T_feats,1,T_text+1)
          cur_log_p_attn_pd = F.log_softmax(cur_log_p_attn_pd, dim=-1)
          loss += F.ctc_loss(
              log_probs=cur_log_p_attn_pd,
              targets=target_seq,
              input_lengths=olens[bidx : bidx + 1],
              target_lengths=ilens[bidx : bidx + 1],
              zero_infinity=True,
          )
      loss = loss / B
      return loss
  
file_path: espnet/espnet2/gan_tts/jets/loss.py
imports: from typing import Tuple
  import numpy
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictorLoss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
label_desc: Use image node_id 2 for calling the ForwardSumLoss obj's underlying member method code with example usage: obj.forward(log_p_attn, ilens, olens, blank_prob) and returns: loss