update compute
Browse files- charmatch.py +23 -28
charmatch.py
CHANGED
@@ -71,9 +71,9 @@ class charmatch(evaluate.Metric):
|
|
71 |
inputs_description="input expected output",
|
72 |
# This defines the format of each prediction and reference
|
73 |
features=datasets.Features({
|
74 |
-
'
|
75 |
-
'expected': datasets.
|
76 |
-
'
|
77 |
}),
|
78 |
# Homepage of the module for documentation
|
79 |
homepage="http://module.homepage",
|
@@ -87,35 +87,30 @@ class charmatch(evaluate.Metric):
|
|
87 |
# TODO: Download external resources if needed
|
88 |
pass
|
89 |
|
90 |
-
def _compute(
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
95 |
return 1.0
|
96 |
-
elif len(deduped) == 2:
|
97 |
-
if expected == output:
|
98 |
-
return 1.0
|
99 |
-
else:
|
100 |
-
return 0.0
|
101 |
else:
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
106 |
|
107 |
-
|
108 |
-
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
return f_05
|
116 |
-
|
117 |
-
avg = sum([get_score(*row) for row in zip(inputs, expected, outputs)]) / len(inputs) * 100
|
118 |
|
119 |
return {
|
120 |
-
"fscore":
|
121 |
}
|
|
|
71 |
inputs_description="input expected output",
|
72 |
# This defines the format of each prediction and reference
|
73 |
features=datasets.Features({
|
74 |
+
'input': datasets.Value('string'),
|
75 |
+
'expected': datasets.Value('string'),
|
76 |
+
'output': datasets.Value('string')
|
77 |
}),
|
78 |
# Homepage of the module for documentation
|
79 |
homepage="http://module.homepage",
|
|
|
87 |
# TODO: Download external resources if needed
|
88 |
pass
|
89 |
|
90 |
+
def _compute(input, expected, output):
|
91 |
+
print(input, expected, output)
|
92 |
+
deduped = {input, expected, output}
|
93 |
+
if len(deduped) == 1:
|
94 |
+
return 1.0
|
95 |
+
elif len(deduped) == 2:
|
96 |
+
if expected == output:
|
97 |
return 1.0
|
|
|
|
|
|
|
|
|
|
|
98 |
else:
|
99 |
+
return 0.0
|
100 |
+
else:
|
101 |
+
expected_corrections = lev(input, expected)
|
102 |
+
distance_to_input = lev(input, output)
|
103 |
+
distance_to_expected = lev(output, expected)
|
104 |
+
print(f'dl(s,g): {expected_corrections}\ndl(s,h): {distance_to_input}\ndl(h,g): {distance_to_expected}')
|
105 |
|
106 |
+
true_positives = min(expected_corrections, max(0, (expected_corrections + distance_to_input - distance_to_expected))) / 2
|
107 |
+
print(f'T: {true_positives}')
|
108 |
|
109 |
+
precision = true_positives / distance_to_input
|
110 |
+
recall = true_positives / expected_corrections
|
111 |
+
f_05 = (1 + 0.5**2) * (precision * recall) / (0.5**2 * precision + recall)
|
112 |
+
print(f'P: {precision}\nR: {recall}')
|
|
|
|
|
|
|
|
|
113 |
|
114 |
return {
|
115 |
+
"fscore": f_05
|
116 |
}
|