class_docstr: RNN encoder using nn.LSTM for cuDNN support / ONNX exportability.
class_docstr_tok: ["RNN","encoder","using","nn.LSTM","for","cuDNN","support","\/","ONNX","exportability","."]
code: def __init__(
      self,
      dictionary,
      embed_tokens,
      embed_dim=512,
      cell_type="lstm",
      hidden_dim=512,
      num_layers=1,
      dropout_in=0.1,
      dropout_out=0.1,
      residual_level=None,
      bidirectional=False,
      left_pad=True,
      encoder_context_embed=False,
  ):
      assert (
          cell_type == "lstm"
      ), 'sequence-lstm requires cell_type="lstm"'
  
      super().__init__(dictionary)
      self.dictionary = dictionary
      self.dropout_in = dropout_in
      self.dropout_out = dropout_out
      self.residual_level = residual_level
      self.hidden_dim = hidden_dim
      self.bidirectional = bidirectional
      self.padding_idx = dictionary.pad()
      self.left_pad = left_pad
      self.embed_tokens = embed_tokens
  
      if encoder_context_embed:
          self.embed_tokens_context = ContextEmbedding(
              embed_dim=embed_dim
          )
      self.encoder_context_embed = encoder_context_embed
  
      self.word_dim = embed_dim
  
      self.bilstm = BiLSTM(
          num_layers=num_layers,
          bidirectional=bidirectional,
          embed_dim=embed_dim,
          hidden_dim=hidden_dim,
          dropout=dropout_out,
          residual_level=residual_level,
      )
  
      # Variable tracker
      self.tracker = VariableTracker()
  
      # Initialize adversarial mode
      self.set_gradient_tracking_mode(False)
      self.set_embed_noising_mode(False)
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.onnx.operators
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.modules import AdaptiveSoftmax
  from pytorch_translate import attention, rnn_cell, utils, vocab_reduction
  from pytorch_translate.common_layers import ContextEmbedding, DecoderWithOutputProjection, Embedding, Linear, RNNLayer, VariableTracker
  from pytorch_translate.data import data
  from pytorch_translate.multi_model import MultiDecoder, MultiEncoder
  from pytorch_translate.multilingual import MultilingualDecoder, MultilingualEncoder
  from pytorch_translate.ngram import NGramDecoder
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import maybe_cat, maybe_cuda, torch_find
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence, pad_packed_sequence
label_desc: Use image node_id 2 to create a new LSTMSequenceEncoder object from inherited base classes: FairseqEncoder with example: obj = LSTMSequenceEncoder(dictionary, embed_tokens, embed_dim, cell_type, hidden_dim, num_layers, dropout_in, dropout_out, residual_level, bidirectional, left_pad, encoder_context_embed)