gabrielaltay
commited on
Commit
·
32068ce
1
Parent(s):
dbf5259
host data on the hub
Browse files- data/GAD.zip +3 -0
- gad.py +44 -72
data/GAD.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f47dbe6fb46c853516cf68d934b7a4cf975d9b68fa0c6ca67ff860b6d9245542
|
3 |
+
size 2811223
|
gad.py
CHANGED
@@ -42,11 +42,6 @@ _HOMEPAGE = "https://github.com/dmis-lab/biobert" # This data source is used by
|
|
42 |
|
43 |
_LICENSE = "CC_BY_4p0"
|
44 |
|
45 |
-
_URLs = {
|
46 |
-
"source": "https://drive.google.com/uc?export=download&id=1-jDKGcXREb2X9xTFnuiJ36PvsqoyHWcw",
|
47 |
-
"bigbio_text": "https://drive.google.com/uc?export=download&id=1-jDKGcXREb2X9xTFnuiJ36PvsqoyHWcw",
|
48 |
-
}
|
49 |
-
|
50 |
_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]
|
51 |
|
52 |
_SOURCE_VERSION = "1.0.0"
|
@@ -115,31 +110,53 @@ class GAD(datasets.GeneratorBasedBuilder):
|
|
115 |
self, dl_manager: datasets.DownloadManager
|
116 |
) -> List[datasets.SplitGenerator]:
|
117 |
|
|
|
|
|
118 |
if "blurb" in self.config.name:
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
def _generate_examples(self, filepath: Path):
|
142 |
-
|
|
|
143 |
df = pd.read_csv(filepath, sep="\t", header=None).reset_index()
|
144 |
else:
|
145 |
df = pd.read_csv(filepath, sep="\t")
|
@@ -164,48 +181,3 @@ class GAD(datasets.GeneratorBasedBuilder):
|
|
164 |
yield id, ex
|
165 |
else:
|
166 |
raise ValueError(f"Invalid config: {self.config.name}")
|
167 |
-
|
168 |
-
def _blurb_split_generator(self, dl_manager: datasets.DownloadManager):
|
169 |
-
"""Creates train/dev/test for BLURB split"""
|
170 |
-
|
171 |
-
my_urls = _URLs[self.config.schema]
|
172 |
-
data_dir = Path(dl_manager.download_and_extract(my_urls))
|
173 |
-
data_files = {
|
174 |
-
"train": data_dir / "GAD" / str(1) / "train.tsv",
|
175 |
-
"test": data_dir / "GAD" / str(1) / "test.tsv",
|
176 |
-
}
|
177 |
-
|
178 |
-
root_path = data_files["train"].parents[1]
|
179 |
-
# Save the train + validation sets accordingly
|
180 |
-
with open(data_files["train"], "r") as f:
|
181 |
-
train_data = f.readlines()
|
182 |
-
|
183 |
-
data = {}
|
184 |
-
data["train"], data["dev"] = train_data[:4261], train_data[4261:]
|
185 |
-
|
186 |
-
for batch in ["train", "dev"]:
|
187 |
-
fname = batch + "_blurb.tsv"
|
188 |
-
fname = root_path / fname
|
189 |
-
|
190 |
-
with open(fname, "w") as f:
|
191 |
-
f.write("index\tsentence\tlabel\n")
|
192 |
-
for idx, line in enumerate(data[batch]):
|
193 |
-
f.write(f"{idx}\t{line}")
|
194 |
-
|
195 |
-
train_fpath = root_path / "train_blurb.tsv"
|
196 |
-
dev_fpath = root_path / "dev_blurb.tsv"
|
197 |
-
|
198 |
-
return [
|
199 |
-
datasets.SplitGenerator(
|
200 |
-
name=datasets.Split.TRAIN,
|
201 |
-
gen_kwargs={"filepath": train_fpath},
|
202 |
-
),
|
203 |
-
datasets.SplitGenerator(
|
204 |
-
name=datasets.Split.VALIDATION,
|
205 |
-
gen_kwargs={"filepath": dev_fpath},
|
206 |
-
),
|
207 |
-
datasets.SplitGenerator(
|
208 |
-
name=datasets.Split.TEST,
|
209 |
-
gen_kwargs={"filepath": data_files["test"]},
|
210 |
-
),
|
211 |
-
]
|
|
|
42 |
|
43 |
_LICENSE = "CC_BY_4p0"
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]
|
46 |
|
47 |
_SOURCE_VERSION = "1.0.0"
|
|
|
110 |
self, dl_manager: datasets.DownloadManager
|
111 |
) -> List[datasets.SplitGenerator]:
|
112 |
|
113 |
+
data_dir = Path(dl_manager.download_and_extract("data/GAD.zip"))
|
114 |
+
|
115 |
if "blurb" in self.config.name:
|
116 |
+
data_files = {
|
117 |
+
"train": data_dir / "GAD" / "blurb" / "train.tsv",
|
118 |
+
"validation": data_dir / "GAD" / "blurb" / "dev.tsv",
|
119 |
+
"test": data_dir / "GAD" / "blurb" / "test.tsv",
|
120 |
+
}
|
121 |
+
|
122 |
+
return [
|
123 |
+
datasets.SplitGenerator(
|
124 |
+
name=datasets.Split.TRAIN,
|
125 |
+
gen_kwargs={"filepath": data_files["train"]},
|
126 |
+
),
|
127 |
+
datasets.SplitGenerator(
|
128 |
+
name=datasets.Split.VALIDATION,
|
129 |
+
gen_kwargs={"filepath": data_files["validation"]},
|
130 |
+
),
|
131 |
+
datasets.SplitGenerator(
|
132 |
+
name=datasets.Split.TEST,
|
133 |
+
gen_kwargs={"filepath": data_files["test"]},
|
134 |
+
),
|
135 |
+
]
|
136 |
+
|
137 |
+
else:
|
138 |
+
|
139 |
+
fold_id = int(self.config.subset_id.split("_fold")[1][0]) + 1
|
140 |
+
|
141 |
+
data_files = {
|
142 |
+
"train": data_dir / "GAD" / str(fold_id) / "train.tsv",
|
143 |
+
"test": data_dir / "GAD" / str(fold_id) / "test.tsv",
|
144 |
+
}
|
145 |
+
|
146 |
+
return [
|
147 |
+
datasets.SplitGenerator(
|
148 |
+
name=datasets.Split.TRAIN,
|
149 |
+
gen_kwargs={"filepath": data_files["train"]},
|
150 |
+
),
|
151 |
+
datasets.SplitGenerator(
|
152 |
+
name=datasets.Split.TEST,
|
153 |
+
gen_kwargs={"filepath": data_files["test"]},
|
154 |
+
),
|
155 |
+
]
|
156 |
|
157 |
def _generate_examples(self, filepath: Path):
|
158 |
+
# train files in non-blurb splits don't have headers for some reason
|
159 |
+
if "train.tsv" in str(filepath) and "blurb" not in self.config.name:
|
160 |
df = pd.read_csv(filepath, sep="\t", header=None).reset_index()
|
161 |
else:
|
162 |
df = pd.read_csv(filepath, sep="\t")
|
|
|
181 |
yield id, ex
|
182 |
else:
|
183 |
raise ValueError(f"Invalid config: {self.config.name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|