code: def build_model(self, states=None):
      opt = self.opt
      if not states:
          states = {}
      kwargs = opt_to_kwargs(opt)
  
      model = HredModel(
          len(self.dict),
          opt["embeddingsize"],
          opt["hiddensize"],
          device=self.device,
          padding_idx=self.NULL_IDX,
          start_idx=self.START_IDX,
          end_idx=self.END_IDX,
          unknown_idx=self.dict[self.dict.unk_token],
          longest_label=states.get("longest_label", 1),
          **kwargs,
      )
  
      if (
          opt.get("dict_tokenizer") == "bpe"
          and opt["embedding_type"] != "random"
      ):
          print("skipping preinitialization of embeddings for bpe")
      elif not states and opt["embedding_type"] != "random":
          # `not states`: only set up embeddings if not loading model
          self._copy_embeddings(
              model.decoder.lt.weight, opt["embedding_type"]
          )
          if opt["lookuptable"] in ["unique", "dec_out"]:
              # also set encoder lt, since it's not shared
              self._copy_embeddings(
                  model.encoder.lt.weight,
                  opt["embedding_type"],
                  log=False,
              )
  
      if states:
          # set loaded states if applicable
          model.load_state_dict(states["model"])
  
      if opt["embedding_type"].endswith("fixed"):
          print("Seq2seq: fixing embedding weights.")
          model.decoder.lt.weight.requires_grad = False
          model.encoder.lt.weight.requires_grad = False
          if opt["lookuptable"] in ["dec_out", "all"]:
              model.output.weight.requires_grad = False
  
      return model
  
file_path: ParlAI/parlai/agents/hred/hred.py
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  import torch
  from parlai.agents.seq2seq.modules import opt_to_kwargs
  from parlai.core.torch_generator_agent import TorchGeneratorAgent
  from .modules import HredModel
label_desc: Use image node_id 3 for calling the HredAgent obj's underlying member method code with example usage: obj.build_model(states) and returns: model