class_docstr: Container module with an encoder, a recurrent module, and a decoder.
code: def __init__(
      self,
      rnn_type,
      ntoken,
      ninp,
      nhid,
      nlayers,
      dropout=0.5,
      dropouth=0.5,
      dropouti=0.5,
      dropoute=0.1,
      wdrop=0,
      tie_weights=False,
  ):
      super(RNNModel, self).__init__()
      self.lockdrop = LockedDropout()
      self.idrop = nn.Dropout(dropouti)
      self.hdrop = nn.Dropout(dropouth)
      self.drop = nn.Dropout(dropout)
      self.encoder = nn.Embedding(ntoken, ninp)
      assert rnn_type in [
          "LSTM",
          "QRNN",
          "GRU",
      ], "RNN type is not supported"
      if rnn_type == "LSTM":
          self.rnns = [
              torch.nn.LSTM(
                  ninp if l == 0 else nhid,
                  nhid
                  if l != nlayers - 1
                  else (ninp if tie_weights else nhid),
                  1,
                  dropout=0,
              )
              for l in range(nlayers)
          ]
          if wdrop:
              self.rnns = [
                  WeightDrop(rnn, ["weight_hh_l0"], dropout=wdrop)
                  for rnn in self.rnns
              ]
      if rnn_type == "GRU":
          self.rnns = [
              torch.nn.GRU(
                  ninp if l == 0 else nhid,
                  nhid if l != nlayers - 1 else ninp,
                  1,
                  dropout=0,
              )
              for l in range(nlayers)
          ]
          if wdrop:
              self.rnns = [
                  WeightDrop(rnn, ["weight_hh_l0"], dropout=wdrop)
                  for rnn in self.rnns
              ]
      elif rnn_type == "QRNN":
          from torchqrnn import QRNNLayer
  
          self.rnns = [
              QRNNLayer(
                  input_size=ninp if l == 0 else nhid,
                  hidden_size=nhid
                  if l != nlayers - 1
                  else (ninp if tie_weights else nhid),
                  save_prev_x=True,
                  zoneout=0,
                  window=2 if l == 0 else 1,
                  output_gate=True,
              )
              for l in range(nlayers)
          ]
          for rnn in self.rnns:
              rnn.linear = WeightDrop(
                  rnn.linear, ["weight"], dropout=wdrop
              )
      print(self.rnns)
      self.rnns = torch.nn.ModuleList(self.rnns)
      self.decoder = nn.Linear(nhid, ntoken)
  
      # Optionally tie weights as in:
      # "Using the Output Embedding to Improve Language Models" (Press & Wolf 2016)
      # https://arxiv.org/abs/1608.05859
      # and
      # "Tying Word Vectors and Word Classifiers: A Loss Framework for Language Modeling" (Inan et al. 2016)
      # https://arxiv.org/abs/1611.01462
      if tie_weights:
          # if nhid != ninp:
          #    raise ValueError('When using the tied flag, nhid must be equal to emsize')
          self.decoder.weight = self.encoder.weight
  
      self.init_weights()
  
      self.rnn_type = rnn_type
      self.ninp = ninp
      self.nhid = nhid
      self.nlayers = nlayers
      self.dropout = dropout
      self.dropouti = dropouti
      self.dropouth = dropouth
      self.dropoute = dropoute
      self.tie_weights = tie_weights
  
file_path: awd-lstm-lm/model.py
imports: import torch
  import torch.nn
  from embed_regularize import embedded_dropout
  from locked_dropout import LockedDropout
  from weight_drop import WeightDrop
label_desc: Use image node_id 1 to create a new RNNModel object from inherited base classes: nn with example: obj = RNNModel(rnn_type, ntoken, ninp, nhid, nlayers, dropout, dropouth, dropouti, dropoute, wdrop, tie_weights)