(prediction, ground_truth)
| 34 | |
| 35 | |
| 36 | def f1_score(prediction, ground_truth): |
| 37 | prediction_tokens = normalize_answer(prediction).split() |
| 38 | ground_truth_tokens = normalize_answer(ground_truth).split() |
| 39 | common = Counter(prediction_tokens) & Counter(ground_truth_tokens) |
| 40 | num_same = sum(common.values()) |
| 41 | if num_same == 0: |
| 42 | return 0 |
| 43 | precision = 1.0 * num_same / len(prediction_tokens) |
| 44 | recall = 1.0 * num_same / len(ground_truth_tokens) |
| 45 | f1 = (2 * precision * recall) / (precision + recall) |
| 46 | return f1 |
| 47 | |
| 48 | |
| 49 | def exact_match_score(prediction, ground_truth): |
no test coverage detected