class_docstr: Translation rerank task.
  The input can be either (src, tgt) sentence pairs or tgt sentence only.
class_docstr_tok: ["Translation","rerank","task",".","The","input","can","be","either","(","src",",","tgt",")","sentence","pairs","or","tgt","sentence","only","."]
code: def reduce_metrics(self, logging_outputs, criterion):
      super().reduce_metrics(logging_outputs, criterion)
  
      if not self.cfg.eval_target_metric:
          return
  
      def sum_logs(key):
          return sum(log.get(key, 0) for log in logging_outputs)
  
      if self.cfg.target_metric == "bleu":
          counts, totals = [], []
          for i in range(EVAL_BLEU_ORDER):
              counts.append(sum_logs("_bleu_counts_" + str(i)))
              totals.append(sum_logs("_bleu_totals_" + str(i)))
  
          if max(totals) > 0:
              # log counts as numpy arrays -- log_scalar will sum them correctly
              metrics.log_scalar("_bleu_counts", np.array(counts))
              metrics.log_scalar("_bleu_totals", np.array(totals))
              metrics.log_scalar(
                  "_bleu_sys_len", sum_logs("_bleu_sys_len")
              )
              metrics.log_scalar(
                  "_bleu_ref_len", sum_logs("_bleu_ref_len")
              )
  
              def compute_bleu(meters):
                  import inspect
                  import sacrebleu
  
                  fn_sig = inspect.getfullargspec(
                      sacrebleu.compute_bleu
                  )[0]
                  if "smooth_method" in fn_sig:
                      smooth = {"smooth_method": "exp"}
                  else:
                      smooth = {"smooth": "exp"}
                  bleu = sacrebleu.compute_bleu(
                      correct=meters["_bleu_counts"].sum,
                      total=meters["_bleu_totals"].sum,
                      sys_len=meters["_bleu_sys_len"].sum,
                      ref_len=meters["_bleu_ref_len"].sum,
                      **smooth,
                  )
                  return round(bleu.score, 2)
  
              metrics.log_derived("bleu", compute_bleu)
      elif self.cfg.target_metric == "ter":
          num_edits = sum_logs("_ter_num_edits")
          ref_len = sum_logs("_ter_ref_len")
  
          if ref_len > 0:
              metrics.log_scalar("_ter_num_edits", num_edits)
              metrics.log_scalar("_ter_ref_len", ref_len)
  
              def compute_ter(meters):
                  score = (
                      meters["_ter_num_edits"].sum
                      / meters["_ter_ref_len"].sum
                  )
                  return round(score.item(), 2)
  
              metrics.log_derived("ter", compute_ter)
  
imports: from dataclasses import dataclass, field
  import itertools
  import logging
  import os
  import numpy
  import torch
  from fairseq.logging import metrics
  from fairseq.data import ConcatDataset, ConcatSentencesDataset, data_utils, Dictionary, IdDataset, indexed_dataset, NestedDictionaryDataset, NumSamplesDataset, NumelDataset, PrependTokenDataset, RawLabelDataset, RightPadDataset, SortDataset, TruncateDataset, TokenBlockDataset
  from fairseq.dataclass import ChoiceEnum, FairseqDataclass
  from fairseq.tasks import FairseqTask, register_task
  from omegaconf import II, MISSING
label_desc: Use image node_id 14 for calling the DiscriminativeRerankingNMTTask obj's underlying member method code with example usage: obj.reduce_metrics(logging_outputs, criterion) and returns: sum, round, round