class_docstr: The Tacotron decoder
  
  Arguments
  ---------
  n_mel_channels: int
      the number of channels in the MEL sepctrogram
  n_frames_per_step:
      the number of frames in the spectrogram for each
      time step of the decoder
  encoder_embedding_dim: int
      the dimension of the encoder embedding
  attention_location_n_filters: int
      the number of filters in location-based attention
  attention_location_kernel_size: int
      the kernel size of location-based attention
  attention_rnn_dim: int
      RNN dimension for the attention layer
  decoder_rnn_dim: int
      the encoder RNN dimension
  prenet_dim: int
      the dimension of the prenet (inner and output layers)
  max_decoder_steps: int
      the maximum number of decoder steps for the longest utterance
      expected for the model
  gate_threshold: float
      the fixed threshold to which the outputs of the decoders will be compared
  p_attention_dropout: float
      dropout probability for attention layers
  
  Example
  -------
  >>> import torch
  >>> from speechbrain.lobes.models.Tacotron2 import Decoder
  >>> layer = Decoder()
  >>> memory = torch.randn(2, 173, 512)
  >>> decoder_inputs = torch.randn(2, 80, 173)
  >>> memory_lengths = torch.tensor([173, 91])
  >>> mel_outputs, gate_outputs, alignments = layer(
  ...     memory, decoder_inputs, memory_lengths)
  >>> mel_outputs.shape, gate_outputs.shape, alignments.shape
  (torch.Size([2, 80, 173]), torch.Size([2, 173]), torch.Size([2, 173, 173]))
class_docstr_tok: ["The","Tacotron","decoder","Arguments","--","--","--","--","-","n_mel_channels",":","int","the","number","of","channels","in","the","MEL","sepctrogram","n_frames_per_step",":","the","number","of","frames","in","the","spectrogram","for","each","time","step","of","the","decoder","encoder_embedding_dim",":","int","the","dimension","of","the","encoder","embedding","attention_location_n_filters",":","int","the","number","of","filters","in","location-based","attention","attention_location_kernel_size",":","int","the","kernel","size","of","location-based","attention","attention_rnn_dim",":","int","RNN","dimension","for","the","attention","layer","decoder_rnn_dim",":","int","the","encoder","RNN","dimension","prenet_dim",":","int","the","dimension","of","the","prenet","(","inner","and","output","layers",")","max_decoder_steps",":","int","the","maximum","number","of","decoder","steps","for","the","longest","utterance","expected","for","the","model","gate_threshold",":","float","the","fixed","threshold","to","which","the","outputs","of","the","decoders","will","be","compared","p_attention_dropout",":","float","dropout","probability","for","attention","layers","Example","--","--","--","-",">",">",">","import","torch",">",">",">","from","speechbrain.lobes.models.Tacotron2","import","Decoder",">",">",">","layer","=","Decoder","(",")",">",">",">","memory","=","torch.randn","(","2",",","173",",","512",")",">",">",">","decoder_inputs","=","torch.randn","(","2",",","80",",","173",")",">",">",">","memory_lengths","=","torch.tensor","(","[","173",",","91","]",")",">",">",">","mel_outputs",",","gate_outputs",",","alignments","=","layer","(","...","memory",",","decoder_inputs",",","memory_lengths",")",">",">",">","mel_outputs.shape",",","gate_outputs.shape",",","alignments.shape","(","torch.Size","(","[","2",",","80",",","173","]",")",",","torch.Size","(","[","2",",","173","]",")",",","torch.Size","(","[","2",",","173",",","173","]",")",")"]
docstr: Decoder inference
  
  Arguments
  ---------
  memory: torch.Tensor
      Encoder outputs
  
  Returns
  -------
  mel_outputs: torch.Tensor
      mel outputs from the decoder
  gate_outputs: torch.Tensor
      gate outputs from the decoder
  alignments: torch.Tensor
      sequence of attention weights from the decoder
  mel_lengths: torch.Tensor
      the length of MEL spectrograms
docstr_tok: ["Decoder","inference","Arguments","--","--","--","--","-","memory",":","torch.Tensor","Encoder","outputs","Returns","--","--","--","-","mel_outputs",":","torch.Tensor","mel","outputs","from","the","decoder","gate_outputs",":","torch.Tensor","gate","outputs","from","the","decoder","alignments",":","torch.Tensor","sequence","of","attention","weights","from","the","decoder","mel_lengths",":","torch.Tensor","the","length","of","MEL","spectrograms"]
code: def infer(self, memory, memory_lengths):
      """Decoder inference
  
      Arguments
      ---------
      memory: torch.Tensor
          Encoder outputs
  
      Returns
      -------
      mel_outputs: torch.Tensor
          mel outputs from the decoder
      gate_outputs: torch.Tensor
          gate outputs from the decoder
      alignments: torch.Tensor
          sequence of attention weights from the decoder
      mel_lengths: torch.Tensor
          the length of MEL spectrograms
      """
      decoder_input = self.get_go_frame(memory)
  
      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_lengths = torch.zeros(
          [memory.size(0)], dtype=torch.int32, device=memory.device
      )
      not_finished = torch.ones(
          [memory.size(0)], dtype=torch.int32, device=memory.device
      )
  
      mel_outputs, gate_outputs, alignments = (
          torch.zeros(1),
          torch.zeros(1),
          torch.zeros(1),
      )
      first_iter = True
      while True:
          decoder_input = self.prenet(decoder_input)
          (
              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,
          )
  
          if first_iter:
              mel_outputs = mel_output.unsqueeze(0)
              gate_outputs = gate_output
              alignments = attention_weights
              first_iter = False
          else:
              mel_outputs = torch.cat(
                  (mel_outputs, mel_output.unsqueeze(0)), dim=0
              )
              gate_outputs = torch.cat(
                  (gate_outputs, gate_output), dim=0
              )
              alignments = torch.cat(
                  (alignments, attention_weights), dim=0
              )
  
          dec = (
              torch.le(torch.sigmoid(gate_output), self.gate_threshold)
              .to(torch.int32)
              .squeeze(1)
          )
  
          not_finished = not_finished * dec
          mel_lengths += not_finished
          if self.early_stopping and torch.sum(not_finished) == 0:
              break
          if len(mel_outputs) == self.max_decoder_steps:
              break
  
          decoder_input = mel_output
  
      (
          mel_outputs,
          gate_outputs,
          alignments,
      ) = self.parse_decoder_outputs(
          mel_outputs, gate_outputs, alignments
      )
  
      return mel_outputs, gate_outputs, alignments, mel_lengths
  
imports: from math import sqrt
  from speechbrain.nnet.loss.guidedattn_loss import GuidedAttentionLoss
  from speechbrain.lobes.models.transformer.Transformer import get_mask_from_lengths
  import torch
  from torch import nn
  from torch.nn import functional
  from collections import namedtuple
label_desc: Use image node_id 8 for calling the Decoder obj's underlying member method code with example usage: obj.infer(memory, memory_lengths) and returns: mel_outputs,  gate_outputs,  alignments,  mel_lengths