code: def evaluate_weights(scores_info, feature_weights, length_penalty):
      scorer = bleu.Scorer(
          bleu.BleuConfig(
              pad=vocab_constants.PAD_ID,
              eos=vocab_constants.EOS_ID,
              unk=vocab_constants.UNK_ID,
          )
      )
  
      for example in scores_info:
          weighted_scores = (example["scores"] * feature_weights).sum(
              axis=1
          )
          weighted_scores /= (
              example["tgt_len"] ** length_penalty
          ) + 1e-12
          top_hypo_ind = np.argmax(weighted_scores)
          top_hypo = example["hypos"][top_hypo_ind]
          ref = example["target_tokens"]
          scorer.add(torch.IntTensor(ref), torch.IntTensor(top_hypo))
  
      return scorer.score()
  
file_path: translate/pytorch_translate/rescoring/weights_search.py
imports: import argparse
  import pickle
  import numpy
  import torch
  from fairseq.scoring import bleu
  from pytorch_translate import vocab_constants
  from pytorch_translate.data.dictionary import Dictionary
  from pytorch_translate.generate import smoothed_sentence_bleu
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate_weights(scores_info, feature_weights, length_penalty) and returns: scorer