Add ISCO hierarchy download and creation
Browse files- metric_template_1.py +16 -2
metric_template_1.py
CHANGED
@@ -16,6 +16,8 @@
|
|
16 |
import evaluate
|
17 |
import datasets
|
18 |
import ham
|
|
|
|
|
19 |
|
20 |
|
21 |
# TODO: Add BibTeX citation
|
@@ -56,6 +58,9 @@ Examples:
|
|
56 |
|
57 |
# TODO: Define external resources urls if needed
|
58 |
BAD_WORDS_URL = "http://url/to/external/resource/bad_words.txt"
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
@@ -87,7 +92,15 @@ class MetricTemplate1(evaluate.Metric):
|
|
87 |
def _download_and_prepare(self, dl_manager):
|
88 |
"""Optional: download external resources useful to compute the scores"""
|
89 |
# TODO: Download external resources if needed
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
def _compute(self, predictions, references):
|
93 |
"""Returns the scores"""
|
@@ -103,9 +116,10 @@ class MetricTemplate1(evaluate.Metric):
|
|
103 |
)
|
104 |
|
105 |
# Example usage:
|
106 |
-
hierarchy = {"G": ["E"], "E": ["B"], "F": ["C"], "C": ["B"], "B": []}
|
107 |
# true_labels = [{'G'}]
|
108 |
# predicted_labels = [{'F'}]
|
|
|
109 |
hP, hR = ham.hierarchical_precision_recall(references, predictions, hierarchy)
|
110 |
hF = ham.hierarchical_f_measure(hP, hR)
|
111 |
print(
|
|
|
16 |
import evaluate
|
17 |
import datasets
|
18 |
import ham
|
19 |
+
import os
|
20 |
+
import isco
|
21 |
|
22 |
|
23 |
# TODO: Add BibTeX citation
|
|
|
58 |
|
59 |
# TODO: Define external resources urls if needed
|
60 |
BAD_WORDS_URL = "http://url/to/external/resource/bad_words.txt"
|
61 |
+
ISCO_HIERARCHY_URL = (
|
62 |
+
"https://storage.googleapis.com/isco-public/tables/ISCO_structure.csv"
|
63 |
+
)
|
64 |
|
65 |
|
66 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
|
|
92 |
def _download_and_prepare(self, dl_manager):
|
93 |
"""Optional: download external resources useful to compute the scores"""
|
94 |
# TODO: Download external resources if needed
|
95 |
+
|
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(
|
100 |
+
os.path.join(isco_csv, "isco_structure.csv")
|
101 |
+
)
|
102 |
+
print("ISCO hierarchy created")
|
103 |
+
print(self.isco_hierarchy)
|
104 |
|
105 |
def _compute(self, predictions, references):
|
106 |
"""Returns the scores"""
|
|
|
116 |
)
|
117 |
|
118 |
# Example usage:
|
119 |
+
# hierarchy = {"G": ["E"], "E": ["B"], "F": ["C"], "C": ["B"], "B": []}
|
120 |
# true_labels = [{'G'}]
|
121 |
# predicted_labels = [{'F'}]
|
122 |
+
hierarchy = self.isco_hierarchy
|
123 |
hP, hR = ham.hierarchical_precision_recall(references, predictions, hierarchy)
|
124 |
hF = ham.hierarchical_f_measure(hP, hR)
|
125 |
print(
|