class_docstr: Generator Rerank Agent.
  
  Utilize a classifier/predictor model as re-ranker with a generative agent.
class_docstr_tok: ["Generator","Rerank","Agent",".","Utilize","a","classifier\/predictor","model","as","re-ranker","with","a","generative","agent","."]
docstr: Batch process a list of observations.
  
  We call batch act directly on the generator, and then individually process each
  batch reply.
docstr_tok: ["Batch","process","a","list","of","observations",".","We","call","batch","act","directly","on","the","generator",",","and","then","individually","process","each","batch","reply","."]
code: def batch_act(self, observations: List[Message]) -> List[Message]:
      """
      Batch process a list of observations.
  
      We call batch act directly on the generator, and then individually process each
      batch reply.
      """
      batch_reply = [Message() for _ in range(len(observations))]
      # 1. get all beam texts to consider
      for strategy in self.inference_strategies:
          self.set_decoding_method(strategy)
          inference_batch_reply = super().batch_act(observations)
          for i, resp in enumerate(inference_batch_reply):
              beam_texts = batch_reply[i].get("beam_texts", [])
              batch_reply[i] = resp  # add metrics, other response items
              new_beam_texts = [
                  (*b, strategy) for b in resp.get("beam_texts", [])
              ]
              batch_reply[i].force_set(
                  "beam_texts", beam_texts + new_beam_texts
              )
      # 2. Rerank
      observations_for_reranker = self.get_observations_for_reranker(
          observations, batch_reply
      )
      for observation, generator_response in zip(
          observations_for_reranker, batch_reply
      ):
          if (
              "beam_texts" not in generator_response
              or not generator_response["beam_texts"]
          ):
              logging.warn(
                  f'Generator response had no "beam_texts" field and was: {generator_response}. Skipping reranking. Something could be seriously wrong, but this also occurs when batchsize is not a multiple of number of examples'
              )
              continue
          reranked_candidates, indices = self.reranker.rerank(
              observation,
              [b[0] for b in generator_response["beam_texts"]],  # text
              torch.tensor(
                  [b[1] for b in generator_response["beam_texts"]]
              ),  # score
          )
          if self.debug_mode:
              reranked_candidates = [
                  f"*{generator_response['beam_texts'][i][-1]}* {text}"
                  for i, text in zip(indices, reranked_candidates)
              ]
          generator_response.force_set("text", reranked_candidates[0])
          generator_response.force_set(
              "beam_texts", reranked_candidates
          )
      return batch_reply
  
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 8 for calling the AbstractGeneratorRerankAgentMixin obj's underlying member method code with example usage: obj.batch_act(observations) and returns: batch_reply