Taken from the official evaluation script for v1.1 of the SQuAD dataset.
(prediction, ground_truth)
| 86 | |
| 87 | |
| 88 | def token_f1_score(prediction, ground_truth): |
| 89 | """ |
| 90 | Taken from the official evaluation script for v1.1 of the SQuAD dataset. |
| 91 | """ |
| 92 | prediction_tokens = normalize_answer(prediction).split() |
| 93 | ground_truth_tokens = normalize_answer(ground_truth).split() |
| 94 | common = Counter(prediction_tokens) & Counter(ground_truth_tokens) |
| 95 | num_same = sum(common.values()) |
| 96 | if num_same == 0: |
| 97 | return 0 |
| 98 | precision = 1.0 * num_same / len(prediction_tokens) |
| 99 | recall = 1.0 * num_same / len(ground_truth_tokens) |
| 100 | f1 = (2 * precision * recall) / (precision + recall) |
| 101 | return f1 |
| 102 | |
| 103 | |
| 104 | class QASPER(Task): |
no test coverage detected