class_docstr: Base class for criteria with need to run beam search.
class_docstr_tok: ["Base","class","for","criteria","with","need","to","run","beam","search","."]
docstr: Aggregate logging outputs from data parallel training.
docstr_tok: ["Aggregate","logging","outputs","from","data","parallel","training","."]
code: def aggregate_logging_outputs(logging_outputs):
      """Aggregate logging outputs from data parallel training."""
      sample_size = sum(
          log.get("sample_size", 0) for log in logging_outputs
      )
      ntokens = sum(log.get("ntokens", 0) for log in logging_outputs)
      nsentences = sum(
          log.get("nsentences", 0) for log in logging_outputs
      )
      return {
          "loss": sum(log.get("loss", 0) for log in logging_outputs)
          / sample_size
          / math.log(2),
          "ntokens": ntokens,
          "nsentences": nsentences,
          "sample_size": sample_size,
      }
  
imports: import copy
  import math
  import torch
  from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
  from fairseq.scoring import bleu
  from pytorch_translate import generate
label_desc: Use image node_id 6 for calling the BaseSequenceLossCriterion obj's underlying member method code with example usage: obj.aggregate_logging_outputs(logging_outputs) and returns: dict