class_docstr: Model which takes context, memories, candidates and encodes them.
class_docstr_tok: ["Model","which","takes","context",",","memories",",","candidates","and","encodes","them","."]
code: def __init__(self, opt: Opt, dictionary: DictionaryAgent):
      super().__init__()
      self.opt = opt
      self.pad_idx = dictionary[dictionary.null_token]
  
      # set up embeddings
      self.embeddings = create_embeddings(
          dictionary, opt["embedding_size"], self.pad_idx
      )
  
      self.share_word_embedding = opt.get("share_word_embeddings", True)
      if not self.share_word_embedding:
          self.cand_embeddings = create_embeddings(
              dictionary, opt["embedding_size"], self.pad_idx
          )
  
      if not opt.get("learn_embeddings"):
          self.embeddings.weight.requires_grad = False
          if not self.share_word_embedding:
              self.cand_embeddings.weight.requires_grad = False
  
      self.reduction_type = opt.get("reduction_type", "mean")
  
      self.context_encoder = self.build_context_encoder(
          opt,
          dictionary,
          self.embeddings,
          self.pad_idx,
          reduction_type=self.reduction_type,
      )
  
      if opt.get("share_encoders"):
          self.cand_encoder = TransformerResponseWrapper(
              self.context_encoder, self.context_encoder.out_dim
          )
      else:
          if not self.share_word_embedding:
              cand_embeddings = self.cand_embeddings
          else:
              cand_embeddings = self.embeddings
          self.cand_encoder = self.build_candidate_encoder(
              opt,
              dictionary,
              cand_embeddings,
              self.pad_idx,
              reduction_type=self.reduction_type,
          )
  
      # build memory encoder
      if opt.get("wrap_memory_encoder", False):
          self.memory_transformer = TransformerResponseWrapper(
              self.context_encoder, self.context_encoder.out_dim
          )
      else:
          self.memory_transformer = self.context_encoder
  
      self.attender = BasicAttention(
          dim=2, attn=opt["memory_attention"], residual=True
      )
  
file_path: ParlAI/parlai/agents/transformer/modules/mem_net.py
imports: import torch
  import torch.nn
  from typing import Optional, Tuple
  from parlai.agents.transformer.modules import create_embeddings, BasicAttention, TransformerEncoder, TransformerResponseWrapper
  from parlai.core.opt import Opt
  from parlai.core.torch_agent import DictionaryAgent
label_desc: Use image node_id 4 to create a new TransformerMemNetModel object from inherited base classes: nn with example: obj = TransformerMemNetModel(opt, dictionary)