class_docstr: FastPitch model (https://arxiv.org/abs/2006.06873) that is used to generate mel spectrogram from text.
class_docstr_tok: ["FastPitch","model","(","https",":","\/\/arxiv.org\/abs\/2006.06873",")","that","is","used","to","generate","mel","spectrogram","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)
  
      self.learn_alignment = cfg.get("learn_alignment", False)
  
      # Setup vocabulary (=tokenizer) and input_fft_kwargs (supported only with self.learn_alignment=True)
      input_fft_kwargs = {}
      if self.learn_alignment:
          self.vocab = None
  
          self.ds_class = cfg.train_ds.dataset._target_
          self.ds_class_name = self.ds_class.split(".")[-1]
          if not self.ds_class in [
              "nemo.collections.tts.data.dataset.TTSDataset",
              "nemo.collections.tts.data.text_to_speech_dataset.TextToSpeechDataset",
              "nemo.collections.tts.torch.data.TTSDataset",
          ]:
              raise ValueError(
                  f"Unknown dataset class: {self.ds_class}."
              )
  
          self._setup_tokenizer(cfg)
          assert self.vocab is not None
          input_fft_kwargs["n_embed"] = len(self.vocab.tokens)
          input_fft_kwargs["padding_idx"] = self.vocab.pad
  
      self._parser = None
      self._tb_logger = None
      super().__init__(cfg=cfg, trainer=trainer)
  
      self.bin_loss_warmup_epochs = cfg.get(
          "bin_loss_warmup_epochs", 100
      )
      self.log_images = cfg.get("log_images", False)
      self.log_train_images = False
  
      default_prosody_loss_scale = 0.1 if self.learn_alignment else 1.0
      dur_loss_scale = cfg.get(
          "dur_loss_scale", default_prosody_loss_scale
      )
      pitch_loss_scale = cfg.get(
          "pitch_loss_scale", default_prosody_loss_scale
      )
      energy_loss_scale = cfg.get(
          "energy_loss_scale", default_prosody_loss_scale
      )
  
      self.mel_loss_fn = MelLoss()
      self.pitch_loss_fn = PitchLoss(loss_scale=pitch_loss_scale)
      self.duration_loss_fn = DurationLoss(loss_scale=dur_loss_scale)
      self.energy_loss_fn = EnergyLoss(loss_scale=energy_loss_scale)
  
      self.aligner = None
      if self.learn_alignment:
          aligner_loss_scale = cfg.get("aligner_loss_scale", 1.0)
          self.aligner = instantiate(self._cfg.alignment_module)
          self.forward_sum_loss_fn = ForwardSumLoss(
              loss_scale=aligner_loss_scale
          )
          self.bin_loss_fn = BinLoss(loss_scale=aligner_loss_scale)
  
      self.preprocessor = instantiate(self._cfg.preprocessor)
      input_fft = instantiate(self._cfg.input_fft, **input_fft_kwargs)
      output_fft = instantiate(self._cfg.output_fft)
      duration_predictor = instantiate(self._cfg.duration_predictor)
      pitch_predictor = instantiate(self._cfg.pitch_predictor)
      speaker_encoder = instantiate(
          self._cfg.get("speaker_encoder", None)
      )
      energy_embedding_kernel_size = cfg.get(
          "energy_embedding_kernel_size", 0
      )
      energy_predictor = instantiate(
          self._cfg.get("energy_predictor", None)
      )
  
      # [TODO] may remove if we change the pre-trained config
      # cfg: condition_types = [ "add" ]
      n_speakers = cfg.get("n_speakers", 0)
      speaker_emb_condition_prosody = cfg.get(
          "speaker_emb_condition_prosody", False
      )
      speaker_emb_condition_decoder = cfg.get(
          "speaker_emb_condition_decoder", False
      )
      speaker_emb_condition_aligner = cfg.get(
          "speaker_emb_condition_aligner", False
      )
      min_token_duration = cfg.get("min_token_duration", 0)
      use_log_energy = cfg.get("use_log_energy", True)
      if (
          n_speakers > 1
          and "add" not in input_fft.cond_input.condition_types
      ):
          input_fft.cond_input.condition_types.append("add")
      if speaker_emb_condition_prosody:
          duration_predictor.cond_input.condition_types.append("add")
          pitch_predictor.cond_input.condition_types.append("add")
      if speaker_emb_condition_decoder:
          output_fft.cond_input.condition_types.append("add")
      if speaker_emb_condition_aligner and self.aligner is not None:
          self.aligner.cond_input.condition_types.append("add")
  
      self.fastpitch = FastPitchModule(
          input_fft,
          output_fft,
          duration_predictor,
          pitch_predictor,
          energy_predictor,
          self.aligner,
          speaker_encoder,
          n_speakers,
          cfg.symbols_embedding_dim,
          cfg.pitch_embedding_kernel_size,
          energy_embedding_kernel_size,
          cfg.n_mel_channels,
          min_token_duration,
          cfg.max_token_duration,
          use_log_energy,
      )
      self._input_types = self._output_types = None
      self.export_config = {
          "emb_range": (
              0,
              self.fastpitch.encoder.word_emb.num_embeddings,
          ),
          "enable_volume": False,
          "enable_ragged_batches": False,
      }
      if self.fastpitch.speaker_emb is not None:
          self.export_config["num_speakers"] = cfg.n_speakers
  
      self.log_config = cfg.get("log_config", None)
  
      # Adapter modules setup (from FastPitchAdapterModelMixin)
      self.setup_adapters()
  
imports: import contextlib
  from dataclasses import dataclass, field
  from pathlib import Path
  from typing import List, Optional
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import TensorBoardLogger
  from nemo.collections.common.parts.preprocessing import parsers
  from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
  from nemo.collections.tts.losses.fastpitchloss import DurationLoss, EnergyLoss, MelLoss, PitchLoss
  from nemo.collections.tts.models.base import SpectrogramGenerator
  from nemo.collections.tts.modules.fastpitch import FastPitchModule
  from nemo.collections.tts.parts.mixins import FastPitchAdapterModelMixin
  from nemo.collections.tts.parts.utils.callbacks import LoggingCallback
  from nemo.collections.tts.parts.utils.helpers import batch_from_ragged, g2p_backward_compatible_support, plot_alignment_to_numpy, plot_spectrogram_to_numpy, process_batch, sample_tts_input
  from nemo.core.classes import Exportable
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import Index, LengthsType, MelSpectrogramType, ProbsType, RegressionValuesType, TokenDurationType, TokenIndex, TokenLogDurationType
  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 FastPitchModel object from inherited base classes: SpectrogramGenerator, Exportable, FastPitchAdapterModelMixin with example: obj = FastPitchModel(cfg, trainer)