code: def deduplicate_metric(
      metric_fn, group_key: str = "group", value_key: str = "value"
  ):
      """Returns a metric that only considers one example per group.
  
      Useful for things like ReCoRD where inputs may be replicated during training
      to handle multiple labels, but where at eval we only want a single copy of
      each example.
  
      Args:
        metric_fn: function, the metric to compute on the unique examples.
        group_key: the key for the grouping value in the target dictionary.
        value_key: the key for the value in the dictionaries.
  
      Returns:
        A metric function that deduplicated based on the grouping key before
        returning a metric.
      """
  
      def _deduplicated_metric(targets, predictions):
          """Deduplicate targets and predictions and pass that to the metric fn."""
          processed_groups = set()
          deduplicated_targets = []
          deduplicated_predictions = []
          for targ, pred in zip(targets, predictions):
              group = targ[group_key]
              if group in processed_groups:
                  continue
              processed_groups.add(group)
              deduplicated_targets.append(targ[value_key])
              deduplicated_predictions.append(pred[value_key])
          return metric_fn(
              deduplicated_targets, deduplicated_predictions
          )
  
      return _deduplicated_metric
  
imports: import collections
  import itertools
  import re
  import string
  from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union
  from absl import logging
  import editdistance
  import flax
  import jax.numpy
  import numpy
  import sacrebleu
  import scipy.stats
  import seqio
  import sklearn.metrics
  from t5.evaluation import qa_utils
  import tensorflow.compat.v2
  from rouge_score import rouge_scorer
  from rouge_score import scoring
label_desc: Use image node_id 15 for calling a global function with example usage: deduplicate_metric(metric_fn, group_key, value_key) and returns: _deduplicated_metric, metric_fn