class_docstr: Mixer-TTS and Mixer-TTS-X models (https://arxiv.org/abs/2110.03584) that is used to generate mel spectrogram from text.
class_docstr_tok: ["Mixer-TTS","and","Mixer-TTS-X","models","(","https",":","\/\/arxiv.org\/abs\/2110.03584",")","that","is","used","to","generate","mel","spectrogram","from","text","."]
code: def validation_step(self, batch, batch_idx):
      attn_prior, lm_tokens = None, None
      if self.cond_on_lm_embeddings:
          (
              audio,
              audio_len,
              text,
              text_len,
              attn_prior,
              pitch,
              _,
              lm_tokens,
          ) = batch
      else:
          audio, audio_len, text, text_len, attn_prior, pitch, _ = batch
  
      spect, spect_len = self.preprocessor(
          input_signal=audio, length=audio_len
      )
  
      # pitch normalization
      zero_pitch_idx = pitch == 0
      pitch = (pitch - self.pitch_mean) / self.pitch_std
      pitch[zero_pitch_idx] = 0.0
  
      (
          pred_spect,
          _,
          pred_log_durs,
          pred_pitch,
          attn_soft,
          attn_logprob,
          attn_hard,
          attn_hard_dur,
      ) = self(
          text=text,
          text_len=text_len,
          pitch=pitch,
          spect=spect,
          spect_len=spect_len,
          attn_prior=attn_prior,
          lm_tokens=lm_tokens,
      )
  
      (
          loss,
          durs_loss,
          acc,
          acc_dist_1,
          acc_dist_3,
          pitch_loss,
          mel_loss,
          ctc_loss,
          bin_loss,
      ) = self._metrics(
          pred_durs=pred_log_durs,
          pred_pitch=pred_pitch,
          true_durs=attn_hard_dur,
          true_text_len=text_len,
          true_pitch=pitch,
          true_spect=spect,
          pred_spect=pred_spect,
          true_spect_len=spect_len,
          attn_logprob=attn_logprob,
          attn_soft=attn_soft,
          attn_hard=attn_hard,
          attn_hard_dur=attn_hard_dur,
      )
  
      # without ground truth internal features except for durations
      (
          pred_spect,
          _,
          pred_log_durs,
          pred_pitch,
          attn_soft,
          attn_logprob,
          attn_hard,
          attn_hard_dur,
      ) = self(
          text=text,
          text_len=text_len,
          pitch=None,
          spect=spect,
          spect_len=spect_len,
          attn_prior=attn_prior,
          lm_tokens=lm_tokens,
      )
  
      *_, with_pred_features_mel_loss, _, _ = self._metrics(
          pred_durs=pred_log_durs,
          pred_pitch=pred_pitch,
          true_durs=attn_hard_dur,
          true_text_len=text_len,
          true_pitch=pitch,
          true_spect=spect,
          pred_spect=pred_spect,
          true_spect_len=spect_len,
          attn_logprob=attn_logprob,
          attn_soft=attn_soft,
          attn_hard=attn_hard,
          attn_hard_dur=attn_hard_dur,
      )
  
      val_log = {
          "val_loss": loss,
          "val_durs_loss": durs_loss,
          "val_pitch_loss": torch.tensor(1.0).to(durs_loss.device)
          if pitch_loss is None
          else pitch_loss,
          "val_mel_loss": mel_loss,
          "val_with_pred_features_mel_loss": with_pred_features_mel_loss,
          "val_durs_acc": acc,
          "val_durs_acc_dist_3": acc_dist_3,
          "val_ctc_loss": torch.tensor(1.0).to(durs_loss.device)
          if ctc_loss is None
          else ctc_loss,
          "val_bin_loss": torch.tensor(1.0).to(durs_loss.device)
          if bin_loss is None
          else bin_loss,
      }
      self.log_dict(
          val_log,
          prog_bar=False,
          on_epoch=True,
          logger=True,
          sync_dist=True,
      )
  
      if (
          batch_idx == 0
          and self.current_epoch % 5 == 0
          and isinstance(self.logger, WandbLogger)
      ):
          specs = []
          pitches = []
          for i in range(min(3, spect.shape[0])):
              specs += [
                  wandb.Image(
                      plot_spectrogram_to_numpy(
                          spect[i, :, : spect_len[i]].data.cpu().numpy()
                      ),
                      caption=f"gt mel {i}",
                  ),
                  wandb.Image(
                      plot_spectrogram_to_numpy(
                          pred_spect.transpose(1, 2)[
                              i, :, : spect_len[i]
                          ]
                          .data.cpu()
                          .numpy()
                      ),
                      caption=f"pred mel {i}",
                  ),
              ]
  
              pitches += [
                  wandb.Image(
                      plot_pitch_to_numpy(
                          average_features(
                              pitch.unsqueeze(1), attn_hard_dur
                          )
                          .squeeze(1)[i, : text_len[i]]
                          .data.cpu()
                          .numpy(),
                          ylim_range=[-2.5, 2.5],
                      ),
                      caption=f"gt pitch {i}",
                  ),
              ]
  
              pitches += [
                  wandb.Image(
                      plot_pitch_to_numpy(
                          pred_pitch[i, : text_len[i]]
                          .data.cpu()
                          .numpy(),
                          ylim_range=[-2.5, 2.5],
                      ),
                      caption=f"pred pitch {i}",
                  ),
              ]
  
          self.logger.experiment.log(
              {"specs": specs, "pitches": pitches}
          )
  
imports: import contextlib
  from typing import List, Optional
  import numpy
  import omegaconf
  import torch
  import transformers
  import wandb
  from hydra.utils import instantiate
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import WandbLogger
  from torch import nn
  from torch.nn import functional
  from transformers import AlbertTokenizer
  from nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers import EnglishCharsTokenizer, EnglishPhonemesTokenizer
  from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
  from nemo.collections.tts.models.base import SpectrogramGenerator
  from nemo.collections.tts.modules.fastpitch import average_features, regulate_len
  from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel, g2p_backward_compatible_support, get_mask_from_lengths, plot_pitch_to_numpy, plot_spectrogram_to_numpy
  from nemo.core import Exportable
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import LengthsType, LogprobsType, 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 13 for calling the MixerTTSModel obj's underlying member method code with example usage: obj.validation_step(batch, batch_idx) without return types