def str_em(predictions, asqa, target_keys=None):
  """Compute STR-EM metric.

  Args:
    predictions: {key: answer} dictionary of predicted answers
    asqa: dict representation of asqa
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    Value of the STR-EM metric
  """
  acc = []

  for key, context in predictions.items():
    if target_keys is not None and key not in target_keys:
      continue

    loc_acc = []

    for qa_pair in asqa[key]['qa_pairs']:
      loc_acc.append(_exact_presence(qa_pair['short_answers'], context))

    acc.append(np.mean(loc_acc))

  return 100 * np.mean(acc)
Compute STR-EM metric.

  Args:
    predictions: {key: answer} dictionary of predicted answers
    asqa: dict representation of asqa
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    Value of the STR-EM metric
  
language/asqa/scoring.py