def score_qa_accuracy(predictions, asqa, target_keys=None):
  """Compute QA metrics.

  Args:
    predictions: {qa_key: short_answer} output of ROBERTA predictions of short
      answers to disambiguated questions
    asqa: dict representation of the asqa dataset
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    QA metrics (QA-EM, QA-F1, QA-Hit)
  """

  em, f1, bins = [], [], []

  for key, instance in asqa.items():

    if target_keys is not None and key not in target_keys:
      continue

    loc_counter, loc_em, loc_f1 = 0, 0, 0

    for idx, qa_pair in enumerate(instance['qa_pairs']):
      answers = qa_pair['short_answers']
      full_key = key + '_' + str(idx)
      prediction = predictions[full_key]

      if not isinstance(prediction, list):
        prediction = [prediction]

      loc_em += max([_compute_exact(a, p) for a in answers for p in prediction])
      loc_f1 += max([_compute_f1(a, p) for a in answers for p in prediction])

      loc_counter += 1

    em.append(loc_em / loc_counter)
    f1.append(loc_f1 / loc_counter)
    bins.append(loc_em == loc_counter)

  return {
      'QA-EM': 100 * np.mean(em),
      'QA-F1': 100 * np.mean(f1),
      'QA-Hit': 100 * np.mean(bins)
  }
Compute QA metrics.

  Args:
    predictions: {qa_key: short_answer} output of ROBERTA predictions of short
      answers to disambiguated questions
    asqa: dict representation of the asqa dataset
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    QA metrics (QA-EM, QA-F1, QA-Hit)
  
language/asqa/scoring.py