class_docstr: Wrapper for nn.LSTM
  
  Differences include:
  * weight initialization
  * the bidirectional option makes the first layer bidirectional only
  (and in that case the hidden dim is divided by 2)
class_docstr_tok: ["Wrapper","for","nn.LSTM","Differences","include",":","*","weight","initialization","*","the","bidirectional","option","makes","the","first","layer","bidirectional","only","(","and","in","that","case","the","hidden","dim","is","divided","by","2",")"]
code: def __init__(
      self, num_layers, bidirectional, embed_dim, hidden_dim, dropout
  ):
      super().__init__()
      self.num_layers = num_layers
      self.bidirectional = bidirectional
      if bidirectional:
          assert (
              hidden_dim % 2 == 0
          ), "hidden_dim should be even if bidirectional"
      self.hidden_dim = hidden_dim
  
      self.layers = torch.nn.ModuleList([])
      for layer in range(num_layers):
          is_layer_bidirectional = bidirectional and layer == 0
          if is_layer_bidirectional:
              assert hidden_dim % 2 == 0, (
                  "hidden_dim must be even if bidirectional "
                  "(to be divided evenly between directions)"
              )
          self.layers.append(
              BiLSTM.LSTM(
                  embed_dim if layer == 0 else hidden_dim,
                  hidden_dim // 2
                  if is_layer_bidirectional
                  else hidden_dim,
                  num_layers=1,
                  dropout=dropout,
                  bidirectional=is_layer_bidirectional,
              )
          )
      log_class_usage(__class__)
  
file_path: pytext/pytext/models/seq_models/rnn_encoder.py
imports: from typing import Dict, List, Tuple
  import torch
  import torch.nn.functional
  from pytext.config import ConfigBase
  from pytext.utils.usage import log_class_usage
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from .base import PyTextSeq2SeqModule
label_desc: Use image node_id 2 to create a new BiLSTM object from inherited base classes: torch.nn with example: obj = BiLSTM(num_layers, bidirectional, embed_dim, hidden_dim, dropout)