Spaces:
Sleeping
Sleeping
nb
commited on
Commit
·
6ab874f
1
Parent(s):
c78d126
Add waf metric logic
Browse files- waf_metric.py +24 -11
waf_metric.py
CHANGED
@@ -62,7 +62,6 @@ class WafMetric(evaluate.Metric):
|
|
62 |
"""TODO: Short description of my evaluation module."""
|
63 |
|
64 |
def _info(self):
|
65 |
-
# TODO: Specifies the evaluate.EvaluationModuleInfo object
|
66 |
return evaluate.MetricInfo(
|
67 |
# This is the description that will appear on the modules page.
|
68 |
module_type="metric",
|
@@ -70,26 +69,40 @@ class WafMetric(evaluate.Metric):
|
|
70 |
citation=_CITATION,
|
71 |
inputs_description=_KWARGS_DESCRIPTION,
|
72 |
# This defines the format of each prediction and reference
|
73 |
-
features=datasets.Features(
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
77 |
# Homepage of the module for documentation
|
78 |
homepage="http://module.homepage",
|
79 |
# Additional links to the codebase or references
|
80 |
codebase_urls=["http://github.com/path/to/codebase/of/new_module"],
|
81 |
-
reference_urls=["http://path.to.reference.url/new_module"]
|
82 |
)
|
83 |
|
84 |
def _download_and_prepare(self, dl_manager):
|
85 |
"""Optional: download external resources useful to compute the scores"""
|
86 |
-
# TODO: Download external resources if needed
|
87 |
pass
|
88 |
|
89 |
def _compute(self, predictions, references):
|
90 |
"""Returns the scores"""
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
return {
|
94 |
-
"
|
95 |
-
|
|
|
|
62 |
"""TODO: Short description of my evaluation module."""
|
63 |
|
64 |
def _info(self):
|
|
|
65 |
return evaluate.MetricInfo(
|
66 |
# This is the description that will appear on the modules page.
|
67 |
module_type="metric",
|
|
|
69 |
citation=_CITATION,
|
70 |
inputs_description=_KWARGS_DESCRIPTION,
|
71 |
# This defines the format of each prediction and reference
|
72 |
+
features=datasets.Features(
|
73 |
+
{
|
74 |
+
"predictions": datasets.Value("int64"),
|
75 |
+
"references": datasets.Value("int64"),
|
76 |
+
}
|
77 |
+
),
|
78 |
# Homepage of the module for documentation
|
79 |
homepage="http://module.homepage",
|
80 |
# Additional links to the codebase or references
|
81 |
codebase_urls=["http://github.com/path/to/codebase/of/new_module"],
|
82 |
+
reference_urls=["http://path.to.reference.url/new_module"],
|
83 |
)
|
84 |
|
85 |
def _download_and_prepare(self, dl_manager):
|
86 |
"""Optional: download external resources useful to compute the scores"""
|
|
|
87 |
pass
|
88 |
|
89 |
def _compute(self, predictions, references):
|
90 |
"""Returns the scores"""
|
91 |
+
white_cnt = 0
|
92 |
+
black_cnt = 0
|
93 |
+
false_white = 0
|
94 |
+
true_black = 0
|
95 |
+
for i, j in zip(predictions, references):
|
96 |
+
if j == 0:
|
97 |
+
white_cnt += 1
|
98 |
+
if i != j:
|
99 |
+
false_white += 1
|
100 |
+
else:
|
101 |
+
black_cnt += 1
|
102 |
+
if i == j:
|
103 |
+
true_black += 1
|
104 |
+
|
105 |
return {
|
106 |
+
"precision": false_white / (white_cnt + 1e-6),
|
107 |
+
"recall": true_black / (black_cnt + 1e-6),
|
108 |
+
}
|