update compute
Browse files- charmatch.py +26 -17
charmatch.py
CHANGED
@@ -87,25 +87,34 @@ class charmatch(evaluate.Metric):
|
|
87 |
# TODO: Download external resources if needed
|
88 |
pass
|
89 |
|
90 |
-
def _compute(
|
91 |
def get_score(input, expected, output):
|
92 |
print(input, expected, output)
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
return {
|
111 |
"fscore": avg
|
|
|
87 |
# TODO: Download external resources if needed
|
88 |
pass
|
89 |
|
90 |
+
def _compute(inputs, expected, outputs):
|
91 |
def get_score(input, expected, output):
|
92 |
print(input, expected, output)
|
93 |
+
deduped = {input, expected, output}
|
94 |
+
if len(deduped) == 1:
|
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 |
+
expected_corrections = lev(input, expected)
|
103 |
+
distance_to_input = lev(input, output)
|
104 |
+
distance_to_expected = lev(output, expected)
|
105 |
+
print(f'dl(s,g): {expected_corrections}\ndl(s,h): {distance_to_input}\ndl(h,g): {distance_to_expected}')
|
106 |
+
|
107 |
+
true_positives = min(expected_corrections, max(0, (expected_corrections + distance_to_input - distance_to_expected))) / 2
|
108 |
+
print(f'T: {true_positives}')
|
109 |
+
|
110 |
+
precision = true_positives / distance_to_input
|
111 |
+
recall = true_positives / expected_corrections
|
112 |
+
f_05 = (1 + 0.5**2) * (precision * recall) / (0.5**2 * precision + recall)
|
113 |
+
print(f'P: {precision}\nR: {recall}')
|
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": avg
|