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: Generate the sequence of features given the sequences of characters.
  Args:
      h (Tensor): Input sequence of encoder hidden states (T, C).
      trans_token (Tensor): Global transition token for duration.
      threshold (float, optional): Threshold to stop generation.
      minlenratio (float, optional): Minimum length ratio.
          If set to 1.0 and the length of input is 10,
          the minimum length of outputs will be 10 * 1 = 10.
      minlenratio (float, optional): Minimum length ratio.
          If set to 10 and the length of input is 10,
          the maximum length of outputs will be 10 * 10 = 100.
      use_att_constraint (bool):
          Whether to apply attention constraint introduced in `Deep Voice 3`_.
      use_dynamic_filter (bool):
          Whether to apply dynamic filter introduced in `Singing Tacotron`_.
      backward_window (int): Backward window size in attention constraint.
      forward_window (int): Forward window size in attention constraint.
  Returns:
      Tensor: Output sequence of features (L, odim).
      Tensor: Output sequence of stop probabilities (L,).
      Tensor: Attention weights (L, T).
  Note:
      This computation is performed in auto-regressive manner.
  .. _`Deep Voice 3`: https://arxiv.org/abs/1710.07654
code: def inference(
      self,
      h,
      trans_token,
      threshold=0.5,
      minlenratio=0.0,
      maxlenratio=30.0,
      use_att_constraint=False,
      use_dynamic_filter=True,
      backward_window=1,
      forward_window=3,
  ):
      """Generate the sequence of features given the sequences of characters.
      Args:
          h (Tensor): Input sequence of encoder hidden states (T, C).
          trans_token (Tensor): Global transition token for duration.
          threshold (float, optional): Threshold to stop generation.
          minlenratio (float, optional): Minimum length ratio.
              If set to 1.0 and the length of input is 10,
              the minimum length of outputs will be 10 * 1 = 10.
          minlenratio (float, optional): Minimum length ratio.
              If set to 10 and the length of input is 10,
              the maximum length of outputs will be 10 * 10 = 100.
          use_att_constraint (bool):
              Whether to apply attention constraint introduced in `Deep Voice 3`_.
          use_dynamic_filter (bool):
              Whether to apply dynamic filter introduced in `Singing Tacotron`_.
          backward_window (int): Backward window size in attention constraint.
          forward_window (int): Forward window size in attention constraint.
      Returns:
          Tensor: Output sequence of features (L, odim).
          Tensor: Output sequence of stop probabilities (L,).
          Tensor: Attention weights (L, T).
      Note:
          This computation is performed in auto-regressive manner.
      .. _`Deep Voice 3`: https://arxiv.org/abs/1710.07654
      """
      # setup
      assert len(h.size()) == 2
      hs = h.unsqueeze(0)
      ilens = [h.size(0)]
      maxlen = int(h.size(0) * maxlenratio)
      minlen = int(h.size(0) * minlenratio)
  
      # 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(1, self.odim)
  
      # initialize attention
      prev_att_w = None
      self.att.reset()
  
      # setup for attention constraint
      if use_att_constraint or use_dynamic_filter:
          last_attended_idx = 0
      else:
          last_attended_idx = None
  
      # loop for an output sequence
      idx = 0
      outs, att_ws, probs = [], [], []
  
      while True:
          # updated index
          idx += self.reduction_factor
  
          # decoder calculation
          if self.use_att_extra_inputs:
              att_c, att_w = self.att(
                  hs,
                  ilens,
                  z_list[0],
                  prev_att_w,
                  prev_out,
                  last_attended_idx=last_attended_idx,
                  backward_window=backward_window,
                  forward_window=forward_window,
              )
          else:
              if trans_token is None:
                  att_c, att_w = self.att(
                      hs,
                      ilens,
                      z_list[0],
                      prev_att_w,
                      last_attended_idx=last_attended_idx,
                      backward_window=backward_window,
                      forward_window=forward_window,
                  )
              else:  # GDCA
                  att_c, att_w = self.att(
                      hs,
                      ilens,
                      trans_token,
                      z_list[0],
                      prev_att_w,
                      last_attended_idx=last_attended_idx,
                      backward_window=backward_window,
                      forward_window=forward_window,
                  )
  
          att_ws += [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(1, self.odim, -1)
          ]  # [(1, odim, r), ...]
          probs += [torch.sigmoid(self.prob_out(zcs))[0]]  # [(r), ...]
          if self.output_activation_fn is not None:
              prev_out = self.output_activation_fn(
                  outs[-1][:, :, -1]
              )  # (1, odim)
          else:
              prev_out = outs[-1][:, :, -1]  # (1, odim)
          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
          if use_att_constraint or use_dynamic_filter:
              last_attended_idx = int(att_w.argmax())
  
          # check whether to finish generation
          if int(sum(probs[-1] >= threshold)) > 0 or idx >= maxlen:
              # check mininum length
              if idx < minlen:
                  continue
              outs = torch.cat(outs, dim=2)  # (1, odim, L)
              if self.postnet is not None:
                  outs = outs + self.postnet(outs)  # (1, odim, L)
              outs = outs.transpose(2, 1).squeeze(0)  # (L, odim)
              probs = torch.cat(probs, dim=0)
              att_ws = torch.cat(att_ws, dim=0)
              break
  
      if self.output_activation_fn is not None:
          outs = self.output_activation_fn(outs)
  
      return outs, probs, 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 4 for calling the Decoder obj's underlying member method code with example usage: obj.inference(h, trans_token, threshold, minlenratio, maxlenratio, use_att_constraint, use_dynamic_filter, backward_window, forward_window) and returns: outs,  probs,  att_ws