class_docstr: RNN encoder.
class_docstr_tok: ["RNN","encoder","."]
code: def __init__(
      self,
      dictionary,
      embed_tokens,
      embed_dim=512,
      hidden_dim=512,
      num_layers=1,
      cell_type="lstm",
      dropout_in=0.1,
      dropout_out=0.1,
      residual_level=None,
      bidirectional=False,
      left_pad=True,
      encoder_context_embed=False,
  ):
      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.output_units = hidden_dim  # fairseq LSTM compatibility
      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 = ContextEmbedding(
              embed_dim=self.embed_dim
          ).encoder_embed_fn
      self.encoder_context_embed = encoder_context_embed
      self.word_dim = embed_dim
  
      self.cell_type = cell_type
      self.layers = nn.ModuleList([])
      for layer in range(num_layers):
          self.layers.append(
              RNNLayer(
                  self.word_dim if layer == 0 else hidden_dim,
                  hidden_dim,
                  self.cell_type,
                  True if bidirectional and layer == 0 else False,
              )
          )
  
      self.num_layers = len(self.layers)
  
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 1 to create a new RNNEncoder object from inherited base classes: FairseqEncoder with example: obj = RNNEncoder(dictionary, embed_tokens, embed_dim, hidden_dim, num_layers, cell_type, dropout_in, dropout_out, residual_level, bidirectional, left_pad, encoder_context_embed)