Calculates and returns metrics.
(
references_path,
predictions_path,
is_regex,
answer_field="answer")
| 107 | |
| 108 | |
| 109 | def evaluate_predictions( |
| 110 | references_path, |
| 111 | predictions_path, |
| 112 | is_regex, |
| 113 | answer_field="answer"): |
| 114 | """Calculates and returns metrics.""" |
| 115 | if is_regex != ("CuratedTrec" in references_path): |
| 116 | print("Warning: regex evaluation should (only) be applied to CuratedTrec.") |
| 117 | |
| 118 | references = {} |
| 119 | with open(references_path, 'r', encoding='utf-8') as f: |
| 120 | for line in f: |
| 121 | example = json.loads(line) |
| 122 | references[example["question"]] = example[answer_field] |
| 123 | print("Found {} references in {}".format(len(references), references_path)) |
| 124 | |
| 125 | predictions = {} |
| 126 | with open(predictions_path, 'r', encoding='utf-8') as f: |
| 127 | for line in f: |
| 128 | example = json.loads(line) |
| 129 | predictions[example["question"]] = example["prediction"] |
| 130 | # predictions[example["question"]] = find_last_uppercase_abcd(example["fuse_generation"]) |
| 131 | # predictions[example["question"]] = example["fuse_generation"] |
| 132 | # predictions[example["question"]] = example["best"] |
| 133 | print("Found {} predictions in {}".format(len(predictions), predictions_path)) |
| 134 | |
| 135 | return evaluate_predictions_impl( |
| 136 | references=references, predictions=predictions, is_regex=is_regex) |
nothing calls this directly
no test coverage detected