code: def match_captions(
      predicted_segments,
      gt_segments,
      predicted_captions,
      gt_captions,
      iou_thresholds=(0.3, 0.5, 0.7, 0.9),
  ):
      """Matches the predicted captions to ground truth using the IOU thresholds.
  
      Args:
       predicted_segments: A numpy array of shape [K x 2] containing the predicted
         segment intervals.
       gt_segments: A numpy array of shape [S x 2] containing the ground truth
         segment intervals.
       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.
       iou_thresholds: A list of thresholds for IOU to average over.
  
      Returns:
       ground_truths_filtered: Filtered list of ground truth captions for all
        threshold.
       predictions_filtered: Matching list of predicted captions for all
        threshold.
       isxes: For each threshold, contains lists of isx of matches.
      """
  
      # Setup a set of dictionaries to hold the results.
      ground_truths_filtered = {
          str(threshold): {} for threshold in iou_thresholds
      }
      predictions_filtered = {
          str(threshold): {} for threshold in iou_thresholds
      }
  
      # Create GT lists for each of the IOU thresholds.
      isx = 0
      isxes = {str(threshold): [] for threshold in iou_thresholds}
      for idx_p, segment in enumerate(predicted_segments):
          pc_idxp = predicted_captions[idx_p]
          added = {
              str(threshold): False for threshold in iou_thresholds
          }
          for idx_g, gt_segment in enumerate(gt_segments):
              gt_idxg = gt_captions[idx_g]
              sample_iou = iou(segment, gt_segment)
              for threshold in iou_thresholds:
                  if sample_iou >= threshold:
                      key = str(isx)
                      isxes[str(threshold)].append(isx)
                      isx += 1
                      ground_truths_filtered[str(threshold)][key] = [
                          {"caption": gt_idxg}
                      ]
                      predictions_filtered[str(threshold)][key] = [
                          {"caption": pc_idxp}
                      ]
                      added[str(threshold)] = True
          for threshold in iou_thresholds:
              if not added[str(threshold)]:
                  key = str(isx)
                  isxes[str(threshold)].append(isx)
                  isx += 1
                  # Set this to a random string with no match to the predictions to
                  # get a zero score
                  ground_truths_filtered[str(threshold)][key] = [
                      {"caption": random_string(random.randint(10, 20))}
                  ]
                  predictions_filtered[str(threshold)][key] = [
                      {"caption": pc_idxp}
                  ]
  
      return ground_truths_filtered, predictions_filtered, isxes
  
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 7 for calling a global function with example usage: match_captions(predicted_segments, gt_segments, predicted_captions, gt_captions, iou_thresholds) and returns: ground_truths_filtered,  predictions_filtered,  isxes