class_docstr: Tacotron2 module for end-to-end text-to-speech (E2E-TTS).
  
  This is a module of Spectrogram prediction network in Tacotron2 described
  in `Natural TTS Synthesis
  by Conditioning WaveNet on Mel Spectrogram Predictions`_,
  which converts the sequence of characters
  into the sequence of Mel-filterbanks.
  
  .. _`Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions`:
     https://arxiv.org/abs/1712.05884
class_docstr_tok: ["Tacotron2","module","for","end-to-end","text-to-speech","(","E2E-TTS",")",".","This","is","a","module","of","Spectrogram","prediction","network","in","Tacotron2","described","in","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`","_",",","which","converts","the","sequence","of","characters","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Natural","TTS","Synthesis","by","Conditioning","WaveNet","on","Mel","Spectrogram","Predictions","`",":","https",":","\/\/arxiv.org\/abs\/1712.05884"]
docstr: Add model-specific arguments to the parser.
docstr_tok: ["Add","model-specific","arguments","to","the","parser","."]
code: def add_arguments(parser):
      """Add model-specific arguments to the parser."""
      group = parser.add_argument_group("tacotron 2 model setting")
      # encoder
      group.add_argument(
          "--embed-dim",
          default=512,
          type=int,
          help="Number of dimension of embedding",
      )
      group.add_argument(
          "--elayers",
          default=1,
          type=int,
          help="Number of encoder layers",
      )
      group.add_argument(
          "--eunits",
          "-u",
          default=512,
          type=int,
          help="Number of encoder hidden units",
      )
      group.add_argument(
          "--econv-layers",
          default=3,
          type=int,
          help="Number of encoder convolution layers",
      )
      group.add_argument(
          "--econv-chans",
          default=512,
          type=int,
          help="Number of encoder convolution channels",
      )
      group.add_argument(
          "--econv-filts",
          default=5,
          type=int,
          help="Filter size of encoder convolution",
      )
      # attention
      group.add_argument(
          "--atype",
          default="location",
          type=str,
          choices=["forward_ta", "forward", "location"],
          help="Type of attention mechanism",
      )
      group.add_argument(
          "--adim",
          default=512,
          type=int,
          help="Number of attention transformation dimensions",
      )
      group.add_argument(
          "--aconv-chans",
          default=32,
          type=int,
          help="Number of attention convolution channels",
      )
      group.add_argument(
          "--aconv-filts",
          default=15,
          type=int,
          help="Filter size of attention convolution",
      )
      group.add_argument(
          "--cumulate-att-w",
          default=True,
          type=strtobool,
          help="Whether or not to cumulate attention weights",
      )
      # decoder
      group.add_argument(
          "--dlayers",
          default=2,
          type=int,
          help="Number of decoder layers",
      )
      group.add_argument(
          "--dunits",
          default=1024,
          type=int,
          help="Number of decoder hidden units",
      )
      group.add_argument(
          "--prenet-layers",
          default=2,
          type=int,
          help="Number of prenet layers",
      )
      group.add_argument(
          "--prenet-units",
          default=256,
          type=int,
          help="Number of prenet hidden units",
      )
      group.add_argument(
          "--postnet-layers",
          default=5,
          type=int,
          help="Number of postnet layers",
      )
      group.add_argument(
          "--postnet-chans",
          default=512,
          type=int,
          help="Number of postnet channels",
      )
      group.add_argument(
          "--postnet-filts",
          default=5,
          type=int,
          help="Filter size of postnet",
      )
      group.add_argument(
          "--output-activation",
          default=None,
          type=str,
          nargs="?",
          help="Output activation function",
      )
      # cbhg
      group.add_argument(
          "--use-cbhg",
          default=False,
          type=strtobool,
          help="Whether to use CBHG module",
      )
      group.add_argument(
          "--cbhg-conv-bank-layers",
          default=8,
          type=int,
          help="Number of convoluional bank layers in CBHG",
      )
      group.add_argument(
          "--cbhg-conv-bank-chans",
          default=128,
          type=int,
          help="Number of convoluional bank channles in CBHG",
      )
      group.add_argument(
          "--cbhg-conv-proj-filts",
          default=3,
          type=int,
          help="Filter size of convoluional projection layer in CBHG",
      )
      group.add_argument(
          "--cbhg-conv-proj-chans",
          default=256,
          type=int,
          help="Number of convoluional projection channels in CBHG",
      )
      group.add_argument(
          "--cbhg-highway-layers",
          default=4,
          type=int,
          help="Number of highway layers in CBHG",
      )
      group.add_argument(
          "--cbhg-highway-units",
          default=128,
          type=int,
          help="Number of highway units in CBHG",
      )
      group.add_argument(
          "--cbhg-gru-units",
          default=256,
          type=int,
          help="Number of GRU units in CBHG",
      )
      # model (parameter) related
      group.add_argument(
          "--use-batch-norm",
          default=True,
          type=strtobool,
          help="Whether to use batch normalization",
      )
      group.add_argument(
          "--use-concate",
          default=True,
          type=strtobool,
          help="Whether to concatenate encoder embedding with decoder outputs",
      )
      group.add_argument(
          "--use-residual",
          default=True,
          type=strtobool,
          help="Whether to use residual connection in conv layer",
      )
      group.add_argument(
          "--dropout-rate", default=0.5, type=float, help="Dropout rate"
      )
      group.add_argument(
          "--zoneout-rate", default=0.1, type=float, help="Zoneout rate"
      )
      group.add_argument(
          "--reduction-factor",
          default=1,
          type=int,
          help="Reduction factor",
      )
      group.add_argument(
          "--spk-embed-dim",
          default=None,
          type=int,
          help="Number of speaker embedding dimensions",
      )
      group.add_argument(
          "--spc-dim",
          default=None,
          type=int,
          help="Number of spectrogram dimensions",
      )
      group.add_argument(
          "--pretrained-model",
          default=None,
          type=str,
          help="Pretrained model path",
      )
      # loss related
      group.add_argument(
          "--use-masking",
          default=False,
          type=strtobool,
          help="Whether to use masking in calculation of loss",
      )
      group.add_argument(
          "--use-weighted-masking",
          default=False,
          type=strtobool,
          help="Whether to use weighted masking in calculation of loss",
      )
      group.add_argument(
          "--bce-pos-weight",
          default=20.0,
          type=float,
          help="Positive sample weight in BCE calculation "
          "(only for use-masking=True)",
      )
      group.add_argument(
          "--use-guided-attn-loss",
          default=False,
          type=strtobool,
          help="Whether to use guided attention loss",
      )
      group.add_argument(
          "--guided-attn-loss-sigma",
          default=0.4,
          type=float,
          help="Sigma in guided attention loss",
      )
      group.add_argument(
          "--guided-attn-loss-lambda",
          default=1.0,
          type=float,
          help="Lambda in guided attention loss",
      )
      return parser
  
imports: import logging
  import numpy
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
  from espnet.nets.pytorch_backend.rnn.attentions import AttForward, AttForwardTA, AttLoc
  from espnet.nets.pytorch_backend.tacotron2.cbhg import CBHG, CBHGLoss
  from espnet.nets.pytorch_backend.tacotron2.decoder import Decoder
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.cli_utils import strtobool
  from espnet.utils.fill_missing_args import fill_missing_args
label_desc: Use image node_id 1 for calling the Tacotron2 obj's underlying member method code with example usage: obj.add_arguments(parser) and returns: parser