class_docstr: Model which takes context, memories, candidates and encodes them.
class_docstr_tok: ["Model","which","takes","context",",","memories",",","candidates","and","encodes","them","."]
docstr: Encode the candidates.
docstr_tok: ["Encode","the","candidates","."]
code: def encode_cand(self, words):
      """
      Encode the candidates.
      """
      if words is None:
          return None
  
      # flatten if there are many candidates
      if words.dim() == 3:
          oldshape = words.shape
          words = words.reshape(oldshape[0] * oldshape[1], oldshape[2])
      else:
          oldshape = None
  
      encoded = self.cand_encoder(words)
  
      if oldshape is not None:
          encoded = encoded.reshape(oldshape[0], oldshape[1], -1)
  
      return encoded
  
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 5 for calling the TransformerMemNetModel obj's underlying member method code with example usage: obj.encode_cand(words) and returns: encoded, None