def compute_set_f1(pred_set, gold_set):
  """Computes F1 of items given two sets of items."""
  prec = 1.
  if pred_set:
    prec = float(len(pred_set & gold_set)) / len(pred_set)

  rec = 1.
  if gold_set:
    rec = float(len(pred_set & gold_set)) / len(gold_set)
  return compute_f1(prec, rec)
Computes F1 of items given two sets of items.
language/xsp/evaluation/official_evaluation.py