Spaces:
Runtime error
Runtime error
Download evaluation/evaluate_utils/utils.py from AssistantBench/leaderboard: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/spaces/AssistantBench/leaderboard/resolve/refs%2Fpr%2F5/evaluation/evaluate_utils/utils.py
- Command line
-
hf download hf://spaces/AssistantBench/leaderboard@refs/pr/5/evaluation/evaluate_utils/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/AssistantBench/leaderboard/resolve/refs%2Fpr%2F5/evaluation/evaluate_utils/utils.py
916 Bytes
| from typing import List, Set, Tuple, Union, Callable | |
| import numpy as np | |
| from scipy.optimize import linear_sum_assignment | |
| def _align_bags( | |
| predicted: List[Set[str]], | |
| gold: List[Set[str]], | |
| method: Callable[[object, object], float], | |
| ) -> List[float]: | |
| """ | |
| 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. | |
| """ | |
| scores = np.zeros([len(gold), len(predicted)]) | |
| for gold_index, gold_item in enumerate(gold): | |
| for pred_index, pred_item in enumerate(predicted): | |
| scores[gold_index, pred_index] = method(pred_item, gold_item) | |
| row_ind, col_ind = linear_sum_assignment(-scores) | |
| max_scores = np.zeros([max(len(gold), len(predicted))]) | |
| for row, column in zip(row_ind, col_ind): | |
| max_scores[row] = max(max_scores[row], scores[row, column]) | |
| return max_scores | |