class_docstr: Transformer Ranker Agent.
  
  Implementation of a TorchRankerAgent, where the model is a Transformer
class_docstr_tok: ["Transformer","Ranker","Agent",".","Implementation","of","a","TorchRankerAgent",",","where","the","model","is","a","Transformer"]
docstr: Score candidates.
docstr_tok: ["Score","candidates","."]
code: def score_candidates(self, batch, cand_vecs, cand_encs=None):
      """
      Score candidates.
      """
      # convoluted check that not all memories are empty
      if (
          self.opt["use_memories"]
          and batch.memory_vecs is not None
          and sum(len(m) for m in batch.memory_vecs)
      ):
          mems = padded_3d(batch.memory_vecs, pad_idx=self.NULL_IDX)
      else:
          mems = None
  
      if cand_encs is not None:
          # we pre-encoded the candidates, do not re-encode here
          cand_vecs = None
  
      context_h, cands_h = self.model(
          xs=batch.text_vec, mems=mems, cands=cand_vecs
      )
  
      if cand_encs is not None:
          cands_h = cand_encs
      scores = self._score(context_h, cands_h)
  
      return scores
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.core.agents import Agent
  from parlai.utils.torch import padded_3d
  from parlai.core.torch_classifier_agent import TorchClassifierAgent
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_generator_agent import TorchGeneratorAgent
  from parlai.utils.misc import recursive_getattr, warn_once
  from parlai.utils.logging import logging
  from parlai.utils.fsdp import should_use_fsdp
  from .modules import TransformerMemNetModel, TransformerGeneratorModel, TransformerLinearWrapper
  import torch
label_desc: Use image node_id 8 for calling the TransformerRankerAgent obj's underlying member method code with example usage: obj.score_candidates(batch, cand_vecs, cand_encs) and returns: scores