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","]",")",")"]
code: def __init__(
      self,
      attention_rnn_dim=1024,
      embedding_dim=512,
      attention_dim=128,
      attention_location_n_filters=32,
      attention_location_kernel_size=31,
  ):
      super().__init__()
      self.query_layer = LinearNorm(
          attention_rnn_dim,
          attention_dim,
          bias=False,
          w_init_gain="tanh",
      )
      self.memory_layer = LinearNorm(
          embedding_dim, attention_dim, bias=False, w_init_gain="tanh"
      )
      self.v = LinearNorm(attention_dim, 1, bias=False)
      self.location_layer = LocationLayer(
          attention_location_n_filters,
          attention_location_kernel_size,
          attention_dim,
      )
      self.score_mask_value = -float("inf")
  
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 1 to create a new Attention object from inherited base classes: nn with example: obj = Attention(attention_rnn_dim, embedding_dim, attention_dim, attention_location_n_filters, attention_location_kernel_size)