(predictions, labels, examples, metric)
| 73 | |
| 74 | |
| 75 | def squad_evaluate(predictions, labels, examples, metric): |
| 76 | assert len(examples) == len(predictions) |
| 77 | score = 0.0 |
| 78 | idx2predictions = {} |
| 79 | idx2ground_truths = {} |
| 80 | for example, prediction in zip(examples, predictions): |
| 81 | idx = example.idx |
| 82 | if idx not in idx2predictions: |
| 83 | idx2predictions[idx] = [] |
| 84 | idx2ground_truths[idx] = example.meta["answers"] |
| 85 | idx2predictions[idx].append(prediction) |
| 86 | # assert len(predictions) == len(idx2predictions) |
| 87 | for idx, predictions in idx2predictions.items(): |
| 88 | prediction = 'N/A' |
| 89 | for i in range(len(predictions)): |
| 90 | prediction = predictions[i] |
| 91 | if prediction.lower().replace(' ', '') == 'n/a': |
| 92 | prediction = 'N/A' |
| 93 | else: |
| 94 | break |
| 95 | ground_truths = idx2ground_truths[idx] |
| 96 | if len(ground_truths) == 1 and ground_truths[0] == 'N/A': |
| 97 | score += (prediction == 'N/A') |
| 98 | else: |
| 99 | score += metric_max_over_ground_truths(metric, prediction, ground_truths) |
| 100 | score = 100.0 * score / len(idx2predictions) |
| 101 | return score |
| 102 | |
| 103 | |
| 104 | def multirc_em(predictions, labels, examples: List[InputExample]): |
nothing calls this directly
no test coverage detected