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","]",")"]
docstr: Performs a forward stap in the inference context
  
  Arguments
  ---------
  x: torch.Tensor
      a batch of inputs (sequence embeddings)
  
  input_lengths: torch.Tensor
      a tensor of input lengths
  
  Returns
  -------
  outputs: torch.Tensor
      the encoder output
docstr_tok: ["Performs","a","forward","stap","in","the","inference","context","Arguments","--","--","--","--","-","x",":","torch.Tensor","a","batch","of","inputs","(","sequence","embeddings",")","input_lengths",":","torch.Tensor","a","tensor","of","input","lengths","Returns","--","--","--","-","outputs",":","torch.Tensor","the","encoder","output"]
code: def infer(self, x, input_lengths):
      """Performs a forward stap in the inference context
  
      Arguments
      ---------
      x: torch.Tensor
          a batch of inputs (sequence embeddings)
  
      input_lengths: torch.Tensor
          a tensor of input lengths
  
      Returns
      -------
      outputs: torch.Tensor
          the encoder output
      """
      device = x.device
      for conv in self.convolutions:
          x = F.dropout(F.relu(conv(x.to(device))), 0.5, self.training)
  
      x = x.transpose(1, 2)
  
      input_lengths = input_lengths.cpu()
      x = nn.utils.rnn.pack_padded_sequence(
          x, input_lengths, batch_first=True
      )
      outputs, _ = self.lstm(x)
  
      outputs, _ = nn.utils.rnn.pad_packed_sequence(
          outputs, batch_first=True
      )
  
      return outputs
  
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 Encoder obj's underlying member method code with example usage: obj.infer(x, input_lengths) and returns: outputs