docstr: Returns an LSTM with forget gate bias init to `forget_gate_bias`.
  Args:
      input_size: See `torch.nn.LSTM`.
      hidden_size: See `torch.nn.LSTM`.
      num_layers: See `torch.nn.LSTM`.
      dropout: See `torch.nn.LSTM`.
  
      forget_gate_bias: float, set by default to 1.0, which constructs a forget gate
          initialized to 1.0.
          Reference:
          [An Empirical Exploration of Recurrent Network Architectures](http://proceedings.mlr.press/v37/jozefowicz15.pdf)
  
      t_max: int value, set to None by default. If an int is specified, performs Chrono Initialization
          of the LSTM network, based on the maximum number of timesteps `t_max` expected during the course
          of training.
          Reference:
          [Can recurrent neural networks warp time?](https://openreview.net/forum?id=SJcKhk-Ab)
  
      weights_init_scale: Float scale of the weights after initialization. Setting to lower than one
          sometimes helps reduce variance between runs.
  
      hidden_hidden_bias_scale: Float scale for the hidden-to-hidden bias scale. Set to 0.0 for
          the default behaviour.
  
  Returns:
      A `torch.nn.LSTM`.
docstr_tok: ["Returns","an","LSTM","with","forget","gate","bias","init","to","`","forget_gate_bias","`",".","Args",":","input_size",":","See","`","torch.nn.LSTM","`",".","hidden_size",":","See","`","torch.nn.LSTM","`",".","num_layers",":","See","`","torch.nn.LSTM","`",".","dropout",":","See","`","torch.nn.LSTM","`",".","forget_gate_bias",":","float",",","set","by","default","to","1.0",",","which","constructs","a","forget","gate","initialized","to","1.0",".","Reference",":","[","An","Empirical","Exploration","of","Recurrent","Network","Architectures","]","(","http",":","\/\/proceedings.mlr.press\/v37\/jozefowicz15.pdf",")","t_max",":","int","value",",","set","to","None","by","default",".","If","an","int","is","specified",",","performs","Chrono","Initialization","of","the","LSTM","network",",","based","on","the","maximum","number","of","timesteps","`","t_max","`","expected","during","the","course","of","training",".","Reference",":","[","Can","recurrent","neural","networks","warp","time","?","]","(","https",":","\/\/openreview.net\/forum","?","id=SJcKhk-Ab",")","weights_init_scale",":","Float","scale","of","the","weights","after","initialization",".","Setting","to","lower","than","one","sometimes","helps","reduce","variance","between","runs",".","hidden_hidden_bias_scale",":","Float","scale","for","the","hidden-to-hidden","bias","scale",".","Set","to","0.0","for","the","default","behaviour",".","Returns",":","A","`","torch.nn.LSTM","`","."]
code: def __init__(
      self,
      input_size: int,
      hidden_size: int,
      num_layers: int,
      dropout: Optional[float],
      forget_gate_bias: Optional[float],
      t_max: Optional[int] = None,
      weights_init_scale: float = 1.0,
      hidden_hidden_bias_scale: float = 0.0,
      proj_size: int = 0,
  ):
      """Returns an LSTM with forget gate bias init to `forget_gate_bias`.
      Args:
          input_size: See `torch.nn.LSTM`.
          hidden_size: See `torch.nn.LSTM`.
          num_layers: See `torch.nn.LSTM`.
          dropout: See `torch.nn.LSTM`.
  
          forget_gate_bias: float, set by default to 1.0, which constructs a forget gate
              initialized to 1.0.
              Reference:
              [An Empirical Exploration of Recurrent Network Architectures](http://proceedings.mlr.press/v37/jozefowicz15.pdf)
  
          t_max: int value, set to None by default. If an int is specified, performs Chrono Initialization
              of the LSTM network, based on the maximum number of timesteps `t_max` expected during the course
              of training.
              Reference:
              [Can recurrent neural networks warp time?](https://openreview.net/forum?id=SJcKhk-Ab)
  
          weights_init_scale: Float scale of the weights after initialization. Setting to lower than one
              sometimes helps reduce variance between runs.
  
          hidden_hidden_bias_scale: Float scale for the hidden-to-hidden bias scale. Set to 0.0 for
              the default behaviour.
  
      Returns:
          A `torch.nn.LSTM`.
      """
      super(LSTMDropout, self).__init__()
  
      self.lstm = torch.nn.LSTM(
          input_size=input_size,
          hidden_size=hidden_size,
          num_layers=num_layers,
          dropout=dropout,
          proj_size=proj_size,
      )
  
      if t_max is not None:
          # apply chrono init
          for name, v in self.lstm.named_parameters():
              if "bias" in name:
                  p = getattr(self.lstm, name)
                  n = p.nelement()
                  hidden_size = n // 4
                  p.data.fill_(0)
                  p.data[hidden_size : 2 * hidden_size] = torch.log(
                      torch.nn.init.uniform_(
                          p.data[0:hidden_size], 1, t_max - 1
                      )
                  )
                  # forget gate biases = log(uniform(1, Tmax-1))
                  p.data[0:hidden_size] = -p.data[
                      hidden_size : 2 * hidden_size
                  ]
                  # input gate biases = -(forget gate biases)
  
      elif forget_gate_bias is not None:
          for name, v in self.lstm.named_parameters():
              if "bias_ih" in name:
                  bias = getattr(self.lstm, name)
                  bias.data[hidden_size : 2 * hidden_size].fill_(
                      forget_gate_bias
                  )
              if "bias_hh" in name:
                  bias = getattr(self.lstm, name)
                  bias.data[hidden_size : 2 * hidden_size] *= float(
                      hidden_hidden_bias_scale
                  )
  
      self.dropout = torch.nn.Dropout(dropout) if dropout else None
  
      for name, v in self.named_parameters():
          if "weight" in name or "bias" in name:
              v.data *= float(weights_init_scale)
  
imports: import math
  from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new LSTMDropout object from inherited base classes: torch.nn with example: obj = LSTMDropout(input_size, hidden_size, num_layers, dropout, forget_gate_bias, t_max, weights_init_scale, hidden_hidden_bias_scale, proj_size)