def compute_f1_from_labels(labels: List[Label]) -> Dict[str, float]:
  """Aggregates the metrics to overall change detection metrics.

  Args:
    labels: Label of each example

  Returns:
    Aggregated metrics over the change detection portion of the task.
  """
  true_pos = labels.count(Label.TRUE_POSITIVE)
  false_pos = labels.count(Label.FALSE_POSITIVE)
  false_neg = labels.count(Label.FALSE_NEGATIVE)
  true_neg = labels.count(Label.TRUE_NEGATIVE)
  if not true_pos:
    print("WARNING: No true positive predictions detected!")
    print(f"FP ({false_pos}) FN ({false_neg}) TN ({true_neg})")
    precision, recall, f1 = 0.0, 0.0, 0.0
  else:
    precision = true_pos / (true_pos + false_pos)
    recall = true_pos / (true_pos + false_neg)
    f1 = 2 * recall * precision / (recall + precision)
  acc = (true_pos + true_neg) / (false_pos + false_neg + true_pos + true_neg)
  return {
      "label_precision": precision,
      "label_recall": recall,
      "label_f1": f1,
      "label_acc": acc,
  }
Aggregates the metrics to overall change detection metrics.

  Args:
    labels: Label of each example

  Returns:
    Aggregated metrics over the change detection portion of the task.
  
language/diffqg/metrics.py