class_docstr: This criterion computes losses from input (monolingual data in
  translation) with two components:
  1. Reconstruction loss:
  2. LM loss:
  The total loss is a weighted sum of these two components.
class_docstr_tok: ["This","criterion","computes","losses","from","input","(","monolingual","data","in","translation",")","with","two","components",":","1",".","Reconstruction","loss",":","2",".","LM","loss",":","The","total","loss","is","a","weighted","sum","of","these","two","components","."]
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."""
  
      def get_logging_output(key):
          if key in logging_outputs[0].keys():
              return logging_outputs[0][key]
          else:
              return sum(
                  log[key] if key in log else 0
                  for _, log in logging_outputs[0].items()
              )
  
      loss_sum = get_logging_output("loss")
      ntokens = get_logging_output("ntokens")
      nsentences = get_logging_output("nsentences")
      sample_size = get_logging_output("sample_size")
      agg_output = {
          "loss": loss_sum / sample_size / math.log(2),
          "ntokens": ntokens,
          "nsentences": nsentences,
          "sample_size": sample_size,
      }
      if sample_size != ntokens:
          agg_output["nll_loss"] = loss_sum / ntokens / math.log(2)
      return agg_output
  
file_path: translate/pytorch_translate/dual_learning/dual_learning_criterion.py
imports: import math
  import torch
  from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
  from fairseq.scoring import bleu
  from pytorch_translate import beam_decode
  from pytorch_translate.data.weighted_data import WeightedLanguagePairDataset
label_desc: Use image node_id 6 for calling the UnsupervisedCriterion obj's underlying member method code with example usage: obj.aggregate_logging_outputs(logging_outputs) and returns: agg_output, logging_outputs, sum