class_docstr: Decoder module of Spectrogram prediction network.
  
  This is a module of decoder of Spectrogram prediction network in Singing Tacotron,
  which described in `https://arxiv.org/pdf/2202.07907v1.pdf`_.
  The decoder generates the sequence of
  features from the sequence of the hidden states.
  
  .. _`Singing-Tacotron: Global Duration Control Attention and Dynamic
  Filter for End-to-end Singing Voice Synthesis`:
     https://arxiv.org/pdf/2202.07907v1.pdf
docstr: Calculate forward propagation.
  
  Args:
      hs (Tensor): Batch of the sequences of padded hidden states (B, Tmax, idim).
      hlens (LongTensor): Batch of lengths of each input batch (B,).
      trans_token (Tensor): Global transition token for duration (B x Tmax x 1)
      ys (Tensor):
          Batch of the sequences of padded target features (B, Lmax, odim).
  
  Returns:
      Tensor: Batch of output tensors after postnet (B, Lmax, odim).
      Tensor: Batch of output tensors before postnet (B, Lmax, odim).
      Tensor: Batch of logits of stop prediction (B, Lmax).
      Tensor: Batch of attention weights (B, Lmax, Tmax).
  
  Note:
      This computation is performed in teacher-forcing manner.
code: def forward(self, hs, hlens, trans_token, ys):
      """Calculate forward propagation.
  
      Args:
          hs (Tensor): Batch of the sequences of padded hidden states (B, Tmax, idim).
          hlens (LongTensor): Batch of lengths of each input batch (B,).
          trans_token (Tensor): Global transition token for duration (B x Tmax x 1)
          ys (Tensor):
              Batch of the sequences of padded target features (B, Lmax, odim).
  
      Returns:
          Tensor: Batch of output tensors after postnet (B, Lmax, odim).
          Tensor: Batch of output tensors before postnet (B, Lmax, odim).
          Tensor: Batch of logits of stop prediction (B, Lmax).
          Tensor: Batch of attention weights (B, Lmax, Tmax).
  
      Note:
          This computation is performed in teacher-forcing manner.
  
      """
      # thin out frames (B, Lmax, odim) ->  (B, Lmax/r, odim)
      if self.reduction_factor > 1:
          ys = ys[:, self.reduction_factor - 1 :: self.reduction_factor]
  
      # length list should be list of int
      hlens = list(map(int, hlens))
  
      # initialize hidden states of decoder
      c_list = [self._zero_state(hs)]
      z_list = [self._zero_state(hs)]
      for _ in range(1, len(self.lstm)):
          c_list += [self._zero_state(hs)]
          z_list += [self._zero_state(hs)]
      prev_out = hs.new_zeros(hs.size(0), self.odim)
  
      # initialize attention
      prev_att_w = None
      self.att.reset()
  
      # loop for an output sequence
      outs, logits, att_ws = [], [], []
      for y in ys.transpose(0, 1):
          if trans_token is None:
              if self.use_att_extra_inputs:
                  att_c, att_w = self.att(
                      hs, hlens, z_list[0], prev_att_w, prev_out
                  )
              else:
                  att_c, att_w = self.att(
                      hs, hlens, z_list[0], prev_att_w
                  )
          else:  # GDCA
              att_c, att_w = self.att(
                  hs, hlens, trans_token, z_list[0], prev_att_w
              )
          prenet_out = (
              self.prenet(prev_out)
              if self.prenet is not None
              else prev_out
          )
          xs = torch.cat([att_c, prenet_out], dim=1)
          z_list[0], c_list[0] = self.lstm[0](
              xs, (z_list[0], c_list[0])
          )
          for i in range(1, len(self.lstm)):
              z_list[i], c_list[i] = self.lstm[i](
                  z_list[i - 1], (z_list[i], c_list[i])
              )
          zcs = (
              torch.cat([z_list[-1], att_c], dim=1)
              if self.use_concate
              else z_list[-1]
          )
          outs += [self.feat_out(zcs).view(hs.size(0), self.odim, -1)]
          logits += [self.prob_out(zcs)]
          att_ws += [att_w]
          prev_out = y  # teacher forcing
          if self.cumulate_att_w and prev_att_w is not None:
              prev_att_w = prev_att_w + att_w  # Note: error when use +=
          else:
              prev_att_w = att_w
  
      logits = torch.cat(logits, dim=1)  # (B, Lmax)
      before_outs = torch.cat(outs, dim=2)  # (B, odim, Lmax)
      att_ws = torch.stack(att_ws, dim=1)  # (B, Lmax, Tmax)
  
      if self.reduction_factor > 1:
          before_outs = before_outs.view(
              before_outs.size(0), self.odim, -1
          )  # (B, odim, Lmax)
  
      if self.postnet is not None:
          after_outs = before_outs + self.postnet(
              before_outs
          )  # (B, odim, Lmax)
      else:
          after_outs = before_outs
      before_outs = before_outs.transpose(2, 1)  # (B, Lmax, odim)
      after_outs = after_outs.transpose(2, 1)  # (B, Lmax, odim)
      logits = logits
  
      # apply activation function for scaling
      if self.output_activation_fn is not None:
          before_outs = self.output_activation_fn(before_outs)
          after_outs = self.output_activation_fn(after_outs)
  
      return after_outs, before_outs, logits, att_ws
  
file_path: espnet/espnet2/svs/singing_tacotron/decoder.py
imports: import six
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.rnn.attentions import AttForwardTA
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet, Prenet, ZoneOutCell
label_desc: Use image node_id 3 for calling the Decoder obj's underlying member method code with example usage: obj.forward(hs, hlens, trans_token, ys) and returns: after_outs,  before_outs,  logits,  att_ws