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 generate_spectrogram(
      self,
      tokens: Optional[torch.Tensor] = None,
      tokens_len: Optional[torch.Tensor] = None,
      lm_tokens: Optional[torch.Tensor] = None,
      raw_texts: Optional[List[str]] = None,
      norm_text_for_lm_model: bool = True,
      lm_model: str = "albert",
  ):
      if tokens is not None:
          if tokens_len is None:
              # It is assumed that padding is consecutive and only at the end
              tokens_len = (tokens != self.tokenizer.pad).sum(dim=-1)
      else:
          if raw_texts is None:
              raise ValueError(
                  "raw_texts must be specified if tokens is None"
              )
  
          t_seqs = [self.tokenizer(t) for t in raw_texts]
          tokens = torch.nn.utils.rnn.pad_sequence(
              sequences=[
                  torch.tensor(t, dtype=torch.long, device=self.device)
                  for t in t_seqs
              ],
              batch_first=True,
              padding_value=self.tokenizer.pad,
          )
          tokens_len = torch.tensor(
              [len(t) for t in t_seqs],
              dtype=torch.long,
              device=tokens.device,
          )
  
      if self.cond_on_lm_embeddings and lm_tokens is None:
          if raw_texts is None:
              raise ValueError(
                  "raw_texts must be specified if lm_tokens is None"
              )
  
          lm_model_tokenizer = self._get_lm_model_tokenizer(lm_model)
          lm_padding_value = lm_model_tokenizer._convert_token_to_id(
              "<pad>"
          )
          lm_space_value = lm_model_tokenizer._convert_token_to_id("▁")
  
          assert isinstance(
              self.tokenizer, EnglishCharsTokenizer
          ) or isinstance(self.tokenizer, EnglishPhonemesTokenizer)
  
          if (
              norm_text_for_lm_model
              and self.text_normalizer_call is not None
          ):
              raw_texts = [
                  self.text_normalizer_call(
                      t, **self.text_normalizer_call_kwargs
                  )
                  for t in raw_texts
              ]
  
          preprocess_texts_as_tts_input = [
              self.tokenizer.text_preprocessing_func(t)
              for t in raw_texts
          ]
          lm_tokens_as_ids_list = [
              lm_model_tokenizer.encode(t, add_special_tokens=False)
              for t in preprocess_texts_as_tts_input
          ]
  
          if self.tokenizer.pad_with_space:
              lm_tokens_as_ids_list = [
                  [lm_space_value] + t + [lm_space_value]
                  for t in lm_tokens_as_ids_list
              ]
  
          lm_tokens = torch.full(
              (
                  len(lm_tokens_as_ids_list),
                  max([len(t) for t in lm_tokens_as_ids_list]),
              ),
              fill_value=lm_padding_value,
              device=tokens.device,
          )
          for i, lm_tokens_i in enumerate(lm_tokens_as_ids_list):
              lm_tokens[i, : len(lm_tokens_i)] = torch.tensor(
                  lm_tokens_i, device=tokens.device
              )
  
      pred_spect = self.infer(
          tokens, tokens_len, lm_tokens=lm_tokens
      ).transpose(1, 2)
      return pred_spect
  
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 14 for calling the MixerTTSModel obj's underlying member method code with example usage: obj.generate_spectrogram(tokens, tokens_len, lm_tokens, raw_texts, norm_text_for_lm_model, lm_model) and returns: pred_spect