class_docstr: A stacked, bidirectional LSTM which uses
  :class:`~allennlp.modules.lstm_cell_with_projection.LstmCellWithProjection`'s
  with highway layers between the inputs to layers.
  The inputs to the forward and backward directions are independent - forward and backward
  states are not concatenated between layers.
  Additionally, this LSTM maintains its `own` state, which is updated every time
  ``forward`` is called. It is dynamically resized for different batch sizes and is
  designed for use with non-continuous inputs (i.e inputs which aren't formatted as a stream,
  such as text used for a language modelling task, which is how stateful RNNs are typically used).
  This is non-standard, but can be thought of as having an "end of sentence" state, which is
  carried across different sentences.
  Parameters
  ----------
  input_size : ``int``, required
      The dimension of the inputs to the LSTM.
  hidden_size : ``int``, required
      The dimension of the outputs of the LSTM.
  cell_size : ``int``, required.
      The dimension of the memory cell of the
      :class:`~allennlp.modules.lstm_cell_with_projection.LstmCellWithProjection`.
  num_layers : ``int``, required
      The number of bidirectional LSTMs to use.
  requires_grad: ``bool``, optional
      If True, compute gradient of ELMo parameters for fine tuning.
  recurrent_dropout_probability: ``float``, optional (default = 0.0)
      The dropout probability to be used in a dropout scheme as stated in
      `A Theoretically Grounded Application of Dropout in Recurrent Neural Networks
      <https://arxiv.org/abs/1512.05287>`_ .
  state_projection_clip_value: ``float``, optional, (default = None)
      The magnitude with which to clip the hidden_state after projecting it.
  memory_cell_clip_value: ``float``, optional, (default = None)
      The magnitude with which to clip the memory cell.
code: def __init__(
      self,
      input_size,
      hidden_size,
      cell_size,
      num_layers,
      requires_grad=False,
      recurrent_dropout_probability=0.0,
      memory_cell_clip_value=None,
      state_projection_clip_value=None,
  ):
      super(ElmoLstm, self).__init__(stateful=True)
  
      # Required to be wrapped with a :class:`PytorchSeq2SeqWrapper`.
      self.input_size = input_size
      self.hidden_size = hidden_size
      self.num_layers = num_layers
      self.cell_size = cell_size
      self.requires_grad = requires_grad
  
      forward_layers = []
      backward_layers = []
  
      lstm_input_size = input_size
      go_forward = True
      for layer_index in range(num_layers):
          forward_layer = LstmCellWithProjection(
              lstm_input_size,
              hidden_size,
              cell_size,
              go_forward,
              recurrent_dropout_probability,
              memory_cell_clip_value,
              state_projection_clip_value,
          )
          backward_layer = LstmCellWithProjection(
              lstm_input_size,
              hidden_size,
              cell_size,
              not go_forward,
              recurrent_dropout_probability,
              memory_cell_clip_value,
              state_projection_clip_value,
          )
          lstm_input_size = hidden_size
  
          self.add_module(
              "forward_layer_{}".format(layer_index), forward_layer
          )
          self.add_module(
              "backward_layer_{}".format(layer_index), backward_layer
          )
          forward_layers.append(forward_layer)
          backward_layers.append(backward_layer)
      self.forward_layers = forward_layers
      self.backward_layers = backward_layers
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/elmo_lstm.py
imports: import warnings
  import torch
  from torch.nn.utils.rnn import PackedSequence, pad_packed_sequence
  import numpy
  from allennlp.modules.lstm_cell_with_projection import LstmCellWithProjection
  from allennlp.common.checks import ConfigurationError
  from allennlp.modules.encoder_base import _EncoderBase
  from allennlp.common.file_utils import cached_path
label_desc: Use image node_id 1 to create a new ElmoLstm object from inherited base classes: _EncoderBase with example: obj = ElmoLstm(input_size, hidden_size, cell_size, num_layers, requires_grad, recurrent_dropout_probability, memory_cell_clip_value, state_projection_clip_value)