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 alignment energies
  
  Arguments
  ---------
  query: torch.Tensor
      decoder output (batch, n_mel_channels * n_frames_per_step)
  processed_memory: torch.Tensor
      processed encoder outputs (B, T_in, attention_dim)
  attention_weights_cat: torch.Tensor
      cumulative and prev. att weights (B, 2, max_time)
  
  Returns
  -------
  alignment : torch.Tensor
      (batch, max_time)
docstr_tok: ["Computes","the","alignment","energies","Arguments","--","--","--","--","-","query",":","torch.Tensor","decoder","output","(","batch",",","n_mel_channels","*","n_frames_per_step",")","processed_memory",":","torch.Tensor","processed","encoder","outputs","(","B",",","T_in",",","attention_dim",")","attention_weights_cat",":","torch.Tensor","cumulative","and","prev",".","att","weights","(","B",",","2",",","max_time",")","Returns","--","--","--","-","alignment",":","torch.Tensor","(","batch",",","max_time",")"]
code: def get_alignment_energies(
      self, query, processed_memory, attention_weights_cat
  ):
      """Computes the alignment energies
  
      Arguments
      ---------
      query: torch.Tensor
          decoder output (batch, n_mel_channels * n_frames_per_step)
      processed_memory: torch.Tensor
          processed encoder outputs (B, T_in, attention_dim)
      attention_weights_cat: torch.Tensor
          cumulative and prev. att weights (B, 2, max_time)
  
      Returns
      -------
      alignment : torch.Tensor
          (batch, max_time)
      """
  
      processed_query = self.query_layer(query.unsqueeze(1))
      processed_attention_weights = self.location_layer(
          attention_weights_cat
      )
      energies = self.v(
          torch.tanh(
              processed_query
              + processed_attention_weights
              + processed_memory
          )
      )
  
      energies = energies.squeeze(2)
      return energies
  
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 2 for calling the Attention obj's underlying member method code with example usage: obj.get_alignment_energies(query, processed_memory, attention_weights_cat) and returns: energies