class_docstr: Encoder module of Spectrogram prediction network.
  
  This is a module of encoder of Spectrogram prediction network in Singing Tacotron,
  which described in `Singing-Tacotron: Global Duration Control Attention and Dynamic
  Filter for End-to-end Singing Voice Synthesis`_. This is the encoder which converts
  either a sequence of characters or acoustic features into the sequence of
  hidden states.
  
  .. _`Singing-Tacotron: Global Duration Control Attention and Dynamic
  Filter for End-to-end Singing Voice Synthesis`:
     https://arxiv.org/abs/2202.07907
class_docstr_tok: ["Encoder","module","of","Spectrogram","prediction","network",".","This","is","a","module","of","encoder","of","Spectrogram","prediction","network","in","Singing","Tacotron",",","which","described","in","`","Singing-Tacotron",":","Global","Duration","Control","Attention","and","Dynamic","Filter","for","End-to-end","Singing","Voice","Synthesis","`","_",".","This","is","the","encoder","which","converts","either","a","sequence","of","characters","or","acoustic","features","into","the","sequence","of","hidden","states",".","..","_","`","Singing-Tacotron",":","Global","Duration","Control","Attention","and","Dynamic","Filter","for","End-to-end","Singing","Voice","Synthesis","`",":","https",":","\/\/arxiv.org\/abs\/2202.07907"]
docstr: Initialize Singing Tacotron encoder module.
  
  Args:
      idim (int) Dimension of the inputs.
      input_layer (str): Input layer type.
      embed_dim (int, optional) Dimension of character embedding.
      elayers (int, optional) The number of encoder blstm layers.
      eunits (int, optional) The number of encoder blstm units.
      econv_layers (int, optional) The number of encoder conv layers.
      econv_filts (int, optional) The number of encoder conv filter size.
      econv_chans (int, optional) The number of encoder conv filter channels.
      use_batch_norm (bool, optional) Whether to use batch normalization.
      use_residual (bool, optional) Whether to use residual connection.
      dropout_rate (float, optional) Dropout rate.
docstr_tok: ["Initialize","Singing","Tacotron","encoder","module",".","Args",":","idim","(","int",")","Dimension","of","the","inputs",".","input_layer","(","str",")",":","Input","layer","type",".","embed_dim","(","int",",","optional",")","Dimension","of","character","embedding",".","elayers","(","int",",","optional",")","The","number","of","encoder","blstm","layers",".","eunits","(","int",",","optional",")","The","number","of","encoder","blstm","units",".","econv_layers","(","int",",","optional",")","The","number","of","encoder","conv","layers",".","econv_filts","(","int",",","optional",")","The","number","of","encoder","conv","filter","size",".","econv_chans","(","int",",","optional",")","The","number","of","encoder","conv","filter","channels",".","use_batch_norm","(","bool",",","optional",")","Whether","to","use","batch","normalization",".","use_residual","(","bool",",","optional",")","Whether","to","use","residual","connection",".","dropout_rate","(","float",",","optional",")","Dropout","rate","."]
code: def __init__(
      self,
      idim,
      input_layer="embed",
      embed_dim=512,
      elayers=1,
      eunits=512,
      econv_layers=3,
      econv_chans=512,
      econv_filts=5,
      use_batch_norm=True,
      use_residual=False,
      dropout_rate=0.5,
      padding_idx=0,
  ):
      """Initialize Singing Tacotron encoder module.
  
      Args:
          idim (int) Dimension of the inputs.
          input_layer (str): Input layer type.
          embed_dim (int, optional) Dimension of character embedding.
          elayers (int, optional) The number of encoder blstm layers.
          eunits (int, optional) The number of encoder blstm units.
          econv_layers (int, optional) The number of encoder conv layers.
          econv_filts (int, optional) The number of encoder conv filter size.
          econv_chans (int, optional) The number of encoder conv filter channels.
          use_batch_norm (bool, optional) Whether to use batch normalization.
          use_residual (bool, optional) Whether to use residual connection.
          dropout_rate (float, optional) Dropout rate.
  
      """
      super(Encoder, self).__init__()
      # store the hyperparameters
      self.idim = idim
      self.use_residual = use_residual
  
      # define network layer modules
      if input_layer == "linear":
          self.embed = torch.nn.Linear(idim, econv_chans)
      elif input_layer == "embed":
          self.embed = torch.nn.Embedding(
              idim, embed_dim, padding_idx=padding_idx
          )
      else:
          raise ValueError("unknown input_layer: " + input_layer)
  
      if econv_layers > 0:
          self.convs = torch.nn.ModuleList()
          for layer in range(econv_layers):
              ichans = (
                  embed_dim
                  if layer == 0 and input_layer == "embed"
                  else econv_chans
              )
              if use_batch_norm:
                  self.convs += [
                      torch.nn.Sequential(
                          torch.nn.Conv1d(
                              ichans,
                              econv_chans,
                              econv_filts,
                              stride=1,
                              padding=(econv_filts - 1) // 2,
                              bias=False,
                          ),
                          torch.nn.BatchNorm1d(econv_chans),
                          torch.nn.ReLU(),
                          torch.nn.Dropout(dropout_rate),
                      )
                  ]
              else:
                  self.convs += [
                      torch.nn.Sequential(
                          torch.nn.Conv1d(
                              ichans,
                              econv_chans,
                              econv_filts,
                              stride=1,
                              padding=(econv_filts - 1) // 2,
                              bias=False,
                          ),
                          torch.nn.ReLU(),
                          torch.nn.Dropout(dropout_rate),
                      )
                  ]
      else:
          self.convs = None
      if elayers > 0:
          iunits = econv_chans if econv_layers != 0 else embed_dim
          self.blstm = torch.nn.LSTM(
              iunits,
              eunits // 2,
              elayers,
              batch_first=True,
              bidirectional=True,
          )
      else:
          self.blstm = None
  
      # initialize
      self.apply(encoder_init)
  
file_path: espnet/espnet2/svs/singing_tacotron/encoder.py
imports: import torch
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: torch.nn with example: obj = Encoder(idim, input_layer, embed_dim, elayers, eunits, econv_layers, econv_chans, econv_filts, use_batch_norm, use_residual, dropout_rate, padding_idx)