class_docstr: NaiveRNNDP-SVS module.
  
  This is an implementation of naive RNN with duration prediction
  for singing voice synthesis
  The features are processed directly over time-domain from music score and
  predict the singing voice features
class_docstr_tok: ["NaiveRNNDP-SVS","module",".","This","is","an","implementation","of","naive","RNN","with","duration","prediction","for","singing","voice","synthesis","The","features","are","processed","directly","over","time-domain","from","music","score","and","predict","the","singing","voice","features"]
docstr: Initialize NaiveRNNDP module.
  
  Args:
      idim (int): Dimension of the label inputs.
      odim (int): Dimension of the outputs.
      midi_dim (int): Dimension of the midi inputs.
      embed_dim (int): Dimension of the token embedding.
      eprenet_conv_layers (int): Number of prenet conv layers.
      eprenet_conv_filts (int): Number of prenet conv filter size.
      eprenet_conv_chans (int): Number of prenet conv filter channels.
      elayers (int): Number of encoder layers.
      eunits (int): Number of encoder hidden units.
      ebidirectional (bool): If bidirectional in encoder.
      midi_embed_integration_type (str): how to integrate midi information,
          ("add" or "cat").
      dlayers (int): Number of decoder lstm layers.
      dunits (int): Number of decoder lstm units.
      dbidirectional (bool): if bidirectional in decoder.
      postnet_layers (int): Number of postnet layers.
      postnet_filts (int): Number of postnet filter size.
      postnet_chans (int): Number of postnet filter channels.
      use_batch_norm (bool): Whether to use batch normalization.
      reduction_factor (int): Reduction factor.
      duration_predictor_layers (int): Number of duration predictor layers.
      duration_predictor_chans (int): Number of duration predictor channels.
      duration_predictor_kernel_size (int): Kernel size of duration predictor.
      duration_predictor_dropout_rate (float): Dropout rate in duration predictor.
      # extra embedding related
      spks (Optional[int]): Number of speakers. If set to > 1, assume that the
          sids will be provided as the input and use sid embedding layer.
      langs (Optional[int]): Number of languages. If set to > 1, assume that the
          lids will be provided as the input and use sid embedding layer.
      spk_embed_dim (Optional[int]): Speaker embedding dimension. If set to > 0,
          assume that spembs will be provided as the input.
      spk_embed_integration_type (str): How to integrate speaker embedding.
      eprenet_dropout_rate (float): Prenet dropout rate.
      edropout_rate (float): Encoder dropout rate.
      ddropout_rate (float): Decoder dropout rate.
      postnet_dropout_rate (float): Postnet dropout_rate.
      init_type (str): How to initialize transformer parameters.
      use_masking (bool): Whether to mask padded part in loss calculation.
      use_weighted_masking (bool): Whether to apply weighted masking in
          loss calculation.
