Upload eval_utils.py with huggingface_hub
Browse files- eval_utils.py +21 -0
eval_utils.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
from .operator import SequentialOperator
|
6 |
+
from .stream import MultiStream
|
7 |
+
|
8 |
+
|
9 |
+
def evaluate(dataset: pd.DataFrame, metric_names: List[str]):
|
10 |
+
result = dataset.copy()
|
11 |
+
# prepare the input stream
|
12 |
+
for metric_name in metric_names:
|
13 |
+
multi_stream = MultiStream.from_iterables(
|
14 |
+
{"test": dataset.to_dict("records")}, copying=True
|
15 |
+
)
|
16 |
+
metrics_operator = SequentialOperator(steps=[metric_name])
|
17 |
+
instances = list(metrics_operator(multi_stream)["test"])
|
18 |
+
result[metric_name] = [
|
19 |
+
instance["score"]["instance"]["score"] for instance in instances
|
20 |
+
]
|
21 |
+
return result
|