class_docstr: Poly-encoder Agent.
  
  Equivalent of bert_ranker/polyencoder and biencoder_multiple_output but does not
  rely on an external library (hugging face).
class_docstr_tok: ["Poly-encoder","Agent",".","Equivalent","of","bert_ranker\/polyencoder","and","biencoder_multiple_output","but","does","not","rely","on","an","external","library","(","hugging","face",")","."]
docstr: Encode candidates.
  
  Called when scoring candidates.
docstr_tok: ["Encode","candidates",".","Called","when","scoring","candidates","."]
code: def get_cand_rep(
      self,
      batch: Batch,
      cand_vecs: torch.LongTensor,
      cand_encs: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      """
      Encode candidates.
  
      Called when scoring candidates.
      """
      bsz = self._get_batch_size(batch)
      if cand_encs is not None:
          if bsz == 1:
              cand_rep = cand_encs
          else:
              cand_rep = cand_encs.expand(bsz, cand_encs.size(1), -1)
      # bsz x num cands x seq len
      elif len(cand_vecs.shape) == 3:
          _, _, cand_rep = self.model(cand_tokens=cand_vecs)
      # bsz x seq len (if batch cands) or num_cands x seq len (if fixed cands)
      else:
          assert len(cand_vecs.shape) == 2
          _, _, cand_rep = self.model(
              cand_tokens=cand_vecs.unsqueeze(1)
          )
          num_cands = cand_rep.size(
              0
          )  # will be bsz if using batch cands
          cand_rep = (
              cand_rep.expand(num_cands, bsz, -1)
              .transpose(0, 1)
              .contiguous()
          )
  
      return cand_rep
  
imports: from parlai.core.params import ParlaiParser
  from typing import Any, Dict, Optional, Tuple
  import torch
  from parlai.core.opt import Opt
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_agent import Batch
  from parlai.utils.misc import recursive_getattr
  from parlai.utils.logging import logging
  from .biencoder import AddLabelFixedCandsTRA
  from .modules import BasicAttention, MultiHeadAttention, TransformerEncoder
  from .transformer import TransformerRankerAgent
label_desc: Use image node_id 11 for calling the PolyencoderAgent obj's underlying member method code with example usage: obj.get_cand_rep(batch, cand_vecs, cand_encs) and returns: cand_rep