Spaces:
Running
Running
Update metric.py
Browse files
metric.py
CHANGED
|
@@ -40,14 +40,7 @@ Examples:
|
|
| 40 |
|
| 41 |
|
| 42 |
_CITATION = """
|
| 43 |
-
|
| 44 |
-
title={Research on Chinese Chart Data Extraction Methods},
|
| 45 |
-
author={Qiuping Ma,Hangshuo Bi,Qi Zhang,Xiaofan Zhao},
|
| 46 |
-
journal={None},
|
| 47 |
-
volume={0},
|
| 48 |
-
pages={0--0},
|
| 49 |
-
year={2025}
|
| 50 |
-
}
|
| 51 |
"""
|
| 52 |
|
| 53 |
|
|
@@ -123,7 +116,6 @@ class Accuracy(evaluate.Metric):
|
|
| 123 |
true_positives += nested_metrics['true_positives']
|
| 124 |
false_positives += nested_metrics['false_positives']
|
| 125 |
false_negatives += nested_metrics['false_negatives']
|
| 126 |
-
|
| 127 |
elif true_value == 0 and abs(pred_value) < 0.05:
|
| 128 |
true_positives += 1
|
| 129 |
elif true_value != 0 and abs((pred_value - true_value) / true_value) < 0.05:
|
|
@@ -133,11 +125,11 @@ class Accuracy(evaluate.Metric):
|
|
| 133 |
false_negatives += 1
|
| 134 |
else:
|
| 135 |
false_positives += 1
|
|
|
|
| 136 |
for key in true_table:
|
| 137 |
if key not in pred_table:
|
| 138 |
false_negatives += 1
|
| 139 |
|
| 140 |
-
|
| 141 |
precision = true_positives / (true_positives + false_positives) if (true_positives + false_positives) > 0 else 0
|
| 142 |
recall = true_positives / (true_positives + false_negatives) if (true_positives + false_negatives) > 0 else 0
|
| 143 |
f1 = 2 * (precision * recall) / (precision + recall) if (precision + recall) > 0 else 0
|
|
@@ -160,16 +152,16 @@ class Accuracy(evaluate.Metric):
|
|
| 160 |
def main():
|
| 161 |
accuracy_metric = Accuracy()
|
| 162 |
|
| 163 |
-
|
| 164 |
results = accuracy_metric.compute(
|
| 165 |
predictions=["""
|
| 166 |
| | lobby | search | band | charge | chain ||--|--|--|--|--|--|| desire | 5 | 8 | 7 | 5 | 9 || wage | 1 | 5 | 3 | 8 | 5 |
|
| 167 |
-
"""],
|
| 168 |
references=["""
|
| 169 |
| | lobby | search | band | charge | chain ||--|--|--|--|--|--|| desire | 1 | 6 | 7 | 5 | 9 || wage | 1 | 5 | 2 | 8 | 5 |
|
| 170 |
-
"""],
|
| 171 |
)
|
| 172 |
-
print(results)
|
| 173 |
|
| 174 |
if __name__ == '__main__':
|
| 175 |
main()
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
_CITATION = """
|
| 43 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
|
|
|
|
| 116 |
true_positives += nested_metrics['true_positives']
|
| 117 |
false_positives += nested_metrics['false_positives']
|
| 118 |
false_negatives += nested_metrics['false_negatives']
|
|
|
|
| 119 |
elif true_value == 0 and abs(pred_value) < 0.05:
|
| 120 |
true_positives += 1
|
| 121 |
elif true_value != 0 and abs((pred_value - true_value) / true_value) < 0.05:
|
|
|
|
| 125 |
false_negatives += 1
|
| 126 |
else:
|
| 127 |
false_positives += 1
|
| 128 |
+
|
| 129 |
for key in true_table:
|
| 130 |
if key not in pred_table:
|
| 131 |
false_negatives += 1
|
| 132 |
|
|
|
|
| 133 |
precision = true_positives / (true_positives + false_positives) if (true_positives + false_positives) > 0 else 0
|
| 134 |
recall = true_positives / (true_positives + false_negatives) if (true_positives + false_negatives) > 0 else 0
|
| 135 |
f1 = 2 * (precision * recall) / (precision + recall) if (precision + recall) > 0 else 0
|
|
|
|
| 152 |
def main():
|
| 153 |
accuracy_metric = Accuracy()
|
| 154 |
|
| 155 |
+
# 计算指标
|
| 156 |
results = accuracy_metric.compute(
|
| 157 |
predictions=["""
|
| 158 |
| | lobby | search | band | charge | chain ||--|--|--|--|--|--|| desire | 5 | 8 | 7 | 5 | 9 || wage | 1 | 5 | 3 | 8 | 5 |
|
| 159 |
+
"""], # 预测的表格
|
| 160 |
references=["""
|
| 161 |
| | lobby | search | band | charge | chain ||--|--|--|--|--|--|| desire | 1 | 6 | 7 | 5 | 9 || wage | 1 | 5 | 2 | 8 | 5 |
|
| 162 |
+
"""], # 参考的表格
|
| 163 |
)
|
| 164 |
+
print(results) # 输出结果
|
| 165 |
|
| 166 |
if __name__ == '__main__':
|
| 167 |
main()
|