class_docstr: A wrapper of rnn cells, with their corresponding forward function.
  If bidirectional, halve the hidden_size for each cell.
class_docstr_tok: ["A","wrapper","of","rnn","cells",",","with","their","corresponding","forward","function",".","If","bidirectional",",","halve","the","hidden_size","for","each","cell","."]
code: def __init__(
      self,
      input_size,
      hidden_size,
      cell_type="lstm",
      is_bidirectional=False,
  ):
      super().__init__()
      self.is_bidirectional = is_bidirectional
      num_directions = 2 if is_bidirectional else 1
  
      if cell_type == "lstm":
          cell_class = rnn_cell.LSTMCell
      elif cell_type == "milstm":
          cell_class = rnn_cell.MILSTMCell
      elif cell_type == "layer_norm_lstm":
          cell_class = rnn_cell.LayerNormLSTMCell
      else:
          raise Exception(f"{cell_type} not implemented")
  
      self.fwd_cell = cell_class(
          input_size, hidden_size // num_directions
      )
      if is_bidirectional:
          self.bwd_cell = cell_class(
              input_size, hidden_size // num_directions
          )
  
      self.fwd_func = VariableLengthRecurrent(
          rnn_cell=self.fwd_cell, reverse=False
      )
      if is_bidirectional:
          self.bwd_func = VariableLengthRecurrent(
              rnn_cell=self.bwd_cell, reverse=True
          )
  
imports: import abc
  import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from fairseq.models import FairseqIncrementalDecoder, transformer
  from pytorch_translate import rnn_cell, utils, vocab_reduction
  from pytorch_translate.research.lexical_choice import lexical_translation
label_desc: Use image node_id 1 to create a new RNNLayer object from inherited base classes: nn with example: obj = RNNLayer(input_size, hidden_size, cell_type, is_bidirectional)