def rare_relation_scores(relationwise, relation2counts):
  """Print statistics of rare relations for different thresholds."""
  for thresh in [5, 100, 500, 1000]:
    freq_stats, freq_total = np.array([0., 0., 0.]), 0
    rare_stats, rare_total = np.array([0., 0., 0.]), 0
    for relation, (stats, _) in relationwise.items():
      if relation2counts.get(relation, 0) < thresh:
        rare_stats += stats
        rare_total += 1
      else:
        freq_stats += stats
        freq_total += 1
    rare_stats /= rare_total
    freq_stats /= freq_total
    print(
        "Threshold =", thresh, "rare", rare_total,
        "Micro-P %.3f Micro-R %.3f Micro-F %.3f" %
        (rare_stats[0], rare_stats[1], rare_stats[2]), "freq", freq_total,
        "Micro-P %.3f Micro-R %.3f Micro-F %.3f" %
        (freq_stats[0], freq_stats[1], freq_stats[2]))
Print statistics of rare relations for different thresholds.
language/labs/drkit/evaluate.py