class_docstr: Re-ranker object which uses a predictor model to rerank candidates given.
  
  This AbstractReranker can be subclassed to use any classifier or ranking model as
  the predictor.
class_docstr_tok: ["Re-ranker","object","which","uses","a","predictor","model","to","rerank","candidates","given",".","This","AbstractReranker","can","be","subclassed","to","use","any","classifier","or","ranking","model","as","the","predictor","."]
docstr: Re-rank candidates according to predictor score.
  
  :param observation:
      Message object that includes the dialogue history
  :param response_cands:
      ranked list of model response candidates
  :param response_cand_scores:
      list of model response candidates' scores
  
  :return (candidates, indices):
      candidates: a re-ranked list of candidates
      indices: list of indices into response_cands corresponding to re-rank order
docstr_tok: ["Re-rank","candidates","according","to","predictor","score",".",":","param","observation",":","Message","object","that","includes","the","dialogue","history",":","param","response_cands",":","ranked","list","of","model","response","candidates",":","param","response_cand_scores",":","list","of","model","response","candidates","'","scores",":","return","(","candidates",",","indices",")",":","candidates",":","a","re-ranked","list","of","candidates","indices",":","list","of","indices","into","response_cands","corresponding","to","re-rank","order"]
code: def rerank(
      self,
      observation: Message,
      response_cands: List[str],
      response_cand_scores: torch.Tensor,
  ) -> Tuple[List[str], List[int]]:
      """
      Re-rank candidates according to predictor score.
  
      :param observation:
          Message object that includes the dialogue history
      :param response_cands:
          ranked list of model response candidates
      :param response_cand_scores:
          list of model response candidates' scores
  
      :return (candidates, indices):
          candidates: a re-ranked list of candidates
          indices: list of indices into response_cands corresponding to re-rank order
      """
      full_context = observation["full_text"]
  
      # 0) Normalize the replies if the opt is passed in
      if self.normalize_candidates:
          response_cands = [normalize_reply(c) for c in response_cands]
  
      # 1) Augment context with response candidates
      if not self.include_label_cand_only:
          contexts = [
              self.augment_context(
                  full_context,
                  cand,
                  include_context=self.include_context,
              )
              for cand in response_cands
          ]
          contexts = [self.delimiter.join(utts) for utts in contexts]
      else:
          # This variant only passes in the label candidates (with no dialogue history whatsoever
          # into the ranker. Can be useful for things like e.g. simple utterance-based safety classifiers.
          contexts = response_cands
  
      # 2) Predict with augmented context
      label_candidates = self.get_predictor_label_candidates(
          observation, full_context
      )
      reranker_outputs = self.batch_predict(contexts, label_candidates)
  
      # 3) Rerank
      rerank_for_class = self.get_class_to_rerank_for(
          observation, full_context
      )
      reranked_candidates, indices = self._rerank_candidates(
          reranker_outputs,
          response_cands,
          response_cand_scores,
          rerank_for_class=rerank_for_class,
      )
  
      if self.show_debug_logging(observation):
          debug_str = self._construct_debug_logging(
              observation,
              response_cands,
              response_cand_scores,
              reranker_outputs,
              reranked_candidates,
              rerank_for_class,
          )
          # Need print because even logging.WARN swallowed during eval
          print(debug_str)
      return reranked_candidates, indices
  
imports: import logging
  import torch
  from abc import ABC, abstractmethod, abstractclassmethod
  from typing import List, Optional, Tuple
  from parlai.agents.transformer.transformer import TransformerGeneratorAgent
  from parlai.core.agents import create_agent_from_model_file, Agent
  from parlai.core.build_data import modelzoo_path
  from parlai.core.message import Message
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.torch_agent import TorchAgent
  from parlai.utils.strings import normalize_reply
  from parlai.utils.torch import argsort
  from parlai.agents.hugging_face.gpt2 import Gpt2Agent
  from projects.msc.agents.long_tga import TransformerVariantAgent
label_desc: Use image node_id 10 for calling the AbstractReranker obj's underlying member method code with example usage: obj.rerank(observation, response_cands, response_cand_scores) and returns: reranked_candidates,  indices