class_docstr: singing_Tacotron module for end-to-end singing-voice-synthesis.
  
  This is a module of Spectrogram prediction network in Singing Tacotron
  described in `Singing-Tacotron: Global Duration Control Attention and
  Dynamic Filter for End-to-end Singing Voice Synthesis`_,
  which learn accurate alignment information automatically.
  
  .. _`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:
      text (LongTensor): Input sequence of characters (T_text,).
      feats (Optional[Tensor]): Feature sequence to extract style (N, idim).
      label (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded label ids (Tmax).
      melody (Optional[Dict]): key is "lab" or "score";
          value (LongTensor): Batch of padded melody (Tmax).
      pitch (FloatTensor): Batch of padded f0 (Tmax).
      duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
          value (LongTensor): Batch of padded duration (Tmax).
      slur (LongTensor): Batch of padded slur (B, Tmax).
      spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
      sids (Optional[Tensor]): Speaker ID (1,).
      lids (Optional[Tensor]): Language ID (1,).
      threshold (float): Threshold in inference.
      minlenratio (float): Minimum length ratio in inference.
      maxlenratio (float): Maximum length ratio in inference.
      use_att_constraint (bool): Whether to apply attention constraint.
      use_dynamic_filter (bool): Whether to apply dynamic filter.
      backward_window (int): Backward window in attention constraint
          or dynamic filter.
      forward_window (int): Forward window in attention constraint
          or dynamic filter.
      use_teacher_forcing (bool): Whether to use teacher forcing.
  
  Returns:
      Dict[str, Tensor]: Output dict including the following items:
          * feat_gen (Tensor): Output sequence of features (T_feats, odim).
          * prob (Tensor): Output sequence of stop probabilities (T_feats,).
          * att_w (Tensor): Attention weights (T_feats, T).
docstr_tok: ["Generate","the","sequence","of","features","given","the","sequences","of","characters",".","Args",":","text","(","LongTensor",")",":","Input","sequence","of","characters","(","T_text",",",")",".","feats","(","Optional","[","Tensor","]",")",":","Feature","sequence","to","extract","style","(","N",",","idim",")",".","label","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","label","ids","(","Tmax",")",".","melody","(","Optional","[","Dict","]",")",":","key","is","``","lab","''","or","``","score","''",";","value","(","LongTensor",")",":","Batch","of","padded","melody","(","Tmax",")",".","pitch","(","FloatTensor",")",":","Batch","of","padded","f0","(","Tmax",")",".","duration","(","Optional","[","Dict","]",")",":","key","is","``","lab","''",",","``","score_phn","''","or","``","score_syb","''",";","value","(","LongTensor",")",":","Batch","of","padded","duration","(","Tmax",")",".","slur","(","LongTensor",")",":","Batch","of","padded","slur","(","B",",","Tmax",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","(","spk_embed_dim",",",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","ID","(","1",",",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","ID","(","1",",",")",".","threshold","(","float",")",":","Threshold","in","inference",".","minlenratio","(","float",")",":","Minimum","length","ratio","in","inference",".","maxlenratio","(","float",")",":","Maximum","length","ratio","in","inference",".","use_att_constraint","(","bool",")",":","Whether","to","apply","attention","constraint",".","use_dynamic_filter","(","bool",")",":","Whether","to","apply","dynamic","filter",".","backward_window","(","int",")",":","Backward","window","in","attention","constraint","or","dynamic","filter",".","forward_window","(","int",")",":","Forward","window","in","attention","constraint","or","dynamic","filter",".","use_teacher_forcing","(","bool",")",":","Whether","to","use","teacher","forcing",".","Returns",":","Dict","[","str",",","Tensor","]",":","Output","dict","including","the","following","items",":","*","feat_gen","(","Tensor",")",":","Output","sequence","of","features","(","T_feats",",","odim",")",".","*","prob","(","Tensor",")",":","Output","sequence","of","stop","probabilities","(","T_feats",",",")",".","*","att_w","(","Tensor",")",":","Attention","weights","(","T_feats",",","T",")","."]
code: def inference(
      self,
      text: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      label: Optional[Dict[str, torch.Tensor]] = None,
      melody: Optional[Dict[str, torch.Tensor]] = None,
      duration: Optional[Dict[str, torch.Tensor]] = None,
      slur: Optional[Dict[str, torch.Tensor]] = None,
      pitch: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      threshold: float = 0.5,
      minlenratio: float = 0.0,
      maxlenratio: float = 30.0,
      use_att_constraint: bool = False,
      use_dynamic_filter: bool = False,
      backward_window: int = 1,
      forward_window: int = 3,
      use_teacher_forcing: bool = False,
  ) -> Dict[str, torch.Tensor]:
      """Generate the sequence of features given the sequences of characters.
  
      Args:
          text (LongTensor): Input sequence of characters (T_text,).
          feats (Optional[Tensor]): Feature sequence to extract style (N, idim).
          label (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded label ids (Tmax).
          melody (Optional[Dict]): key is "lab" or "score";
              value (LongTensor): Batch of padded melody (Tmax).
          pitch (FloatTensor): Batch of padded f0 (Tmax).
          duration (Optional[Dict]): key is "lab", "score_phn" or "score_syb";
              value (LongTensor): Batch of padded duration (Tmax).
          slur (LongTensor): Batch of padded slur (B, Tmax).
          spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
          sids (Optional[Tensor]): Speaker ID (1,).
          lids (Optional[Tensor]): Language ID (1,).
          threshold (float): Threshold in inference.
          minlenratio (float): Minimum length ratio in inference.
          maxlenratio (float): Maximum length ratio in inference.
          use_att_constraint (bool): Whether to apply attention constraint.
          use_dynamic_filter (bool): Whether to apply dynamic filter.
          backward_window (int): Backward window in attention constraint
              or dynamic filter.
          forward_window (int): Forward window in attention constraint
              or dynamic filter.
          use_teacher_forcing (bool): Whether to use teacher forcing.
  
      Returns:
          Dict[str, Tensor]: Output dict including the following items:
              * feat_gen (Tensor): Output sequence of features (T_feats, odim).
              * prob (Tensor): Output sequence of stop probabilities (T_feats,).
              * att_w (Tensor): Attention weights (T_feats, T).
  
      """
  
      label = label["score"]
      midi = melody["score"]
      duration = duration["lab"]
      y = feats
      spemb = spembs
  
      # add eos at the last of sequence
      label = F.pad(label, [0, 1], "constant", self.eos)
      midi = F.pad(midi, [0, 1], "constant", self.midi_eos)
      duration = F.pad(duration, [0, 1], "constant", self.duration_eos)
  
      # add sos at the last of sequence
      label = F.pad(label, [1, 0], "constant", self.eos)
      midi = F.pad(midi, [1, 0], "constant", self.midi_eos)
      duration = F.pad(duration, [1, 0], "constant", self.duration_eos)
  
      ilens = torch.tensor([label.size(1)])
  
      label_emb = self.phone_encode_layer(label)
      midi_emb = self.midi_encode_layer(midi)
      duration_emb = self.duration_encode_layer(duration)
      input_emb = label_emb + midi_emb + duration_emb
      con = label_emb + midi_emb
      dur = duration_emb
  
      # inference with teacher forcing
      if use_teacher_forcing:
          assert (
              feats is not None
          ), "feats must be provided with teacher forcing."
          spembs = None if spemb is None else spemb.unsqueeze(0)
          ys = y.unsqueeze(0)
          olens = torch.tensor([ys.size(1)])
          outs, _, _, att_ws = self._forward(
              xs=input_emb,
              con=con,
              dur=dur,
              ilens=ilens,
              ys=ys,
              olens=olens,
              spembs=spembs,
              sids=sids,
              lids=lids,
          )
  
          return dict(feat_gen=outs[0], att_w=att_ws[0])
  
      # inference
      if self.atype == "GDCA":
          h = self.enc.inference(con, ilens)  # h: (B, seq_len, emb_dim)
          trans_token = self.enc_duration.inference(
              dur
          )  # (B, seq_len, 1)
      else:
          h = self.enc.inference(
              con, ilens
          )  # hs: (B, seq_len, emb_dim)
          h_dur = self.dur_enc.inference(dur, ilens)
          h += h_dur
          trans_token = None
  
      if self.use_gst:
          style_emb = self.gst(y.unsqueeze(0))
          h = h + style_emb
      if self.spks is not None:
          sid_emb = self.sid_emb(sids.view(-1))
          h = h + sid_emb
      if self.langs is not None:
          lid_emb = self.lid_emb(lids.view(-1))
          h = h + lid_emb
      if self.spk_embed_dim is not None:
          hs, spembs = h.unsqueeze(0), spemb.unsqueeze(0)
          h = self._integrate_with_spk_embed(hs, spembs)[0]
  
      out, prob, att_w = self.dec.inference(
          h,
          trans_token,
          threshold=threshold,
          minlenratio=minlenratio,
          maxlenratio=maxlenratio,
          use_att_constraint=use_att_constraint,
          use_dynamic_filter=use_dynamic_filter,
          backward_window=backward_window,
          forward_window=forward_window,
      )
  
      return dict(feat_gen=out, prob=prob, att_w=att_w)
  
imports: import logging
  from typing import Dict, Optional, Sequence, Tuple
  import six
  import torch
  import torch.nn.functional
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from typeguard import check_argument_types
  from espnet2.svs.abs_svs import AbsSVS
  from espnet2.svs.singing_tacotron.decoder import Decoder
  from espnet2.svs.singing_tacotron.encoder import Duration_Encoder, Encoder
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import GuidedAttentionLoss, Tacotron2Loss
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.rnn.attentions import AttForward, AttForwardTA, AttLoc, GDCAttLoc
label_desc: Use image node_id 4 for calling the singing_tacotron obj's underlying member method code with example usage: obj.inference(text, feats, label, melody, duration, slur, pitch, spembs, sids, lids, threshold, minlenratio, maxlenratio, use_att_constraint, use_dynamic_filter, backward_window, forward_window, use_teacher_forcing) and returns: dict, dict