code: def find_top_tokens(args, trans_batch_info, rescorer, pad):
      """Rescore translations and combine weights to find top hypo tokens"""
      len_src_tokens = [
          len(trans_info["src_tokens"])
          for trans_info in trans_batch_info
      ]
      bsz = len(trans_batch_info)
      src_tokens = (
          torch.zeros(bsz, max(len_src_tokens)).fill_(pad).long().cuda()
      )
      for i in range(bsz):
          src_tokens[i, : len_src_tokens[i]] = (
              trans_batch_info[i]["src_tokens"]
              .view(1, -1)
              .long()
              .cuda()
          )
      hypos = [
          hypo
          for trans_info in trans_batch_info
          for hypo in trans_info["hypos"]
      ]
  
      scores = rescorer.score(src_tokens, hypos)
  
      # Prepare all the weights and call combine weighted scores
      weights = [
          args.l2r_model_weight,
          args.r2l_model_weight,
          args.reverse_model_weight,
          args.lm_model_weight,
          args.cloze_transformer_weight,
      ]
      bsz, src_len = src_tokens.size()
      beam_size = len(hypos) // bsz
      hypos = [
          hypos[i * beam_size : (i + 1) * beam_size] for i in range(bsz)
      ]
      scores_to_export = []
      top_hypos = []
      for i in range(bsz):
          score = scores[i * beam_size : (i + 1) * beam_size, :]
          tgt_len = torch.tensor(
              [len(hypo["tokens"]) for hypo in hypos[i]],
              dtype=torch.float,
          )
          combined_scores = combine_weighted_scores(
              score,
              weights,
              len_src_tokens[i],
              tgt_len,
              args.rescore_length_penalty,
          )
          top_index = combined_scores.max(0)[1]
          scores_to_export.append(
              {
                  "hypos": [
                      hypo["tokens"].cpu().tolist() for hypo in hypos[i]
                  ],
                  "target_tokens": trans_batch_info[i]["target_tokens"]
                  .cpu()
                  .numpy(),
                  "scores": score.detach().numpy(),
                  "src_len": len_src_tokens[i],
                  "tgt_len": tgt_len.cpu().numpy(),
              }
          )
          top_hypos.append(hypos[i][top_index]["tokens"])
      return top_hypos, scores_to_export
  
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 4 for calling a global function with example usage: find_top_tokens(args, trans_batch_info, rescorer, pad) and returns: top_hypos,  scores_to_export