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 the response candidates given reranker outputs and a strategy.
  
  Compute reranking differently according to specified rerank strategy
  
  :param reranker_outputs:
      outputs from reranker
  :param response_cands:
      list of response candidates
  :param response_cand_scores:
      tensor with scored response candidates from initial model
  :param rerank_for_class:
      The class (in the ML sense) we want to select for
  
  :return (candidates, indices):
      candidates: reranked list of response candidates.
      indices: list of indices into response_cands corresponding to re-rank order
docstr_tok: ["Re-rank","the","response","candidates","given","reranker","outputs","and","a","strategy",".","Compute","reranking","differently","according","to","specified","rerank","strategy",":","param","reranker_outputs",":","outputs","from","reranker",":","param","response_cands",":","list","of","response","candidates",":","param","response_cand_scores",":","tensor","with","scored","response","candidates","from","initial","model",":","param","rerank_for_class",":","The","class","(","in","the","ML","sense",")","we","want","to","select","for",":","return","(","candidates",",","indices",")",":","candidates",":","reranked","list","of","response","candidates",".","indices",":","list","of","indices","into","response_cands","corresponding","to","re-rank","order"]
code: def _rerank_candidates(
      self,
      reranker_outputs: List[Message],
      response_cands: List[str],
      response_cand_scores: torch.Tensor,
      rerank_for_class: str,
  ) -> Tuple[List[str], List[int]]:
      """
      Re-rank the response candidates given reranker outputs and a strategy.
  
      Compute reranking differently according to specified rerank strategy
  
      :param reranker_outputs:
          outputs from reranker
      :param response_cands:
          list of response candidates
      :param response_cand_scores:
          tensor with scored response candidates from initial model
      :param rerank_for_class:
          The class (in the ML sense) we want to select for
  
      :return (candidates, indices):
          candidates: reranked list of response candidates.
          indices: list of indices into response_cands corresponding to re-rank order
      """
      if self.reranker_strategy == "hard_choice":
          predicted_class = [
              (i, c)
              for i, c in enumerate(response_cands)
              if reranker_outputs[i]["text"] == rerank_for_class
          ]
          try:
              predicted_indices, predicted_class = [
                  list(l) for l in zip(*predicted_class)
              ]
          except ValueError:
              # none predicted
              predicted_indices, predicted_class = [], []
  
          predicted_not_class = [
              (i, c)
              for i, c in enumerate(response_cands)
              if reranker_outputs[i]["text"] != rerank_for_class
          ]
          try:
              predicted_not_indices, predicted_not_class = [
                  list(l) for l in zip(*predicted_not_class)
              ]
          except ValueError:
              predicted_not_indices, predicted_not_class = [], []
  
          candidates = predicted_class + predicted_not_class
          indices = predicted_indices + predicted_not_indices
      elif self.reranker_strategy == "sum_scores":
          rerank_scores = [
              o["sorted_scores"][
                  o["text_candidates"].index(rerank_for_class)
              ]
              for o in reranker_outputs
          ]
          scores = [
              rerank_scores[i].item() + response_cand_scores[i].item()
              for i in range(len(rerank_scores))
          ]
          candidates, indices = argsort(
              scores,
              response_cands,  # type: ignore
              list(range(len(response_cands))),  # type: ignore
              descending=True,
          )[:2]
      elif self.reranker_strategy == "reranker_score":
          rerank_scores = [
              o["sorted_scores"][
                  o["text_candidates"].index(rerank_for_class)
              ].item()
              for o in reranker_outputs
          ]
          candidates, indices = argsort(
              rerank_scores,
              response_cands,  # type: ignore
              list(range(len(response_cands))),  # type: ignore
              descending=True,
          )[:2]
      elif self.reranker_strategy == "none":
          candidates = response_cands
          indices = list(range(len(response_cands)))
  
      return 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 9 for calling the AbstractReranker obj's underlying member method code with example usage: obj._rerank_candidates(reranker_outputs, response_cands, response_cand_scores, rerank_for_class) and returns: candidates,  indices