code: def calculate_gap(predictions, actuals, top_k=20):
      """Performs a local (numpy) calculation of the global average precision.
  
      Only the top_k predictions are taken for each of the videos.
  
      Args:
        predictions: Matrix containing the outputs of the model.
          Dimensions are 'batch' x 'num_classes'.
        actuals: Matrix containing the ground truth labels.
          Dimensions are 'batch' x 'num_classes'.
        top_k: How many predictions to use per video.
  
      Returns:
        float: The global average precision.
      """
      gap_calculator = ap_calculator.AveragePrecisionCalculator()
      sparse_predictions, sparse_labels, num_positives = top_k_by_class(
          predictions, actuals, top_k
      )
      gap_calculator.accumulate(
          flatten(sparse_predictions),
          flatten(sparse_labels),
          sum(num_positives),
      )
      return gap_calculator.peek_ap_at_n()
  
file_path: PaddleHub/modules/video/classification/videotag_tsn_lstm/resource/metrics/youtube8m/eval_util.py
imports: import datetime
  import numpy
  from .None import mean_average_precision_calculator
  from .None import average_precision_calculator
label_desc: Use image node_id 4 for calling a global function with example usage: calculate_gap(predictions, actuals, top_k) and returns: gap_calculator