Spaces:
Sleeping
Sleeping
John Graham Reynolds
commited on
Commit
·
7ca7f15
1
Parent(s):
709f580
update f1 file and load directly from imported class
Browse files- __init__.py +5 -0
- app.py +2 -1
- fixed_f1.py +19 -4
__init__.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fixed_f1 import FixedF1
|
2 |
+
|
3 |
+
__all__ = [
|
4 |
+
"FixedF1"
|
5 |
+
]
|
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import evaluate
|
2 |
from evaluate.utils import launch_gradio_widget
|
|
|
3 |
|
4 |
|
5 |
-
module =
|
6 |
launch_gradio_widget(module)
|
|
|
1 |
import evaluate
|
2 |
from evaluate.utils import launch_gradio_widget
|
3 |
+
from fixed_f1 import FixedF1
|
4 |
|
5 |
|
6 |
+
module = FixedF1()
|
7 |
launch_gradio_widget(module)
|
fixed_f1.py
CHANGED
@@ -4,6 +4,13 @@ from evaluate import evaluator, Metric
|
|
4 |
# from evaluate.metrics.f1 import F1
|
5 |
from sklearn.metrics import f1_score
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
_CITATION = """
|
9 |
@online{MarioBarbeque@HuggingFace,
|
@@ -15,7 +22,15 @@ _CITATION = """
|
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
class FixedF1(evaluate.Metric):
|
20 |
|
21 |
def __init__(self, average="binary"):
|
@@ -25,9 +40,9 @@ class FixedF1(evaluate.Metric):
|
|
25 |
|
26 |
def _info(self):
|
27 |
return evaluate.MetricInfo(
|
28 |
-
description=
|
29 |
-
citation=
|
30 |
-
inputs_description=
|
31 |
features=datasets.Features(
|
32 |
{
|
33 |
"predictions": datasets.Sequence(datasets.Value("int32")),
|
|
|
4 |
# from evaluate.metrics.f1 import F1
|
5 |
from sklearn.metrics import f1_score
|
6 |
|
7 |
+
_DESCRIPTION = """
|
8 |
+
Custom built F1 metric that accept underlying kwargs at instantiation time.
|
9 |
+
This class allows one to circumvent the current issue of `combine`-ing the f1 metric, instantiated with its own parameters, into a `CombinedEvaluations` class with other metrics.
|
10 |
+
|
11 |
+
In general, the F1 score is the harmonic mean of the precision and recall. It can be computed with the equation:
|
12 |
+
F1 = 2 * (precision * recall) / (precision + recall)
|
13 |
+
"""
|
14 |
|
15 |
_CITATION = """
|
16 |
@online{MarioBarbeque@HuggingFace,
|
|
|
22 |
}
|
23 |
"""
|
24 |
|
25 |
+
_INPUTS = """
|
26 |
+
'average': This parameter is required for multiclass/multilabel targets.
|
27 |
+
If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data.
|
28 |
+
Options include: {‘micro’, ‘macro’, ‘samples’, ‘weighted’, ‘binary’} or None.
|
29 |
+
"""
|
30 |
+
|
31 |
+
# could in principle subclass the F1 Metric, but ideally we can work the fix into the HF main F1 class to maintain SOLID code
|
32 |
+
# for this fix we create a new class
|
33 |
+
|
34 |
class FixedF1(evaluate.Metric):
|
35 |
|
36 |
def __init__(self, average="binary"):
|
|
|
40 |
|
41 |
def _info(self):
|
42 |
return evaluate.MetricInfo(
|
43 |
+
description=_DESCRIPTION,
|
44 |
+
citation=_CITATION,
|
45 |
+
inputs_description=_INPUTS,
|
46 |
features=datasets.Features(
|
47 |
{
|
48 |
"predictions": datasets.Sequence(datasets.Value("int32")),
|