docstr_tok: ["Initialize","NaiveRNNDP","module",".","Args",":","idim","(","int",")",":","Dimension","of","the","label","inputs",".","odim","(","int",")",":","Dimension","of","the","outputs",".","midi_dim","(","int",")",":","Dimension","of","the","midi","inputs",".","embed_dim","(","int",")",":","Dimension","of","the","token","embedding",".","eprenet_conv_layers","(","int",")",":","Number","of","prenet","conv","layers",".","eprenet_conv_filts","(","int",")",":","Number","of","prenet","conv","filter","size",".","eprenet_conv_chans","(","int",")",":","Number","of","prenet","conv","filter","channels",".","elayers","(","int",")",":","Number","of","encoder","layers",".","eunits","(","int",")",":","Number","of","encoder","hidden","units",".","ebidirectional","(","bool",")",":","If","bidirectional","in","encoder",".","midi_embed_integration_type","(","str",")",":","how","to","integrate","midi","information",",","(","``","add","''","or","``","cat","''",")",".","dlayers","(","int",")",":","Number","of","decoder","lstm","layers",".","dunits","(","int",")",":","Number","of","decoder","lstm","units",".","dbidirectional","(","bool",")",":","if","bidirectional","in","decoder",".","postnet_layers","(","int",")",":","Number","of","postnet","layers",".","postnet_filts","(","int",")",":","Number","of","postnet","filter","size",".","postnet_chans","(","int",")",":","Number","of","postnet","filter","channels",".","use_batch_norm","(","bool",")",":","Whether","to","use","batch","normalization",".","reduction_factor","(","int",")",":","Reduction","factor",".","duration_predictor_layers","(","int",")",":","Number","of","duration","predictor","layers",".","duration_predictor_chans","(","int",")",":","Number","of","duration","predictor","channels",".","duration_predictor_kernel_size","(","int",")",":","Kernel","size","of","duration","predictor",".","duration_predictor_dropout_rate","(","float",")",":","Dropout","rate","in","duration","predictor",".","#","extra","embedding","related","spks","(","Optional","[","int","]",")",":","Number","of","speakers",".","If","set","to",">","1",",","assume","that","the","sids","will","be","provided","as","the","input","and","use","sid","embedding","layer",".","langs","(","Optional","[","int","]",")",":","Number","of","languages",".","If","set","to",">","1",",","assume","that","the","lids","will","be","provided","as","the","input","and","use","sid","embedding","layer",".","spk_embed_dim","(","Optional","[","int","]",")",":","Speaker","embedding","dimension",".","If","set","to",">","0",",","assume","that","spembs","will","be","provided","as","the","input",".","spk_embed_integration_type","(","str",")",":","How","to","integrate","speaker","embedding",".","eprenet_dropout_rate","(","float",")",":","Prenet","dropout","rate",".","edropout_rate","(","float",")",":","Encoder","dropout","rate",".","ddropout_rate","(","float",")",":","Decoder","dropout","rate",".","postnet_dropout_rate","(","float",")",":","Postnet","dropout_rate",".","init_type","(","str",")",":","How","to","initialize","transformer","parameters",".","use_masking","(","bool",")",":","Whether","to","mask","padded","part","in","loss","calculation",".","use_weighted_masking","(","bool",")",":","Whether","to","apply","weighted","masking","in","loss","calculation","."]
code: def __init__(
      self,
      # network structure related
      idim: int,
      odim: int,
      midi_dim: int = 129,
      embed_dim: int = 512,
      duration_dim: int = 500,
      eprenet_conv_layers: int = 3,
      eprenet_conv_chans: int = 256,
      eprenet_conv_filts: int = 5,
      elayers: int = 3,
      eunits: int = 1024,
      ebidirectional: bool = True,
      midi_embed_integration_type: str = "add",
      dlayers: int = 3,
      dunits: int = 1024,
      dbidirectional: bool = True,
      postnet_layers: int = 5,
      postnet_chans: int = 256,
      postnet_filts: int = 5,
      use_batch_norm: bool = True,
      duration_predictor_layers: int = 2,
      duration_predictor_chans: int = 384,
      duration_predictor_kernel_size: int = 3,
      duration_predictor_dropout_rate: float = 0.1,
      reduction_factor: int = 1,
      # extra embedding related
      spks: Optional[int] = None,
      langs: Optional[int] = None,
      spk_embed_dim: Optional[int] = None,
      spk_embed_integration_type: str = "add",
      eprenet_dropout_rate: float = 0.5,
      edropout_rate: float = 0.1,
      ddropout_rate: float = 0.1,
      postnet_dropout_rate: float = 0.5,
      init_type: str = "xavier_uniform",
      use_masking: bool = False,
      use_weighted_masking: bool = False,
  ):
      """Initialize NaiveRNNDP module.
  
      Args:
          idim (int): Dimension of the label inputs.
          odim (int): Dimension of the outputs.
          midi_dim (int): Dimension of the midi inputs.
          embed_dim (int): Dimension of the token embedding.
          eprenet_conv_layers (int): Number of prenet conv layers.
          eprenet_conv_filts (int): Number of prenet conv filter size.
          eprenet_conv_chans (int): Number of prenet conv filter channels.
          elayers (int): Number of encoder layers.
          eunits (int): Number of encoder hidden units.
          ebidirectional (bool): If bidirectional in encoder.
          midi_embed_integration_type (str): how to integrate midi information,
              ("add" or "cat").
          dlayers (int): Number of decoder lstm layers.
          dunits (int): Number of decoder lstm units.
          dbidirectional (bool): if bidirectional in decoder.
          postnet_layers (int): Number of postnet layers.
          postnet_filts (int): Number of postnet filter size.
          postnet_chans (int): Number of postnet filter channels.
          use_batch_norm (bool): Whether to use batch normalization.
          reduction_factor (int): Reduction factor.
          duration_predictor_layers (int): Number of duration predictor layers.
          duration_predictor_chans (int): Number of duration predictor channels.
          duration_predictor_kernel_size (int): Kernel size of duration predictor.
          duration_predictor_dropout_rate (float): Dropout rate in duration predictor.
          # extra embedding related
          spks (Optional[int]): Number of speakers. If set to > 1, assume that the
              sids will be provided as the input and use sid embedding layer.
          langs (Optional[int]): Number of languages. If set to > 1, assume that the
              lids will be provided as the input and use sid embedding layer.
          spk_embed_dim (Optional[int]): Speaker embedding dimension. If set to > 0,
              assume that spembs will be provided as the input.
          spk_embed_integration_type (str): How to integrate speaker embedding.
          eprenet_dropout_rate (float): Prenet dropout rate.
          edropout_rate (float): Encoder dropout rate.
          ddropout_rate (float): Decoder dropout rate.
          postnet_dropout_rate (float): Postnet dropout_rate.
          init_type (str): How to initialize transformer parameters.
          use_masking (bool): Whether to mask padded part in loss calculation.
          use_weighted_masking (bool): Whether to apply weighted masking in
              loss calculation.
  
      """
      assert check_argument_types()
      super().__init__()
  
      # store hyperparameters
      self.idim = idim
      self.midi_dim = midi_dim
      self.duration_dim = duration_dim
      self.eunits = eunits
      self.odim = odim
      self.eos = idim - 1
      self.reduction_factor = reduction_factor
  
      self.midi_embed_integration_type = midi_embed_integration_type
  
      # use idx 0 as padding idx
      self.padding_idx = 0
  
      # define transformer encoder
      if eprenet_conv_layers != 0:
          # encoder prenet
          self.encoder_input_layer = torch.nn.Sequential(
              EncoderPrenet(
                  idim=idim,
                  embed_dim=embed_dim,
                  elayers=0,
                  econv_layers=eprenet_conv_layers,
                  econv_chans=eprenet_conv_chans,
                  econv_filts=eprenet_conv_filts,
                  use_batch_norm=use_batch_norm,
                  dropout_rate=eprenet_dropout_rate,
                  padding_idx=self.padding_idx,
              ),
              torch.nn.Linear(eprenet_conv_chans, eunits),
          )
          self.midi_encoder_input_layer = torch.nn.Sequential(
              EncoderPrenet(
                  idim=midi_dim,
                  embed_dim=embed_dim,
                  elayers=0,
                  econv_layers=eprenet_conv_layers,
                  econv_chans=eprenet_conv_chans,
                  econv_filts=eprenet_conv_filts,
                  use_batch_norm=use_batch_norm,
                  dropout_rate=eprenet_dropout_rate,
                  padding_idx=self.padding_idx,
              ),
              torch.nn.Linear(eprenet_conv_chans, eunits),
          )
          self.duration_encoder_input_layer = torch.nn.Sequential(
              EncoderPrenet(
                  idim=midi_dim,
                  embed_dim=embed_dim,
                  elayers=0,
                  econv_layers=eprenet_conv_layers,
                  econv_chans=eprenet_conv_chans,
                  econv_filts=eprenet_conv_filts,
                  use_batch_norm=use_batch_norm,
                  dropout_rate=eprenet_dropout_rate,
                  padding_idx=self.padding_idx,
              ),
              torch.nn.Linear(eprenet_conv_chans, eunits),
          )
      else:
          self.encoder_input_layer = torch.nn.Embedding(
              num_embeddings=idim,
              embedding_dim=eunits,
              padding_idx=self.padding_idx,
          )
          self.midi_encoder_input_layer = torch.nn.Embedding(
              num_embeddings=midi_dim,
              embedding_dim=eunits,
              padding_idx=self.padding_idx,
          )
          self.duration_encoder_input_layer = torch.nn.Embedding(
              num_embeddings=duration_dim,
              embedding_dim=eunits,
              padding_idx=self.padding_idx,
          )
  
      self.encoder = torch.nn.LSTM(
          input_size=eunits,
          hidden_size=eunits,
          num_layers=elayers,
          batch_first=True,
          dropout=edropout_rate,
          bidirectional=ebidirectional,
          # proj_size=eunits,
      )
  
      self.midi_encoder = torch.nn.LSTM(
          input_size=eunits,
          hidden_size=eunits,
          num_layers=elayers,
          batch_first=True,
          dropout=edropout_rate,
          bidirectional=ebidirectional,
          # proj_size=eunits,
      )
  
      self.duration_encoder = torch.nn.LSTM(
          input_size=eunits,
          hidden_size=eunits,
          num_layers=elayers,
          batch_first=True,
          dropout=edropout_rate,
          bidirectional=ebidirectional,
          # proj_size=eunits,
      )
  
      dim_direction = 2 if ebidirectional is True else 1
      if self.midi_embed_integration_type == "add":
          self.midi_projection = torch.nn.Linear(
              eunits * dim_direction, eunits * dim_direction
          )
      else:
          self.midi_projection = torch.nn.Linear(
              3 * eunits * dim_direction, eunits * dim_direction
          )
  
      # define duration predictor
      self.duration_predictor = DurationPredictor(
          idim=eunits * dim_direction,
          n_layers=duration_predictor_layers,
          n_chans=duration_predictor_chans,
          kernel_size=duration_predictor_kernel_size,
          dropout_rate=duration_predictor_dropout_rate,
      )
  
      # define length regulator
      self.length_regulator = LengthRegulator()
  
      self.decoder = torch.nn.LSTM(
          input_size=eunits * dim_direction,
          hidden_size=dunits,
          num_layers=dlayers,
          batch_first=True,
          dropout=ddropout_rate,
          bidirectional=dbidirectional,
          # proj_size=dunits,
      )
  
      # define spk and lang embedding
      self.spks = None
      if spks is not None and spks > 1:
          self.spks = spks
          self.sid_emb = torch.nn.Embedding(
              spks, dunits * dim_direction
          )
      self.langs = None
      if langs is not None and langs > 1:
          # TODO(Yuning): not encode yet
          self.langs = langs
          self.lid_emb = torch.nn.Embedding(
              langs, dunits * dim_direction
          )
  
      # define projection layer
      self.spk_embed_dim = None
      if spk_embed_dim is not None and spk_embed_dim > 0:
          self.spk_embed_dim = spk_embed_dim
          self.spk_embed_integration_type = spk_embed_integration_type
      if self.spk_embed_dim is not None:
          if self.spk_embed_integration_type == "add":
              self.projection = torch.nn.Linear(
                  self.spk_embed_dim, dunits * dim_direction
              )
          else:
              self.projection = torch.nn.Linear(
                  dunits * dim_direction + self.spk_embed_dim,
                  dunits * dim_direction,
              )
  
      # define final projection
      self.feat_out = torch.nn.Linear(
          dunits * dim_direction, odim * reduction_factor
      )
  
      # define postnet
      self.postnet = (
          None
          if postnet_layers == 0
          else Postnet(
              idim=idim,
              odim=odim,
              n_layers=postnet_layers,
              n_chans=postnet_chans,
              n_filts=postnet_filts,
              use_batch_norm=use_batch_norm,
              dropout_rate=postnet_dropout_rate,
          )
      )
  
      # define loss function
      self.criterion = FastSpeechLoss(
          use_masking=use_masking,
          use_weighted_masking=use_weighted_masking,
      )
  
      # initialize parameters
      self._reset_parameters(
          init_type=init_type,
      )
  
file_path: espnet/espnet2/svs/naive_rnn/naive_rnn_dp.py
imports: from typing import Dict, Optional, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.svs.abs_svs import AbsSVS
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  from espnet.nets.pytorch_backend.e2e_tts_fastspeech import FeedForwardTransformerLoss
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictor
  from espnet.nets.pytorch_backend.fastspeech.length_regulator import LengthRegulator
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
label_desc: Use image node_id 1 to create a new NaiveRNNDP object from inherited base classes: AbsSVS with example: obj = NaiveRNNDP(idim, odim, midi_dim, embed_dim, duration_dim, eprenet_conv_layers, eprenet_conv_chans, eprenet_conv_filts, elayers, eunits, ebidirectional, midi_embed_integration_type, dlayers, dunits, dbidirectional, postnet_layers, postnet_chans, postnet_filts, use_batch_norm, duration_predictor_layers, duration_predictor_chans, duration_predictor_kernel_size, duration_predictor_dropout_rate, reduction_factor, spks, langs, spk_embed_dim, spk_embed_integration_type, eprenet_dropout_rate, edropout_rate, ddropout_rate, postnet_dropout_rate, init_type, use_masking, use_weighted_masking)