class_docstr: RNN Encoder.
docstr: Initialize recurrent encoder.
docstr_tok: ["Initialize","recurrent","encoder","."]
code: def __init__(
      self,
      num_features,
      embeddingsize,
      hiddensize,
      padding_idx=0,
      rnn_class="lstm",
      numlayers=2,
      dropout=0.1,
      bidirectional=False,
      shared_lt=None,
      shared_rnn=None,
      input_dropout=0,
      unknown_idx=None,
      sparse=False,
  ):
      """
      Initialize recurrent encoder.
      """
      super().__init__()
  
      self.dropout = nn.Dropout(p=dropout)
      self.layers = numlayers
      self.dirs = 2 if bidirectional else 1
      self.hsz = hiddensize
  
      if input_dropout > 0 and unknown_idx is None:
          raise RuntimeError(
              "input_dropout > 0 but unknown_idx not set"
          )
      self.input_dropout = UnknownDropout(unknown_idx, input_dropout)
  
      if shared_lt is None:
          self.lt = nn.Embedding(
              num_features,
              embeddingsize,
              padding_idx=padding_idx,
              sparse=sparse,
          )
      else:
          self.lt = shared_lt
  
      if shared_rnn is None:
          self.rnn = rnn_class(
              embeddingsize,
              hiddensize,
              numlayers,
              dropout=dropout if numlayers > 1 else 0,
              batch_first=True,
              bidirectional=bidirectional,
          )
      elif bidirectional:
          raise RuntimeError("Cannot share decoder with bidir encoder.")
      else:
          self.rnn = shared_rnn
  
imports: import math
  import torch
  import torch.nn
  from torch.nn.parameter import Parameter
  from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence
  import torch.nn.functional
  from parlai.utils.torch import neginf
  from parlai.core.torch_generator_agent import TorchGeneratorModel
label_desc: Use image node_id 1 to create a new RNNEncoder object from inherited base classes: nn with example: obj = RNNEncoder(num_features, embeddingsize, hiddensize, padding_idx, rnn_class, numlayers, dropout, bidirectional, shared_lt, shared_rnn, input_dropout, unknown_idx, sparse)