class_docstr: Decoder with Attention model.
  
  Args:
      n_mels (int): number of mel bins
      n_frames_per_step (int): number of frames processed per step, only 1 is supported
      encoder_embedding_dim (int): the number of embedding dimensions in the encoder.
      decoder_rnn_dim (int): number of units in decoder LSTM
      decoder_max_step (int): maximum number of output mel spectrograms
      decoder_dropout (float): dropout probability for decoder LSTM
      decoder_early_stopping (bool): stop decoding when all samples are finished
      attention_rnn_dim (int): number of units in attention LSTM
      attention_hidden_dim (int): dimension of attention hidden representation
      attention_location_n_filter (int): number of filters for attention model
      attention_location_kernel_size (int): kernel size for attention model
      attention_dropout (float): dropout probability for attention LSTM
      prenet_dim (int): number of ReLU units in prenet layers
      gate_threshold (float): probability threshold for stop token
class_docstr_tok: ["Decoder","with","Attention","model",".","Args",":","n_mels","(","int",")",":","number","of","mel","bins","n_frames_per_step","(","int",")",":","number","of","frames","processed","per","step",",","only","1","is","supported","encoder_embedding_dim","(","int",")",":","the","number","of","embedding","dimensions","in","the","encoder",".","decoder_rnn_dim","(","int",")",":","number","of","units","in","decoder","LSTM","decoder_max_step","(","int",")",":","maximum","number","of","output","mel","spectrograms","decoder_dropout","(","float",")",":","dropout","probability","for","decoder","LSTM","decoder_early_stopping","(","bool",")",":","stop","decoding","when","all","samples","are","finished","attention_rnn_dim","(","int",")",":","number","of","units","in","attention","LSTM","attention_hidden_dim","(","int",")",":","dimension","of","attention","hidden","representation","attention_location_n_filter","(","int",")",":","number","of","filters","for","attention","model","attention_location_kernel_size","(","int",")",":","kernel","size","for","attention","model","attention_dropout","(","float",")",":","dropout","probability","for","attention","LSTM","prenet_dim","(","int",")",":","number","of","ReLU","units","in","prenet","layers","gate_threshold","(","float",")",":","probability","threshold","for","stop","token"]
docstr: Decoder forward pass for training.
  
  Args:
      memory (Tensor): Encoder outputs
          with shape (n_batch, max of ``text_lengths``, ``encoder_embedding_dim``).
      mel_specgram_truth (Tensor): Decoder ground-truth mel-specs for teacher forcing
          with shape (n_batch, ``n_mels``, max of ``mel_specgram_lengths``).
      memory_lengths (Tensor): Encoder output lengths for attention masking
          (the same as ``text_lengths``) with shape (n_batch, ).
  
  Returns:
      mel_specgram (Tensor): Predicted mel spectrogram
          with shape (n_batch, ``n_mels``, max of ``mel_specgram_lengths``).
      gate_outputs (Tensor): Predicted stop token for each timestep
          with shape (n_batch,  max of ``mel_specgram_lengths``).
      alignments (Tensor): Sequence of attention weights from the decoder
          with shape (n_batch,  max of ``mel_specgram_lengths``, max of ``text_lengths``).
docstr_tok: ["Decoder","forward","pass","for","training",".","Args",":","memory","(","Tensor",")",":","Encoder","outputs","with","shape","(","n_batch",",","max","of","``","text_lengths","``",",","``","encoder_embedding_dim","``",")",".","mel_specgram_truth","(","Tensor",")",":","Decoder","ground-truth","mel-specs","for","teacher","forcing","with","shape","(","n_batch",",","``","n_mels","``",",","max","of","``","mel_specgram_lengths","``",")",".","memory_lengths","(","Tensor",")",":","Encoder","output","lengths","for","attention","masking","(","the","same","as","``","text_lengths","``",")","with","shape","(","n_batch",",",")",".","Returns",":","mel_specgram","(","Tensor",")",":","Predicted","mel","spectrogram","with","shape","(","n_batch",",","``","n_mels","``",",","max","of","``","mel_specgram_lengths","``",")",".","gate_outputs","(","Tensor",")",":","Predicted","stop","token","for","each","timestep","with","shape","(","n_batch",",","max","of","``","mel_specgram_lengths","``",")",".","alignments","(","Tensor",")",":","Sequence","of","attention","weights","from","the","decoder","with","shape","(","n_batch",",","max","of","``","mel_specgram_lengths","``",",","max","of","``","text_lengths","``",")","."]
code: def forward(
      self,
      memory: Tensor,
      mel_specgram_truth: Tensor,
      memory_lengths: Tensor,
  ) -> Tuple[Tensor, Tensor, Tensor]:
      r"""Decoder forward pass for training.
  
      Args:
          memory (Tensor): Encoder outputs
              with shape (n_batch, max of ``text_lengths``, ``encoder_embedding_dim``).
          mel_specgram_truth (Tensor): Decoder ground-truth mel-specs for teacher forcing
              with shape (n_batch, ``n_mels``, max of ``mel_specgram_lengths``).
          memory_lengths (Tensor): Encoder output lengths for attention masking
              (the same as ``text_lengths``) with shape (n_batch, ).
  
      Returns:
          mel_specgram (Tensor): Predicted mel spectrogram
              with shape (n_batch, ``n_mels``, max of ``mel_specgram_lengths``).
          gate_outputs (Tensor): Predicted stop token for each timestep
              with shape (n_batch,  max of ``mel_specgram_lengths``).
          alignments (Tensor): Sequence of attention weights from the decoder
              with shape (n_batch,  max of ``mel_specgram_lengths``, max of ``text_lengths``).
      """
  
      decoder_input = self._get_initial_frame(memory).unsqueeze(0)
      decoder_inputs = self._parse_decoder_inputs(mel_specgram_truth)
      decoder_inputs = torch.cat((decoder_input, decoder_inputs), dim=0)
      decoder_inputs = self.prenet(decoder_inputs)
  
      mask = _get_mask_from_lengths(memory_lengths)
      (
          attention_hidden,
          attention_cell,
          decoder_hidden,
          decoder_cell,
          attention_weights,
          attention_weights_cum,
          attention_context,
          processed_memory,
      ) = self._initialize_decoder_states(memory)
  
      mel_outputs, gate_outputs, alignments = [], [], []
      while len(mel_outputs) < decoder_inputs.size(0) - 1:
          decoder_input = decoder_inputs[len(mel_outputs)]
          (
              mel_output,
              gate_output,
              attention_hidden,
              attention_cell,
              decoder_hidden,
              decoder_cell,
              attention_weights,
              attention_weights_cum,
              attention_context,
          ) = self.decode(
              decoder_input,
              attention_hidden,
              attention_cell,
              decoder_hidden,
              decoder_cell,
              attention_weights,
              attention_weights_cum,
              attention_context,
              memory,
              processed_memory,
              mask,
          )
  
          mel_outputs += [mel_output.squeeze(1)]
          gate_outputs += [gate_output.squeeze(1)]
          alignments += [attention_weights]
  
      (
          mel_specgram,
          gate_outputs,
          alignments,
      ) = self._parse_decoder_outputs(
          torch.stack(mel_outputs),
          torch.stack(gate_outputs),
          torch.stack(alignments),
      )
  
      return mel_specgram, gate_outputs, alignments
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
label_desc: Use image node_id 7 for calling the _Decoder obj's underlying member method code with example usage: obj.forward(memory, mel_specgram_truth, memory_lengths) and returns: mel_specgram,  gate_outputs,  alignments