code: def evaluate_single_dense_captions(
      predicted_segments,
      gt_segments,
      predictions_filtered,
      ground_truths_filtered,
      predicted_captions,
      gt_captions,
      splits,
      keys,
      iou_thresholds=(0.3, 0.5, 0.7, 0.9),
      soda=False,
      tmponly=False,
      scorers=None,
  ):
      """Compute both the P/R and NLP metrics for the given predictions.
  
      Args:
       predicted_segments: A numpy arrays, of shape [K x 2]
         containing the predicted segment intervals.
       gt_segments: A numpy arrays, of shape [S x 2]
         containing the ground truth segment intervals.
       predictions_filtered: Matching list of predicted captions for each threshold.
       ground_truths_filtered: Filtered list of ground truth captions for each
        threshold.
       predicted_captions: A list, of string of shape [K]
         containing the corresponding K predicted captions.
       gt_captions: A list, of strings of shape [S] containing the
         corresponding S ground truth captions.
       splits: A numpy array, of shape [S] indicating
         the annotation set (1/2 for ActivityNet).
       keys: A string
       iou_thresholds: A list of thresholds for IOU to average over.
       soda: Whether to compute SODA or not.
       tmponly: In this case do not compute captioning metrics.
       scorers: dictionary mapping strings to scorers.
  
      Returns:
        (precision, recall): The precision and recall of the detections averaged
        over the IOU thresholds.
        metrics: The NLP metrics of the predictions averaged over the IOU
          thresholds.
      """
      if scorers is None:
          scorers = {}
  
      # Localization
      (
          detection_precision,
          detection_recall,
          iou_matrices,
      ) = evaluate_detections(
          predicted_segments, gt_segments, splits, iou_thresholds
      )
  
      # Captions
      n_preds = len(predicted_captions)
      if not tmponly:
          metric_tiou = evaluate_caption_scores(
              ground_truths_filtered,
              predictions_filtered,
              iou_thresholds,
              scorers,
          )
          if soda:
              fs = sodac(
                  iou_matrices,
                  scorers["METEOR"],
                  predicted_captions,
                  gt_captions,
                  splits,
                  (0.0,),
              )
      else:
          metric_tiou = {}
  
      mean_precision = sum(detection_precision) / len(
          detection_precision
      )
      mean_recall = sum(detection_recall) / len(detection_recall)
      for j, threshold in enumerate(iou_thresholds):
          metric_tiou[f"Precision@{threshold}"] = float(
              detection_precision[j]
          )
          metric_tiou[f"Recall@{threshold}"] = float(
              detection_recall[j]
          )
      metric_tiou["Precision_Mean"] = float(mean_precision)
      metric_tiou["Recall_Mean"] = float(mean_recall)
      metric_tiou["F1_Score"] = (
          2
          * float(mean_recall)
          * float(mean_precision)
          / (float(mean_recall) + float(mean_precision))
          if float(mean_recall) + float(mean_precision) > 0
          else 0
      )
      if soda and not tmponly:
          for split in fs:
              metric_tiou[f"SODA_c_{split}"] = float(fs[split])
      metric_tiou["n_preds"] = n_preds
      metric_tiou["key"] = keys
  
      return metric_tiou
  
imports: import collections
  import logging
  import random
  import re
  import string
  import numpy
  from scenic.projects.vid2seq.metrics.cider import Cider
  from scenic.projects.vid2seq.metrics.meteor import Meteor
  from scenic.projects.vid2seq.metrics.ptbtokenizer import PTBTokenizer
label_desc: Use image node_id 11 for calling a global function with example usage: evaluate_single_dense_captions(predicted_segments, gt_segments, predictions_filtered, ground_truths_filtered, predicted_captions, gt_captions, splits, keys, iou_thresholds, soda, tmponly, scorers) and returns: metric_tiou