MCPcopy Create free account
hub / github.com/THUDM/GLM / squad_evaluate

Function squad_evaluate

tasks/superglue/evaluate.py:75–101  ·  view source on GitHub ↗
(predictions, labels, examples, metric)

Source from the content-addressed store, hash-verified

73
74
75def 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
104def multirc_em(predictions, labels, examples: List[InputExample]):

Callers

nothing calls this directly

Calls 2

appendMethod · 0.80

Tested by

no test coverage detected