def qa_score(spans, answers):
  """Compute official exact match and F1 scores.

  Args:
    spans: Dictionary of image_id --> question_id --> list(span).
    answers: Dictionary of image_id --> question_id --> list(answers).

  Returns:
    results: Dictionary of exact_match and f1_score.
  """
  em = f1 = total = 0.0
  for image_id, questions in spans.items():
    for question_id, spans in questions.items():
      ground_truths = answers[image_id][question_id]
      em += metric_max_over_ground_truths(compute_em, spans, ground_truths)
      f1 += metric_max_over_ground_truths(compute_f1, spans, ground_truths)
      total += 1
  results = dict(exact_match=em / total, f1_score=f1 / total)
  tf.logging.info("Computed QA score on %d values.", total)
  return results
Compute official exact match and F1 scores.

  Args:
    spans: Dictionary of image_id --> question_id --> list(span).
    answers: Dictionary of image_id --> question_id --> list(answers).

  Returns:
    results: Dictionary of exact_match and f1_score.
  
language/capwap/utils/metric_utils.py