Upload iatf.py with huggingface_hub
Browse files
iatf.py
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import Dict, List, Tuple
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
try:
|
7 |
+
import pyreadr
|
8 |
+
except:
|
9 |
+
print("Install the `pyreadr` package to use.")
|
10 |
+
|
11 |
+
from seacrowd.utils import schemas
|
12 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
13 |
+
from seacrowd.utils.constants import (TASK_TO_SCHEMA, Licenses, Tasks)
|
14 |
+
|
15 |
+
_DATASETNAME = "iatf"
|
16 |
+
|
17 |
+
_CITATION = """\
|
18 |
+
@misc{
|
19 |
+
iatf,
|
20 |
+
title={Inter-Agency Task Force for the Management of Emerging Infectious Diseases (IATF) COVID-19 Resolutions},
|
21 |
+
url={https://como-ph.github.io/post/creating-text-data-from-iatf-resolutions/},
|
22 |
+
author={Chris Mercado, John Robert Medina, Ernest Guevarra}
|
23 |
+
}
|
24 |
+
"""
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
To assess possible impact of various COVID-19 prediction models on Philippine government response, text from various resolutions issued by
|
28 |
+
the Inter-agency Task Force for the Management of Emerging Infectious Diseases (IATF) has been collected using data mining approaches implemented in R.
|
29 |
+
"""
|
30 |
+
|
31 |
+
_HOMEPAGE = "https://github.com/como-ph/covidphtext/tree/master/data"
|
32 |
+
|
33 |
+
_LICENSE = Licenses.GPL_3_0.value
|
34 |
+
|
35 |
+
_SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
|
36 |
+
_SEACROWD_SCHEMA_NAME = TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()
|
37 |
+
_LANGUAGES = ["fil"]
|
38 |
+
_LOCAL = False
|
39 |
+
_SOURCE_VERSION = "1.0.0"
|
40 |
+
_SEACROWD_VERSION = "2024.06.20"
|
41 |
+
|
42 |
+
_URL_BASE = "https://github.com/como-ph/covidphtext/raw/master/data/"
|
43 |
+
_URLS = [
|
44 |
+
"iatfGuidelineOmnibus.rda",
|
45 |
+
"iatfResolution01.rda",
|
46 |
+
"iatfResolution02.rda",
|
47 |
+
"iatfResolution03.rda",
|
48 |
+
"iatfResolution04.rda",
|
49 |
+
"iatfResolution05.rda",
|
50 |
+
"iatfResolution06.rda",
|
51 |
+
"iatfResolution07.rda",
|
52 |
+
"iatfResolution08.rda",
|
53 |
+
"iatfResolution09.rda",
|
54 |
+
"iatfResolution10.rda",
|
55 |
+
"iatfResolution11.rda",
|
56 |
+
"iatfResolution12.rda",
|
57 |
+
"iatfResolution13.rda",
|
58 |
+
"iatfResolution14.rda",
|
59 |
+
"iatfResolution15.rda",
|
60 |
+
"iatfResolution16.rda",
|
61 |
+
"iatfResolution17.rda",
|
62 |
+
"iatfResolution18.rda",
|
63 |
+
"iatfResolution19.rda",
|
64 |
+
"iatfResolution20.rda",
|
65 |
+
"iatfResolution21.rda",
|
66 |
+
"iatfResolution22.rda",
|
67 |
+
"iatfResolution23.rda",
|
68 |
+
"iatfResolution24.rda",
|
69 |
+
"iatfResolution25.rda",
|
70 |
+
"iatfResolution26.rda",
|
71 |
+
"iatfResolution27.rda",
|
72 |
+
"iatfResolution28.rda",
|
73 |
+
"iatfResolution29.rda",
|
74 |
+
"iatfResolution30.rda",
|
75 |
+
"iatfResolution30A.rda",
|
76 |
+
"iatfResolution31.rda",
|
77 |
+
"iatfResolution32.rda",
|
78 |
+
"iatfResolution33.rda",
|
79 |
+
"iatfResolution34.rda",
|
80 |
+
"iatfResolution35.rda",
|
81 |
+
"iatfResolution36.rda",
|
82 |
+
"iatfResolution37.rda",
|
83 |
+
"iatfResolution38.rda",
|
84 |
+
"iatfResolution39.rda",
|
85 |
+
"iatfResolution40.rda",
|
86 |
+
"iatfResolution41.rda",
|
87 |
+
"iatfResolution42.rda",
|
88 |
+
"iatfResolution43.rda",
|
89 |
+
"iatfResolution44.rda",
|
90 |
+
"iatfResolution45.rda",
|
91 |
+
"iatfResolution46.rda",
|
92 |
+
"iatfResolution46A.rda",
|
93 |
+
"iatfResolution47.rda",
|
94 |
+
"iatfResolution48.rda",
|
95 |
+
"iatfResolution49.rda",
|
96 |
+
"iatfResolution50.rda",
|
97 |
+
"iatfResolution50A.rda",
|
98 |
+
"iatfResolution51.rda",
|
99 |
+
"iatfResolution52.rda",
|
100 |
+
"iatfResolution53.rda",
|
101 |
+
"iatfResolution54.rda",
|
102 |
+
"iatfResolution55.rda",
|
103 |
+
"iatfResolution55A.rda",
|
104 |
+
"iatfResolution56.rda",
|
105 |
+
"iatfResolution57.rda",
|
106 |
+
"iatfResolution58.rda",
|
107 |
+
"iatfResolution59.rda",
|
108 |
+
"iatfResolution60.rda",
|
109 |
+
"iatfResolution60A.rda",
|
110 |
+
]
|
111 |
+
|
112 |
+
|
113 |
+
class IATFDataset(datasets.GeneratorBasedBuilder):
|
114 |
+
"""Inter-agency Task Force for the Management of Emerging Infectious Diseases Dataset"""
|
115 |
+
|
116 |
+
BUILDER_CONFIGS = [
|
117 |
+
SEACrowdConfig(
|
118 |
+
name=f"{_DATASETNAME}_source",
|
119 |
+
version=datasets.Version(_SOURCE_VERSION),
|
120 |
+
description=f"{_DATASETNAME} source schema",
|
121 |
+
schema="source",
|
122 |
+
subset_id=f"{_DATASETNAME}",
|
123 |
+
),
|
124 |
+
SEACrowdConfig(
|
125 |
+
name=f"{_DATASETNAME}_seacrowd_{_SEACROWD_SCHEMA_NAME}",
|
126 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
127 |
+
description=f"{_DATASETNAME} seacrowd schema",
|
128 |
+
schema=f"seacrowd_{_SEACROWD_SCHEMA_NAME}",
|
129 |
+
subset_id=f"{_DATASETNAME}",
|
130 |
+
),
|
131 |
+
]
|
132 |
+
|
133 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
134 |
+
|
135 |
+
def _info(self) -> datasets.DatasetInfo:
|
136 |
+
if self.config.schema == "source":
|
137 |
+
features = datasets.Features(
|
138 |
+
{
|
139 |
+
"id": datasets.Value("string"),
|
140 |
+
"text": datasets.Value("string"),
|
141 |
+
}
|
142 |
+
)
|
143 |
+
elif self.config.schema == f"seacrowd_{_SEACROWD_SCHEMA_NAME}":
|
144 |
+
features = schemas.self_supervised_pretraining.features
|
145 |
+
else:
|
146 |
+
raise ValueError(f"Invalid config schema: {self.config.schema}")
|
147 |
+
|
148 |
+
return datasets.DatasetInfo(
|
149 |
+
description=_DESCRIPTION,
|
150 |
+
features=features,
|
151 |
+
homepage=_HOMEPAGE,
|
152 |
+
license=_LICENSE,
|
153 |
+
citation=_CITATION,
|
154 |
+
)
|
155 |
+
|
156 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
157 |
+
filepaths = [Path(dl_manager.download(_URL_BASE + url)) for url in _URLS]
|
158 |
+
return [
|
159 |
+
datasets.SplitGenerator(
|
160 |
+
name=datasets.Split.TRAIN,
|
161 |
+
gen_kwargs={"filepaths": filepaths},
|
162 |
+
),
|
163 |
+
]
|
164 |
+
|
165 |
+
def _generate_examples(self, filepaths: List[Path]) -> Tuple[int, Dict]:
|
166 |
+
counter = 0
|
167 |
+
for path in filepaths:
|
168 |
+
data = pyreadr.read_r(path)
|
169 |
+
text = " ".join([str(x) for x in data[list(data.keys())[0]]["text"].values])
|
170 |
+
if self.config.schema == "source":
|
171 |
+
yield (
|
172 |
+
counter,
|
173 |
+
{
|
174 |
+
"id": str(counter),
|
175 |
+
"text": text.strip(),
|
176 |
+
},
|
177 |
+
)
|
178 |
+
elif self.config.schema == f"seacrowd_{_SEACROWD_SCHEMA_NAME}":
|
179 |
+
yield (
|
180 |
+
counter,
|
181 |
+
{
|
182 |
+
"id": str(counter),
|
183 |
+
"text": text.strip(),
|
184 |
+
},
|
185 |
+
)
|
186 |
+
|
187 |
+
counter += 1
|