class_docstr: The Tacotron attention layer. Location-based attention is used.
  
  Arguments
  ---------
  attention_rnn_dim: int
      the dimension of the RNN to which the attention layer
      is applied
  embedding_dim: int
      the embedding dimension
  attention_dim: int
      the dimension of the memory cell
  attenion_location_n_filters: int
      the number of location filters
  attention_location_kernel_size: int
      the kernel size of the location layer
  
  Example
  -------
  >>> import torch
  >>> from speechbrain.lobes.models.Tacotron2 import (
  ... Attention)
  >>> from speechbrain.lobes.models.transformer.Transformer import (
  ... get_mask_from_lengths)
  >>> layer = Attention()
  >>> attention_hidden_state = torch.randn(2, 1024)
  >>> memory = torch.randn(2, 173, 512)
  >>> processed_memory = torch.randn(2, 173, 128)
  >>> attention_weights_cat = torch.randn(2, 2, 173)
  >>> memory_lengths = torch.tensor([173, 91])
  >>> mask = get_mask_from_lengths(memory_lengths)
  >>> attention_context, attention_weights = layer(
  ...    attention_hidden_state,
  ...    memory,
  ...    processed_memory,
  ...    attention_weights_cat,
  ...    mask
  ... )
  >>> attention_context.shape, attention_weights.shape
  (torch.Size([2, 512]), torch.Size([2, 173]))
class_docstr_tok: ["The","Tacotron","attention","layer",".","Location-based","attention","is","used",".","Arguments","--","--","--","--","-","attention_rnn_dim",":","int","the","dimension","of","the","RNN","to","which","the","attention","layer","is","applied","embedding_dim",":","int","the","embedding","dimension","attention_dim",":","int","the","dimension","of","the","memory","cell","attenion_location_n_filters",":","int","the","number","of","location","filters","attention_location_kernel_size",":","int","the","kernel","size","of","the","location","layer","Example","--","--","--","-",">",">",">","import","torch",">",">",">","from","speechbrain.lobes.models.Tacotron2","import","(","...","Attention",")",">",">",">","from","speechbrain.lobes.models.transformer.Transformer","import","(","...","get_mask_from_lengths",")",">",">",">","layer","=","Attention","(",")",">",">",">","attention_hidden_state","=","torch.randn","(","2",",","1024",")",">",">",">","memory","=","torch.randn","(","2",",","173",",","512",")",">",">",">","processed_memory","=","torch.randn","(","2",",","173",",","128",")",">",">",">","attention_weights_cat","=","torch.randn","(","2",",","2",",","173",")",">",">",">","memory_lengths","=","torch.tensor","(","[","173",",","91","]",")",">",">",">","mask","=","get_mask_from_lengths","(","memory_lengths",")",">",">",">","attention_context",",","attention_weights","=","layer","(","...","attention_hidden_state",",","...","memory",",","...","processed_memory",",","...","attention_weights_cat",",","...","mask","...",")",">",">",">","attention_context.shape",",","attention_weights.shape","(","torch.Size","(","[","2",",","512","]",")",",","torch.Size","(","[","2",",","173","]",")",")"]
docstr: Computes the forward pass
  
  Arguments
  ---------
  attention_hidden_state: torch.Tensor
      attention rnn last output
  memory: torch.Tensor
      encoder outputs
  processed_memory: torch.Tensor
      processed encoder outputs
  attention_weights_cat: torch.Tensor
      previous and cummulative attention weights
  mask: torch.Tensor
      binary mask for padded data
  
  Returns
  -------
  result: tuple
      a (attention_context, attention_weights) tuple
docstr_tok: ["Computes","the","forward","pass","Arguments","--","--","--","--","-","attention_hidden_state",":","torch.Tensor","attention","rnn","last","output","memory",":","torch.Tensor","encoder","outputs","processed_memory",":","torch.Tensor","processed","encoder","outputs","attention_weights_cat",":","torch.Tensor","previous","and","cummulative","attention","weights","mask",":","torch.Tensor","binary","mask","for","padded","data","Returns","--","--","--","-","result",":","tuple","a","(","attention_context",",","attention_weights",")","tuple"]
code: def forward(
      self,
      attention_hidden_state,
      memory,
      processed_memory,
      attention_weights_cat,
      mask,
  ):
      """Computes the forward pass
  
      Arguments
      ---------
      attention_hidden_state: torch.Tensor
          attention rnn last output
      memory: torch.Tensor
          encoder outputs
      processed_memory: torch.Tensor
          processed encoder outputs
      attention_weights_cat: torch.Tensor
          previous and cummulative attention weights
      mask: torch.Tensor
          binary mask for padded data
  
      Returns
      -------
      result: tuple
          a (attention_context, attention_weights) tuple
      """
      alignment = self.get_alignment_energies(
          attention_hidden_state,
          processed_memory,
          attention_weights_cat,
      )
  
      alignment = alignment.masked_fill(mask, self.score_mask_value)
  
      attention_weights = F.softmax(alignment, dim=1)
      attention_context = torch.bmm(
          attention_weights.unsqueeze(1), memory
      )
      attention_context = attention_context.squeeze(1)
  
      return attention_context, attention_weights
  
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 3 for calling the Attention obj's underlying member method code with example usage: obj.forward(attention_hidden_state, memory, processed_memory, attention_weights_cat, mask) and returns: attention_context,  attention_weights