class_docstr: `StackedBidirectionalRNN` implements a multi-layer bidirectional RNN with an
  option to return outputs from all the layers of RNN.
  
  Args:
      config (Config): Configuration object of type BiLSTM.Config.
      embed_dim (int): The number of expected features in the input.
      padding_value (float): Value for the padded elements. Defaults to 0.0.
  
  Attributes:
      padding_value (float): Value for the padded elements.
      dropout (nn.Dropout): Dropout layer preceding the LSTM.
      lstm (nn.LSTM): LSTM layer that operates on the inputs.
      representation_dim (int): The calculated dimension of the output features
          of BiLSTM.
class_docstr_tok: ["`","StackedBidirectionalRNN","`","implements","a","multi-layer","bidirectional","RNN","with","an","option","to","return","outputs","from","all","the","layers","of","RNN",".","Args",":","config","(","Config",")",":","Configuration","object","of","type","BiLSTM.Config",".","embed_dim","(","int",")",":","The","number","of","expected","features","in","the","input",".","padding_value","(","float",")",":","Value","for","the","padded","elements",".","Defaults","to","0.0",".","Attributes",":","padding_value","(","float",")",":","Value","for","the","padded","elements",".","dropout","(","nn.Dropout",")",":","Dropout","layer","preceding","the","LSTM",".","lstm","(","nn.LSTM",")",":","LSTM","layer","that","operates","on","the","inputs",".","representation_dim","(","int",")",":","The","calculated","dimension","of","the","output","features","of","BiLSTM","."]
docstr: Args:
      tokens: batch, max_seq_len, hidden_size
      tokens_mask: batch, max_seq_len (1 for padding, 0 for true)
  Output:
      tokens_encoded: batch, max_seq_len, hidden_size * num_layers if
          concat_layers = True else batch, max_seq_len, hidden_size
docstr_tok: ["Args",":","tokens",":","batch",",","max_seq_len",",","hidden_size","tokens_mask",":","batch",",","max_seq_len","(","1","for","padding",",","0","for","true",")","Output",":","tokens_encoded",":","batch",",","max_seq_len",",","hidden_size","*","num_layers","if","concat_layers","=","True","else","batch",",","max_seq_len",",","hidden_size"]
code: def forward(self, tokens, tokens_mask):
      """
      Args:
          tokens: batch, max_seq_len, hidden_size
          tokens_mask: batch, max_seq_len (1 for padding, 0 for true)
      Output:
          tokens_encoded: batch, max_seq_len, hidden_size * num_layers if
              concat_layers = True else batch, max_seq_len, hidden_size
      """
      # Sort in descending order of sequence lengths.
      seq_lengths = tokens_mask.eq(0).long().sum(1)
      seq_lengths_sorted, idx_of_sorted = torch.sort(
          seq_lengths, dim=0, descending=True
      )
  
      # Sort tokens and pack into padded sequence.
      tokens_sorted = tokens.index_select(0, idx_of_sorted)
      packed_tokens = nn.utils.rnn.pack_padded_sequence(
          tokens_sorted, seq_lengths_sorted, batch_first=True
      )
  
      # Pass tokens through stacked RNN and get all layers' output.
      outputs = [packed_tokens]
      for i in range(self.num_layers):
          rnn_input = outputs[-1]
          rnn_input = nn.utils.rnn.PackedSequence(
              self.dropout(rnn_input.data), rnn_input.batch_sizes
          )
          outputs.append(self.rnns[i](rnn_input)[0])
      outputs = outputs[
          1:
      ]  # Ignore the first element which just tokens.
  
      # Unpack packed RNN outouts and concatenate if necessary.
      for i in range(len(outputs)):
          outputs[i] = nn.utils.rnn.pad_packed_sequence(
              outputs[i],
              padding_value=self.padding_value,
              batch_first=True,
          )[0]
      output = (
          torch.cat(outputs, 2) if self.concat_layers else outputs[-1]
      )
  
      # Restore to original order of examples.
      _, idx_of_original = torch.sort(idx_of_sorted, dim=0)
      output = output.index_select(0, idx_of_original)
  
      # Pad upto original batch's maximum sequence length.
      max_seq_len = tokens_mask.size(1)
      batch_size, output_seq_len, output_dim = output.size()
      if output_seq_len != max_seq_len:
          padding = torch.zeros(
              batch_size, max_seq_len - output_seq_len, output_dim
          ).type(output.data.type())
          output = torch.cat([output, padding], 1)
  
      return output
  
file_path: pytext/pytext/models/representations/stacked_bidirectional_rnn.py
imports: from enum import Enum
  import torch
  import torch.nn
  from pytext.models.module import Module
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 2 for calling the StackedBidirectionalRNN obj's underlying member method code with example usage: obj.forward(tokens, tokens_mask) and returns: output