class_docstr: A stacked LSTM with LSTM layers which alternate between going forwards over
  the sequence and going backwards, with highway connections between each of
  the alternating layers. This implementation is based on the description in
  `Deep Semantic Role Labelling - What works and what's next
  <https://homes.cs.washington.edu/~luheng/files/acl2017_hllz.pdf>`_ .
  
  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.
  num_layers : int, required
      The number of stacked LSTMs to use.
  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>`_ .
  
  Returns
  -------
  output : PackedSequence
      The outputs of the interleaved LSTMs per timestep. A tensor of shape
      (batch_size, max_timesteps, hidden_size) where for a given batch
      element, all outputs past the sequence length for that batch are
      zero tensors.
class_docstr_tok: ["A","stacked","LSTM","with","LSTM","layers","which","alternate","between","going","forwards","over","the","sequence","and","going","backwards",",","with","highway","connections","between","each","of","the","alternating","layers",".","This","implementation","is","based","on","the","description","in","`","Deep","Semantic","Role","Labelling","-","What","works","and","what","'s","next","<","https",":","\/\/homes.cs.washington.edu\/~luheng\/files\/acl2017_hllz.pdf",">","`","_",".","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",".","num_layers",":","int",",","required","The","number","of","stacked","LSTMs","to","use",".","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",">","`","_",".","Returns","--","--","--","-","output",":","PackedSequence","The","outputs","of","the","interleaved","LSTMs","per","timestep",".","A","tensor","of","shape","(","batch_size",",","max_timesteps",",","hidden_size",")","where","for","a","given","batch","element",",","all","outputs","past","the","sequence","length","for","that","batch","are","zero","tensors","."]
docstr: Parameters
  ----------
  inputs : ``PackedSequence``, required.
      A batch first ``PackedSequence`` to run the stacked LSTM over.
  initial_state : Tuple[torch.Tensor, torch.Tensor], optional, (default = None)
      Currently, this is ignored.
  
  Returns
  -------
  output_sequence : ``PackedSequence``
      The encoded sequence of shape (batch_size, sequence_length, hidden_size)
  final_states: ``torch.Tensor``
      The per-layer final (state, memory) states of the LSTM, each with shape
      (num_layers, batch_size, hidden_size).
docstr_tok: ["Parameters","--","--","--","--","--","inputs",":","``","PackedSequence","``",",","required",".","A","batch","first","``","PackedSequence","``","to","run","the","stacked","LSTM","over",".","initial_state",":","Tuple","[","torch.Tensor",",","torch.Tensor","]",",","optional",",","(","default","=","None",")","Currently",",","this","is","ignored",".","Returns","--","--","--","-","output_sequence",":","``","PackedSequence","``","The","encoded","sequence","of","shape","(","batch_size",",","sequence_length",",","hidden_size",")","final_states",":","``","torch.Tensor","``","The","per-layer","final","(","state",",","memory",")","states","of","the","LSTM",",","each","with","shape","(","num_layers",",","batch_size",",","hidden_size",")","."]
code: def forward(
      self,
      inputs,  # pylint: disable=arguments-differ
      # pylint: disable=unused-argument
      initial_state=None,
  ):
      """
      Parameters
      ----------
      inputs : ``PackedSequence``, required.
          A batch first ``PackedSequence`` to run the stacked LSTM over.
      initial_state : Tuple[torch.Tensor, torch.Tensor], optional, (default = None)
          Currently, this is ignored.
  
      Returns
      -------
      output_sequence : ``PackedSequence``
          The encoded sequence of shape (batch_size, sequence_length, hidden_size)
      final_states: ``torch.Tensor``
          The per-layer final (state, memory) states of the LSTM, each with shape
          (num_layers, batch_size, hidden_size).
      """
      inputs, lengths = pad_packed_sequence(inputs, batch_first=True)
  
      # Kernel takes sequence length first tensors.
      inputs = inputs.transpose(0, 1)
  
      sequence_length, batch_size, _ = inputs.size()
      accumulator_shape = [
          self.num_layers,
          sequence_length + 1,
          batch_size,
          self.hidden_size,
      ]
      state_accumulator = inputs.new_zeros(*accumulator_shape)
      memory_accumulator = inputs.new_zeros(*accumulator_shape)
  
      dropout_weights = inputs.new_ones(
          self.num_layers, batch_size, self.hidden_size
      )
      if self.training:
          # Normalize by 1 - dropout_prob to preserve the output statistics of the layer.
          dropout_weights.bernoulli_(
              1 - self.recurrent_dropout_probability
          ).div_((1 - self.recurrent_dropout_probability))
  
      gates = inputs.new_tensor(
          (
              self.num_layers,
              sequence_length,
              batch_size,
              6 * self.hidden_size,
          )
      )
  
      lengths_variable = torch.LongTensor(lengths)
      implementation = _AlternatingHighwayLSTMFunction(
          self.input_size,
          self.hidden_size,
          num_layers=self.num_layers,
          train=self.training,
      )
      output, _ = implementation(
          inputs,
          self.weight,
          self.bias,
          state_accumulator,
          memory_accumulator,
          dropout_weights,
          lengths_variable,
          gates,
      )
  
      # TODO(Mark): Also return the state here by using index_select with the lengths so we can use
      # it as a Seq2VecEncoder.
      output = output.transpose(0, 1)
      output = pack_padded_sequence(output, lengths, batch_first=True)
      return output, None
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/alternating_highway_lstm.py
imports: from __future__ import absolute_import
  import torch
  from torch.autograd import Function
  from torch.nn import Parameter
  from torch.nn.utils.rnn import PackedSequence, pad_packed_sequence, pack_padded_sequence
  from allennlp.nn.initializers import block_orthogonal
  from allennlp.custom_extensions._ext import highway_lstm_layer
label_desc: Use image node_id 3 for calling the AlternatingHighwayLSTM obj's underlying member method code with example usage: obj.forward(inputs, initial_state) and returns: output,  None