MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / _align_bags

Method _align_bags

test/general/lm_eval/tasks/drop.py:196–213  ·  view source on GitHub ↗

Takes gold and predicted answer sets and first finds the optimal 1-1 alignment between them and gets maximum metric values over all the answers.

(self, predicted, gold)

Source from the content-addressed store, hash-verified

194 return normalized_spans, token_bags
195
196 def _align_bags(self, predicted, gold):
197 """
198 Takes gold and predicted answer sets and first finds the optimal 1-1 alignment
199 between them and gets maximum metric values over all the answers.
200 """
201 scores = np.zeros([len(gold), len(predicted)])
202 for gold_index, gold_item in enumerate(gold):
203 for pred_index, pred_item in enumerate(predicted):
204 if self._match_numbers_if_present(gold_item, pred_item):
205 scores[gold_index, pred_index] = self._compute_f1(
206 pred_item, gold_item
207 )
208 row_ind, col_ind = linear_sum_assignment(-scores)
209
210 max_scores = np.zeros([max(len(gold), len(predicted))])
211 for row, column in zip(row_ind, col_ind):
212 max_scores[row] = max(max_scores[row], scores[row, column])
213 return max_scores
214
215 def _compute_f1(self, predicted_bag, gold_bag):
216 intersection = len(gold_bag.intersection(predicted_bag))

Callers 1

get_metricsMethod · 0.95

Calls 2

_compute_f1Method · 0.95

Tested by

no test coverage detected