class_docstr: A polyencoder agent where the model returns attention weights, rather than encoded
  context.
class_docstr_tok: ["A","polyencoder","agent","where","the","model","returns","attention","weights",",","rather","than","encoded","context","."]
docstr: Score candidates.
  
  Override to extract weights appropriately, if needed.
docstr_tok: ["Score","candidates",".","Override","to","extract","weights","appropriately",",","if","needed","."]
code: def score_candidates(self, batch, cand_vecs, cand_encs=None):
      """
      Score candidates.
  
      Override to extract weights appropriately, if needed.
      """
      original_dim = cand_vecs.dim()
      if original_dim == 2:
          cand_vecs = cand_vecs.unsqueeze(1)
      ctxt_rep, ret_weights, ctxt_rep_mask, cand_rep = self.model(
          **self._model_context_input(batch), cand_tokens=cand_vecs
      )
      if original_dim == 2:
          num_cands = cand_rep.size(
              0
          )  # will be bsz if using batch cands
          cand_rep = (
              cand_rep.expand(num_cands, batch.text_vec.size(0), -1)
              .transpose(0, 1)
              .contiguous()
          )
      ctxt_code_weights, ctxt_rep_mask = self.model(
          ctxt_rep=ctxt_rep,
          ctxt_rep_mask=ctxt_rep_mask,
          cand_rep=cand_rep,
      )
      character_weights = torch.bmm(ctxt_code_weights, ret_weights)
      return character_weights, ctxt_rep_mask
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from typing import Optional, Tuple, Dict, Union
  from parlai.agents.transformer.modules import MultiHeadAttention, TransformerEncoder, TransformerEncoderLayer
  from parlai.agents.transformer.polyencoder import PolyencoderAgent, PolyEncoderModule, PolyBasicAttention
  from parlai.core.dict import DictionaryAgent
  from parlai.core.loader import register_agent
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.torch_agent import Batch
  from parlai.utils.torch import PipelineHelper
label_desc: Use image node_id 4 for calling the PolyencoderReturnCodeWeightsAgent obj's underlying member method code with example usage: obj.score_candidates(batch, cand_vecs, cand_encs) and returns: character_weights,  ctxt_rep_mask