class_docstr: The Tacotron2 encoder module, consisting of a sequence of  1-d convolution banks (3 by default)
  and a bidirectional LSTM
  
  Arguments
  ---------
  encoder_n_convolutions: int
      the number of encoder convolutions
  encoder_embedding_dim: int
      the dimension of the encoder embedding
  encoder_kernel_size: int
      the kernel size of the 1-D convolutional layers within
      the encoder
  
  Example
  -------
  >>> import torch
  >>> from speechbrain.lobes.models.Tacotron2 import Encoder
  >>> layer = Encoder()
  >>> x = torch.randn(2, 512, 128)
  >>> input_lengths = torch.tensor([128, 83])
  >>> outputs = layer(x, input_lengths)
  >>> outputs.shape
  torch.Size([2, 128, 512])
class_docstr_tok: ["The","Tacotron2","encoder","module",",","consisting","of","a","sequence","of","1-d","convolution","banks","(","3","by","default",")","and","a","bidirectional","LSTM","Arguments","--","--","--","--","-","encoder_n_convolutions",":","int","the","number","of","encoder","convolutions","encoder_embedding_dim",":","int","the","dimension","of","the","encoder","embedding","encoder_kernel_size",":","int","the","kernel","size","of","the","1-D","convolutional","layers","within","the","encoder","Example","--","--","--","-",">",">",">","import","torch",">",">",">","from","speechbrain.lobes.models.Tacotron2","import","Encoder",">",">",">","layer","=","Encoder","(",")",">",">",">","x","=","torch.randn","(","2",",","512",",","128",")",">",">",">","input_lengths","=","torch.tensor","(","[","128",",","83","]",")",">",">",">","outputs","=","layer","(","x",",","input_lengths",")",">",">",">","outputs.shape","torch.Size","(","[","2",",","128",",","512","]",")"]
code: def __init__(
      self,
      encoder_n_convolutions=3,
      encoder_embedding_dim=512,
      encoder_kernel_size=5,
  ):
      super().__init__()
  
      convolutions = []
      for _ in range(encoder_n_convolutions):
          conv_layer = nn.Sequential(
              ConvNorm(
                  encoder_embedding_dim,
                  encoder_embedding_dim,
                  kernel_size=encoder_kernel_size,
                  stride=1,
                  padding=int((encoder_kernel_size - 1) / 2),
                  dilation=1,
                  w_init_gain="relu",
              ),
              nn.BatchNorm1d(encoder_embedding_dim),
          )
          convolutions.append(conv_layer)
      self.convolutions = nn.ModuleList(convolutions)
  
      self.lstm = nn.LSTM(
          encoder_embedding_dim,
          int(encoder_embedding_dim / 2),
          1,
          batch_first=True,
          bidirectional=True,
      )
  
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 Encoder object from inherited base classes: nn with example: obj = Encoder(encoder_n_convolutions, encoder_embedding_dim, encoder_kernel_size)