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 __setstate__(self, d):
      # special handling for deserializing language models
      if "state_dict" in d:
          # re-initialize language model with constructor arguments
          language_model = LanguageModel(
              dictionary=d["dictionary"],
              is_forward_lm=d["is_forward_lm"],
              hidden_size=d["hidden_size"],
              nlayers=d["nlayers"],
              embedding_size=d["embedding_size"],
              nout=d["nout"],
              document_delimiter=d["document_delimiter"],
              dropout=d["dropout"],
              recurrent_type=d.get("recurrent_type", "lstm"),
              has_decoder=d.get("has_decoder", True),
          )
  
          language_model.load_state_dict(
              d["state_dict"], strict=d.get("has_decoder", True)
          )
  
          # copy over state dictionary to self
          for key in language_model.__dict__:
              self.__dict__[key] = language_model.__dict__[key]
  
          # set the language model to eval() by default (this is necessary since FlairEmbeddings "protect" the LM
          # in their "self.train()" method)
          self.eval()
  
      else:
          if "recurrent_type" not in d:
              d["recurrent_type"] = "lstm"
          if "state_count" not in d:
              d["state_count"] = 2
          super().__setstate__(d)
  
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 17 for calling the LanguageModel obj's underlying member method code with example usage: obj.__setstate__(d) without return types