class_docstr: Tacotron 2 Model that is used to generate mel spectrograms from text
code: def __init__(self, cfg: DictConfig, trainer: "Trainer" = None):
      # Convert to Hydra 1.0 compatible DictConfig
      cfg = model_utils.convert_model_config_to_dict_config(cfg)
      cfg = model_utils.maybe_update_config_version(cfg)
  
      # setup normalizer
      self.normalizer = None
      self.text_normalizer_call = None
      self.text_normalizer_call_kwargs = {}
      self._setup_normalizer(cfg)
  
      # setup tokenizer
      self.tokenizer = None
      if hasattr(cfg, "text_tokenizer"):
          self._setup_tokenizer(cfg)
  
          self.num_tokens = len(self.tokenizer.tokens)
          self.tokenizer_pad = self.tokenizer.pad
          self.tokenizer_unk = self.tokenizer.oov
          # assert self.tokenizer is not None
      else:
          self.num_tokens = len(cfg.labels) + 3
  
      super().__init__(cfg=cfg, trainer=trainer)
  
      schema = OmegaConf.structured(Tacotron2Config)
      # ModelPT ensures that cfg is a DictConfig, but do this second check in case ModelPT changes
      if isinstance(cfg, dict):
          cfg = OmegaConf.create(cfg)
      elif not isinstance(cfg, DictConfig):
          raise ValueError(
              f"cfg was type: {type(cfg)}. Expected either a dict or a DictConfig"
          )
      # Ensure passed cfg is compliant with schema
      try:
          OmegaConf.merge(cfg, schema)
          self.pad_value = cfg.preprocessor.pad_value
      except ConfigAttributeError:
          self.pad_value = cfg.preprocessor.params.pad_value
          logging.warning(
              "Your config is using an old NeMo yaml configuration. Please ensure that the yaml matches the "
              "current version in the main branch for future compatibility."
          )
  
      self._parser = None
      self.audio_to_melspec_precessor = instantiate(cfg.preprocessor)
      self.text_embedding = nn.Embedding(self.num_tokens, 512)
      self.encoder = instantiate(self._cfg.encoder)
      self.decoder = instantiate(self._cfg.decoder)
      self.postnet = instantiate(self._cfg.postnet)
      self.loss = Tacotron2Loss()
      self.calculate_loss = True
  
imports: import contextlib
  from dataclasses import dataclass, field
  from typing import Any, Dict, List, Optional
  import torch
  from hydra.utils import instantiate
  from omegaconf import MISSING, DictConfig, OmegaConf, open_dict
  from omegaconf.errors import ConfigAttributeError
  from pytorch_lightning.loggers import TensorBoardLogger, WandbLogger
  from torch import nn
  from nemo.collections.common.parts.preprocessing import parsers
  from nemo.collections.tts.losses.tacotron2loss import Tacotron2Loss
  from nemo.collections.tts.models.base import SpectrogramGenerator
  from nemo.collections.tts.parts.utils.helpers import g2p_backward_compatible_support, get_mask_from_lengths, tacotron2_log_to_tb_func, tacotron2_log_to_wandb_func
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import AudioSignal, EmbeddedTextType, LengthsType, LogitsType, MelSpectrogramType, SequenceToSequenceAlignmentType
  from nemo.core.neural_types.neural_type import NeuralType
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 1 to create a new Tacotron2Model object from inherited base classes: SpectrogramGenerator with example: obj = Tacotron2Model(cfg, trainer)