Refactored ISCO hierarchy creation and added hierarchical measures calculation
Browse files- metric_template_1.py +7 -4
metric_template_1.py
CHANGED
|
@@ -96,8 +96,8 @@ class MetricTemplate1(evaluate.Metric):
|
|
| 96 |
# Download and prepare the ISCO structure csv file
|
| 97 |
isco_csv = dl_manager.download_and_extract(ISCO_HIERARCHY_URL)
|
| 98 |
print(f"ISCO CSV file downloaded")
|
| 99 |
-
self.isco_hierarchy = isco.
|
| 100 |
-
print("ISCO hierarchy created")
|
| 101 |
print(self.isco_hierarchy)
|
| 102 |
|
| 103 |
def _compute(self, predictions, references):
|
|
@@ -118,8 +118,11 @@ class MetricTemplate1(evaluate.Metric):
|
|
| 118 |
# true_labels = [{'G'}]
|
| 119 |
# predicted_labels = [{'F'}]
|
| 120 |
hierarchy = self.isco_hierarchy
|
| 121 |
-
|
| 122 |
-
hF = ham.
|
|
|
|
|
|
|
|
|
|
| 123 |
print(
|
| 124 |
f"Hierarchical Precision: {hP}, Hierarchical Recall: {hR}, Hierarchical F-measure: {hF}"
|
| 125 |
)
|
|
|
|
| 96 |
# Download and prepare the ISCO structure csv file
|
| 97 |
isco_csv = dl_manager.download_and_extract(ISCO_HIERARCHY_URL)
|
| 98 |
print(f"ISCO CSV file downloaded")
|
| 99 |
+
self.isco_hierarchy = isco.create_hierarchy_dict(isco_csv)
|
| 100 |
+
print("ISCO hierarchy dictionary created")
|
| 101 |
print(self.isco_hierarchy)
|
| 102 |
|
| 103 |
def _compute(self, predictions, references):
|
|
|
|
| 118 |
# true_labels = [{'G'}]
|
| 119 |
# predicted_labels = [{'F'}]
|
| 120 |
hierarchy = self.isco_hierarchy
|
| 121 |
+
tree, code_to_node = isco.create_hierarchy_tree(hierarchy)
|
| 122 |
+
hP, hR, hF = ham.calculate_hierarchical_measures(
|
| 123 |
+
references, predictions, tree, code_to_node
|
| 124 |
+
)
|
| 125 |
+
# hF = ham.hierarchical_f_measure(hP, hR)
|
| 126 |
print(
|
| 127 |
f"Hierarchical Precision: {hP}, Hierarchical Recall: {hR}, Hierarchical F-measure: {hF}"
|
| 128 |
)
|