code: def main():
      parser = argparse.ArgumentParser(
          description=("Rescore generated hypotheses with extra models")
      )
      add_args(parser)
      add_args_rescore(parser)
      args = parser.parse_args()
  
      assert (
          args.translation_info_export_path is not None
      ), "--translation_info_export_path is required for rescoring"
  
      assert (
          args.l2r_model_path is not None
      ), "Rescoring needs forward model"
  
      _, _, forward_task = utils.load_diverse_ensemble_for_inference(
          [args.l2r_model_path]
      )
      rescorer = Rescorer(args, forward_task)
      dst_dict = forward_task.tgt_dict
      base_bleu_scorer = bleu.Scorer(
          dst_dict.pad(), dst_dict.eos(), dst_dict.unk()
      )
      rescoring_bleu_scorer = bleu.Scorer(
          bleu.BleuConfig(
              pad=dst_dict.pad(),
              eos=dst_dict.eos(),
              unk=dst_dict.unk(),
          )
      )
  
      with open(args.translation_info_export_path, "rb") as file:
          translation_info_list = pickle.load(file)
  
      scores_to_export_list = []
      trans_batch_info = []
      for k in tqdm(
          range(0, len(translation_info_list), args.batch_size)
      ):
          trans_batch_info = translation_info_list[
              k : k + args.batch_size
          ]
          for j in range(len(trans_batch_info)):
              trans_batch_info[j]["hypos"] = [
                  {
                      "score": hypo["score"],
                      "tokens": hypo["tokens"].cuda(),
                  }
                  for hypo in trans_batch_info[j]["hypos"]
              ]
          top_tokens, scores_to_export = find_top_tokens(
              args, trans_batch_info, rescorer, dst_dict.pad()
          )
          if args.scores_info_export_path is not None:
              scores_to_export_list += scores_to_export
  
          for i, trans_info in enumerate(trans_batch_info):
              base_bleu_scorer.add(
                  trans_info["target_tokens"].int().cpu(),
                  trans_info["hypos"][0]["tokens"].int().cpu(),
              )
              rescoring_bleu_scorer.add(
                  trans_info["target_tokens"].int().cpu(),
                  top_tokens[i].int().cpu(),
              )
          trans_batch_info = []
  
      print("| Base ", base_bleu_scorer.result_string())
      print("| Rescoring ", rescoring_bleu_scorer.result_string())
  
      if args.scores_info_export_path is not None:
          with open(args.scores_info_export_path, "wb") as file:
              pickle.dump(scores_to_export_list, file)
  
imports: import argparse
  import pickle
  from enum import Enum
  import torch
  from fairseq.scoring import bleu
  from pytorch_translate import hybrid_transformer_rnn, utils
  from pytorch_translate.rescoring.model_scorers import LMScorer, R2LModelScorer, ReverseModelScorer, SimpleModelScorer
  from pytorch_translate.research.rescore import cloze_transformer_model
  from pytorch_translate.tasks import pytorch_translate_task
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling a global function with example usage: main() without return types