docstr: Calculate the average loss for all aggregated batch
docstr_tok: ["Calculate","the","average","loss","for","all","aggregated","batch"]
code: def calculate_loss(self):
      """
      Calculate the average loss for all aggregated batch
      """
      loss_agg = {}
      for loss_name in self.all_loss.keys():
          if "samplewise" in loss_name:
              self.all_context.setdefault("losses", {})[
                  loss_name
              ] = np.concatenate(self.all_loss[loss_name], axis=None)
          else:
              loss_agg[loss_name] = np.average(
                  self.all_loss[loss_name], weights=self.batch_size
              )
  
      return loss_agg
  
imports: from collections import defaultdict
  from typing import Dict, List
  import numpy
  from pytext.common.constants import Stage
  from pytext.data.tensorizers import Tensorizer
  from pytext.metric_reporters.channel import ConsoleChannel
  from pytext.metric_reporters.compositional_metric_reporter import CompositionalMetricReporter
  from pytext.metric_reporters.seq2seq_compositional import CompositionalSeq2SeqFileChannel, Seq2SeqCompositionalMetricReporter
  from pytext.metrics.intent_slot_metrics import FramePredictionPair
  from pytext.metrics.mask_metrics import compute_masked_metrics, compute_nas_masked_metrics
  from .compositional_utils import extract_beam_subtrees, filter_invalid_beams
label_desc: Use image node_id 5 for calling the MaskedSeq2SeqCompositionalMetricReporter obj's underlying member method code with example usage: obj.calculate_loss() and returns: loss_agg