class_docstr: Container module with an encoder, a recurrent module, and a decoder.
class_docstr_tok: ["Container","module","with","an","encoder",",","a","recurrent","module",",","and","a","decoder","."]
code: def __init__(
      self,
      dictionary: Dictionary,
      is_forward_lm: bool,
      hidden_size: int,
      nlayers: int,
      embedding_size: int = 100,
      nout=None,
      document_delimiter: str = "\n",
      dropout=0.1,
      recurrent_type="LSTM",
      has_decoder=True,
  ) -> None:
      super().__init__()
  
      self.dictionary = dictionary
      self.document_delimiter = document_delimiter
      self.is_forward_lm: bool = is_forward_lm
  
      self.dropout = dropout
      self.hidden_size = hidden_size
      self.embedding_size = embedding_size
      self.nlayers = nlayers
  
      self.drop = nn.Dropout(dropout)
      self.encoder = nn.Embedding(len(dictionary), embedding_size)
  
      self.rnn, self.state_count = create_recurrent_layer(
          recurrent_type, embedding_size, hidden_size, nlayers, dropout
      )
      self.recurrent_type = recurrent_type
      self.hidden = None
  
      self.nout = nout
      if nout is not None:
          self.proj: Optional[nn.Linear] = nn.Linear(hidden_size, nout)
          self.initialize(self.proj.weight)
          hidden_size = nout
      else:
          self.proj = None
      if has_decoder:
          self.decoder: Optional[nn.Linear] = nn.Linear(
              hidden_size, len(dictionary)
          )
      else:
          self.decoder = None
  
      self.init_weights()
  
      # auto-spawn on GPU if available
      self.to(flair.device)
  
imports: import math
  from pathlib import Path
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import logsumexp, nn
  from torch.optim import Optimizer
  import flair
  from flair.data import Dictionary
  from flair.nn.recurrent import create_recurrent_layer
label_desc: Use image node_id 1 to create a new LanguageModel object from inherited base classes: nn with example: obj = LanguageModel(dictionary, is_forward_lm, hidden_size, nlayers, embedding_size, nout, document_delimiter, dropout, recurrent_type, has_decoder)