Datasets:
Update files from the datasets library (from 1.16.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.16.0
- README.md +1 -0
- dataset_infos.json +1 -1
- dummy/trex/1.1.0/dummy_data.zip +2 -2
- lama.py +112 -106
README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
---
|
|
|
2 |
annotations_creators:
|
3 |
- crowdsourced
|
4 |
- expert-generated
|
|
|
1 |
---
|
2 |
+
pretty_name: "LAMA: LAnguage Model Analysis"
|
3 |
annotations_creators:
|
4 |
- crowdsourced
|
5 |
- expert-generated
|
dataset_infos.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"trex": {"description": "LAMA is a dataset used to probe and analyze the factual and commonsense knowledge contained in pretrained language models. See https://github.com/facebookresearch/LAMA.\n", "citation": "@inproceedings{petroni2019language,\n title={Language Models as Knowledge Bases?},\n author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel},\n booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019},\n year={2019}\n}\n@inproceedings{petroni2020how,\n title={How Context Affects Language Models' Factual Predictions},\n author={Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rockt{\"a}schel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},\n booktitle={Automated Knowledge Base Construction},\n year={2020},\n url={https://openreview.net/forum?id=025X0zPfn}\n}\n", "homepage": "https://github.com/facebookresearch/LAMA", "license": "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE", "features": {"uuid": {"dtype": "string", "id": null, "_type": "Value"}, "obj_uri": {"dtype": "string", "id": null, "_type": "Value"}, "obj_label": {"dtype": "string", "id": null, "_type": "Value"}, "sub_uri": {"dtype": "string", "id": null, "_type": "Value"}, "sub_label": {"dtype": "string", "id": null, "_type": "Value"}, "predicate_id": {"dtype": "string", "id": null, "_type": "Value"}, "sub_surface": {"dtype": "string", "id": null, "_type": "Value"}, "obj_surface": {"dtype": "string", "id": null, "_type": "Value"}, "masked_sentence": {"dtype": "string", "id": null, "_type": "Value"}, "template": {"dtype": "string", "id": null, "_type": "Value"}, "template_negated": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "description": {"dtype": "string", "id": null, "_type": "Value"}, "type": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "builder_name": "lama", "config_name": "trex", "version": {"version_str": "1.1.0", "description": null, "major": 1, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 656913189, "num_examples": 1304391, "dataset_name": "lama"}}, "download_checksums": {"https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz": {"num_bytes": 74639115, "checksum": "1a151058e6608e47983ea4c99c50bb69248c1c0763a04a3793b0a0b657aa0b61"}}, "download_size":
|
|
|
1 |
+
{"trex": {"description": "LAMA is a dataset used to probe and analyze the factual and commonsense knowledge contained in pretrained language models. See https://github.com/facebookresearch/LAMA.\n", "citation": "@inproceedings{petroni2019language,\n title={Language Models as Knowledge Bases?},\n author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel},\n booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019},\n year={2019}\n}\n@inproceedings{petroni2020how,\n title={How Context Affects Language Models' Factual Predictions},\n author={Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rockt{\"a}schel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},\n booktitle={Automated Knowledge Base Construction},\n year={2020},\n url={https://openreview.net/forum?id=025X0zPfn}\n}\n", "homepage": "https://github.com/facebookresearch/LAMA", "license": "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE", "features": {"uuid": {"dtype": "string", "id": null, "_type": "Value"}, "obj_uri": {"dtype": "string", "id": null, "_type": "Value"}, "obj_label": {"dtype": "string", "id": null, "_type": "Value"}, "sub_uri": {"dtype": "string", "id": null, "_type": "Value"}, "sub_label": {"dtype": "string", "id": null, "_type": "Value"}, "predicate_id": {"dtype": "string", "id": null, "_type": "Value"}, "sub_surface": {"dtype": "string", "id": null, "_type": "Value"}, "obj_surface": {"dtype": "string", "id": null, "_type": "Value"}, "masked_sentence": {"dtype": "string", "id": null, "_type": "Value"}, "template": {"dtype": "string", "id": null, "_type": "Value"}, "template_negated": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "description": {"dtype": "string", "id": null, "_type": "Value"}, "type": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "lama", "config_name": "trex", "version": {"version_str": "1.1.0", "description": null, "major": 1, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 656913189, "num_examples": 1304391, "dataset_name": "lama"}}, "download_checksums": {"https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz": {"num_bytes": 74639115, "checksum": "1a151058e6608e47983ea4c99c50bb69248c1c0763a04a3793b0a0b657aa0b61"}, "https://s3.amazonaws.com/datasets.huggingface.co/lama/relations.jsonl": {"num_bytes": 13086, "checksum": "154be499a67d5a681bdeaff3bce578a64064c6ce73e471523c6423071e3e5298"}}, "download_size": 74652201, "post_processing_size": null, "dataset_size": 656913189, "size_in_bytes": 731565390}, "squad": {"description": "LAMA is a dataset used to probe and analyze the factual and commonsense knowledge contained in pretrained language models. See https://github.com/facebookresearch/LAMA.\n", "citation": "@inproceedings{petroni2019language,\n title={Language Models as Knowledge Bases?},\n author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel},\n booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019},\n year={2019}\n}\n@inproceedings{petroni2020how,\n title={How Context Affects Language Models' Factual Predictions},\n author={Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rockt{\"a}schel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},\n booktitle={Automated Knowledge Base Construction},\n year={2020},\n url={https://openreview.net/forum?id=025X0zPfn}\n}\n", "homepage": "https://github.com/facebookresearch/LAMA", "license": "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "sub_label": {"dtype": "string", "id": null, "_type": "Value"}, "obj_label": {"dtype": "string", "id": null, "_type": "Value"}, "negated": {"dtype": "string", "id": null, "_type": "Value"}, "masked_sentence": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "lama", "config_name": "squad", "version": {"version_str": "1.1.0", "description": null, "major": 1, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 57188, "num_examples": 305, "dataset_name": "lama"}}, "download_checksums": {"https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz": {"num_bytes": 74639115, "checksum": "1a151058e6608e47983ea4c99c50bb69248c1c0763a04a3793b0a0b657aa0b61"}}, "download_size": 74639115, "post_processing_size": null, "dataset_size": 57188, "size_in_bytes": 74696303}, "google_re": {"description": "LAMA is a dataset used to probe and analyze the factual and commonsense knowledge contained in pretrained language models. See https://github.com/facebookresearch/LAMA.\n", "citation": "@inproceedings{petroni2019language,\n title={Language Models as Knowledge Bases?},\n author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel},\n booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019},\n year={2019}\n}\n@inproceedings{petroni2020how,\n title={How Context Affects Language Models' Factual Predictions},\n author={Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rockt{\"a}schel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},\n booktitle={Automated Knowledge Base Construction},\n year={2020},\n url={https://openreview.net/forum?id=025X0zPfn}\n}\n", "homepage": "https://github.com/facebookresearch/LAMA", "license": "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE", "features": {"pred": {"dtype": "string", "id": null, "_type": "Value"}, "sub": {"dtype": "string", "id": null, "_type": "Value"}, "obj": {"dtype": "string", "id": null, "_type": "Value"}, "evidences": {"dtype": "string", "id": null, "_type": "Value"}, "judgments": {"dtype": "string", "id": null, "_type": "Value"}, "sub_w": {"dtype": "string", "id": null, "_type": "Value"}, "sub_label": {"dtype": "string", "id": null, "_type": "Value"}, "sub_aliases": {"dtype": "string", "id": null, "_type": "Value"}, "obj_w": {"dtype": "string", "id": null, "_type": "Value"}, "obj_label": {"dtype": "string", "id": null, "_type": "Value"}, "obj_aliases": {"dtype": "string", "id": null, "_type": "Value"}, "uuid": {"dtype": "string", "id": null, "_type": "Value"}, "masked_sentence": {"dtype": "string", "id": null, "_type": "Value"}, "template": {"dtype": "string", "id": null, "_type": "Value"}, "template_negated": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "lama", "config_name": "google_re", "version": {"version_str": "1.1.0", "description": null, "major": 1, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 7638657, "num_examples": 6106, "dataset_name": "lama"}}, "download_checksums": {"https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz": {"num_bytes": 74639115, "checksum": "1a151058e6608e47983ea4c99c50bb69248c1c0763a04a3793b0a0b657aa0b61"}}, "download_size": 74639115, "post_processing_size": null, "dataset_size": 7638657, "size_in_bytes": 82277772}, "conceptnet": {"description": "LAMA is a dataset used to probe and analyze the factual and commonsense knowledge contained in pretrained language models. See https://github.com/facebookresearch/LAMA.\n", "citation": "@inproceedings{petroni2019language,\n title={Language Models as Knowledge Bases?},\n author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel},\n booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019},\n year={2019}\n}\n@inproceedings{petroni2020how,\n title={How Context Affects Language Models' Factual Predictions},\n author={Fabio Petroni and Patrick Lewis and Aleksandra Piktus and Tim Rockt{\"a}schel and Yuxiang Wu and Alexander H. Miller and Sebastian Riedel},\n booktitle={Automated Knowledge Base Construction},\n year={2020},\n url={https://openreview.net/forum?id=025X0zPfn}\n}\n", "homepage": "https://github.com/facebookresearch/LAMA", "license": "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE", "features": {"uuid": {"dtype": "string", "id": null, "_type": "Value"}, "sub": {"dtype": "string", "id": null, "_type": "Value"}, "obj": {"dtype": "string", "id": null, "_type": "Value"}, "pred": {"dtype": "string", "id": null, "_type": "Value"}, "obj_label": {"dtype": "string", "id": null, "_type": "Value"}, "masked_sentence": {"dtype": "string", "id": null, "_type": "Value"}, "negated": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "lama", "config_name": "conceptnet", "version": {"version_str": "1.1.0", "description": null, "major": 1, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 4130000, "num_examples": 29774, "dataset_name": "lama"}}, "download_checksums": {"https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz": {"num_bytes": 74639115, "checksum": "1a151058e6608e47983ea4c99c50bb69248c1c0763a04a3793b0a0b657aa0b61"}}, "download_size": 74639115, "post_processing_size": null, "dataset_size": 4130000, "size_in_bytes": 78769115}}
|
dummy/trex/1.1.0/dummy_data.zip
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:642f602212b312c023ca121b8031dd305401a26dbfd77b5fca624f4c5dd4467a
|
3 |
+
size 4229
|
lama.py
CHANGED
@@ -15,9 +15,8 @@
|
|
15 |
"""The LAMA Dataset"""
|
16 |
|
17 |
|
18 |
-
import glob
|
19 |
import json
|
20 |
-
import
|
21 |
|
22 |
import datasets
|
23 |
|
@@ -45,12 +44,9 @@ _HOMEPAGE = "https://github.com/facebookresearch/LAMA"
|
|
45 |
|
46 |
_LICENSE = "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE"
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
"google_re": "https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz",
|
52 |
-
"conceptnet": "https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz",
|
53 |
-
}
|
54 |
|
55 |
|
56 |
class Lama(datasets.GeneratorBasedBuilder):
|
@@ -168,16 +164,16 @@ class Lama(datasets.GeneratorBasedBuilder):
|
|
168 |
|
169 |
def _split_generators(self, dl_manager):
|
170 |
"""Returns SplitGenerators."""
|
171 |
-
|
172 |
-
data_dir = dl_manager.download_and_extract(my_urls)
|
173 |
if self.config.name == "trex":
|
|
|
174 |
return [
|
175 |
datasets.SplitGenerator(
|
176 |
name=datasets.Split.TRAIN,
|
177 |
gen_kwargs={
|
178 |
-
"
|
179 |
-
|
180 |
-
"
|
181 |
},
|
182 |
),
|
183 |
]
|
@@ -186,15 +182,12 @@ class Lama(datasets.GeneratorBasedBuilder):
|
|
186 |
datasets.SplitGenerator(
|
187 |
name=datasets.Split.TRAIN,
|
188 |
gen_kwargs={
|
189 |
-
"
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
"Google_RE/place_of_birth_test.jsonl",
|
194 |
-
"Google_RE/place_of_death_test.jsonl",
|
195 |
-
]
|
196 |
],
|
197 |
-
"
|
198 |
},
|
199 |
),
|
200 |
]
|
@@ -203,8 +196,8 @@ class Lama(datasets.GeneratorBasedBuilder):
|
|
203 |
datasets.SplitGenerator(
|
204 |
name=datasets.Split.TRAIN,
|
205 |
gen_kwargs={
|
206 |
-
"
|
207 |
-
"
|
208 |
},
|
209 |
),
|
210 |
]
|
@@ -213,26 +206,26 @@ class Lama(datasets.GeneratorBasedBuilder):
|
|
213 |
datasets.SplitGenerator(
|
214 |
name=datasets.Split.TRAIN,
|
215 |
gen_kwargs={
|
216 |
-
"
|
217 |
-
"
|
218 |
},
|
219 |
),
|
220 |
]
|
221 |
|
222 |
-
def _generate_examples(self,
|
223 |
"""Yields examples from the LAMA dataset."""
|
|
|
224 |
if self.config.name == "trex":
|
225 |
-
paths = filepath
|
226 |
-
relations_path = paths[0]
|
227 |
-
paths = paths[1:]
|
228 |
all_rels = {}
|
229 |
with open(relations_path, encoding="utf-8") as f:
|
230 |
for row in f:
|
231 |
data = json.loads(row)
|
232 |
all_rels[data["relation"]] = data
|
233 |
id_ = -1
|
234 |
-
|
235 |
-
|
|
|
|
|
236 |
for row in f:
|
237 |
data = json.loads(row)
|
238 |
pred = all_rels.get(data["predicate_id"], {})
|
@@ -254,91 +247,104 @@ class Lama(datasets.GeneratorBasedBuilder):
|
|
254 |
"description": str(pred.get("description", "")),
|
255 |
"type": str(pred.get("type", "")),
|
256 |
}
|
|
|
|
|
257 |
elif self.config.name == "conceptnet":
|
258 |
id_ = -1
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
286 |
elif self.config.name == "squad":
|
287 |
id_ = -1
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
id_ += 1
|
293 |
-
yield id_, {
|
294 |
-
"id": str(data["id"]),
|
295 |
-
"sub_label": str(data["sub_label"]),
|
296 |
-
"obj_label": str(data["obj_label"]),
|
297 |
-
"negated": str(data.get("negated", "")),
|
298 |
-
"masked_sentence": str(masked_sentence),
|
299 |
-
}
|
300 |
-
elif self.config.name == "google_re":
|
301 |
-
id_ = -1
|
302 |
-
paths = filepath
|
303 |
-
for filepath in paths:
|
304 |
-
# from https://github.com/facebookresearch/LAMA/blob/master/scripts/run_experiments.py
|
305 |
-
if "place_of_birth" in filepath:
|
306 |
-
pred = {
|
307 |
-
"relation": "place_of_birth",
|
308 |
-
"template": "[X] was born in [Y] .",
|
309 |
-
"template_negated": "[X] was not born in [Y] .",
|
310 |
-
}
|
311 |
-
elif "date_of_birth" in filepath:
|
312 |
-
pred = {
|
313 |
-
"relation": "date_of_birth",
|
314 |
-
"template": "[X] (born [Y]).",
|
315 |
-
"template_negated": "[X] (not born [Y]).",
|
316 |
-
}
|
317 |
-
else:
|
318 |
-
pred = {
|
319 |
-
"relation": "place_of_death",
|
320 |
-
"template": "[X] died in [Y] .",
|
321 |
-
"template_negated": "[X] did not die in [Y] .",
|
322 |
-
}
|
323 |
-
with open(filepath, encoding="utf-8") as f:
|
324 |
for row in f:
|
325 |
data = json.loads(row)
|
326 |
for masked_sentence in data["masked_sentences"]:
|
327 |
id_ += 1
|
328 |
yield id_, {
|
329 |
-
"
|
330 |
-
"sub": str(data["sub"]),
|
331 |
-
"obj": str(data["obj"]),
|
332 |
-
"evidences": str(data["evidences"]),
|
333 |
-
"judgments": str(data["judgments"]),
|
334 |
-
"sub_w": str(data["sub_w"]),
|
335 |
"sub_label": str(data["sub_label"]),
|
336 |
-
"sub_aliases": str(data["sub_aliases"]),
|
337 |
-
"obj_w": str(data["obj_w"]),
|
338 |
"obj_label": str(data["obj_label"]),
|
339 |
-
"
|
340 |
-
"uuid": str(data["uuid"]),
|
341 |
"masked_sentence": str(masked_sentence),
|
342 |
-
"template": str(pred["template"]),
|
343 |
-
"template_negated": str(pred["template_negated"]),
|
344 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
"""The LAMA Dataset"""
|
16 |
|
17 |
|
|
|
18 |
import json
|
19 |
+
from fnmatch import fnmatch
|
20 |
|
21 |
import datasets
|
22 |
|
|
|
44 |
|
45 |
_LICENSE = "The Creative Commons Attribution-Noncommercial 4.0 International License. see https://github.com/facebookresearch/LAMA/blob/master/LICENSE"
|
46 |
|
47 |
+
_RELATIONS_URL = "https://s3.amazonaws.com/datasets.huggingface.co/lama/relations.jsonl"
|
48 |
+
|
49 |
+
_DATA_URL = "https://dl.fbaipublicfiles.com/LAMA/negated_data.tar.gz"
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
class Lama(datasets.GeneratorBasedBuilder):
|
|
|
164 |
|
165 |
def _split_generators(self, dl_manager):
|
166 |
"""Returns SplitGenerators."""
|
167 |
+
archive = dl_manager.download(_DATA_URL)
|
|
|
168 |
if self.config.name == "trex":
|
169 |
+
relations_path = dl_manager.download(_RELATIONS_URL)
|
170 |
return [
|
171 |
datasets.SplitGenerator(
|
172 |
name=datasets.Split.TRAIN,
|
173 |
gen_kwargs={
|
174 |
+
"filepaths": ["TREx/*"],
|
175 |
+
"files": dl_manager.iter_archive(archive),
|
176 |
+
"relations_path": relations_path,
|
177 |
},
|
178 |
),
|
179 |
]
|
|
|
182 |
datasets.SplitGenerator(
|
183 |
name=datasets.Split.TRAIN,
|
184 |
gen_kwargs={
|
185 |
+
"filepaths": [
|
186 |
+
"Google_RE/date_of_birth_test.jsonl",
|
187 |
+
"Google_RE/place_of_birth_test.jsonl",
|
188 |
+
"Google_RE/place_of_death_test.jsonl",
|
|
|
|
|
|
|
189 |
],
|
190 |
+
"files": dl_manager.iter_archive(archive),
|
191 |
},
|
192 |
),
|
193 |
]
|
|
|
196 |
datasets.SplitGenerator(
|
197 |
name=datasets.Split.TRAIN,
|
198 |
gen_kwargs={
|
199 |
+
"filepaths": ["ConceptNet/test.jsonl"],
|
200 |
+
"files": dl_manager.iter_archive(archive),
|
201 |
},
|
202 |
),
|
203 |
]
|
|
|
206 |
datasets.SplitGenerator(
|
207 |
name=datasets.Split.TRAIN,
|
208 |
gen_kwargs={
|
209 |
+
"filepaths": ["Squad/test.jsonl"],
|
210 |
+
"files": dl_manager.iter_archive(archive),
|
211 |
},
|
212 |
),
|
213 |
]
|
214 |
|
215 |
+
def _generate_examples(self, filepaths, files, relations_path=None):
|
216 |
"""Yields examples from the LAMA dataset."""
|
217 |
+
filepaths = list(filepaths)
|
218 |
if self.config.name == "trex":
|
|
|
|
|
|
|
219 |
all_rels = {}
|
220 |
with open(relations_path, encoding="utf-8") as f:
|
221 |
for row in f:
|
222 |
data = json.loads(row)
|
223 |
all_rels[data["relation"]] = data
|
224 |
id_ = -1
|
225 |
+
inside_trec_directory = False
|
226 |
+
for path, f in files:
|
227 |
+
if any(fnmatch(path, pattern) for pattern in filepaths):
|
228 |
+
inside_trec_directory = True
|
229 |
for row in f:
|
230 |
data = json.loads(row)
|
231 |
pred = all_rels.get(data["predicate_id"], {})
|
|
|
247 |
"description": str(pred.get("description", "")),
|
248 |
"type": str(pred.get("type", "")),
|
249 |
}
|
250 |
+
elif inside_trec_directory:
|
251 |
+
break
|
252 |
elif self.config.name == "conceptnet":
|
253 |
id_ = -1
|
254 |
+
for path, f in files:
|
255 |
+
if not filepaths:
|
256 |
+
break
|
257 |
+
if path in list(filepaths):
|
258 |
+
for row in f:
|
259 |
+
data = json.loads(row)
|
260 |
+
if data.get("negated") is not None:
|
261 |
+
for masked_sentence, negated in zip(data["masked_sentences"], data["negated"]):
|
262 |
+
id_ += 1
|
263 |
+
yield id_, {
|
264 |
+
"uuid": str(data["uuid"]),
|
265 |
+
"sub": str(data.get("sub", "")),
|
266 |
+
"obj": str(data.get("obj", "")),
|
267 |
+
"pred": str(data["pred"]),
|
268 |
+
"obj_label": str(data["obj_label"]),
|
269 |
+
"masked_sentence": str(masked_sentence),
|
270 |
+
"negated": str(negated),
|
271 |
+
}
|
272 |
+
else:
|
273 |
+
for masked_sentence in data["masked_sentences"]:
|
274 |
+
id_ += 1
|
275 |
+
yield id_, {
|
276 |
+
"uuid": str(data["uuid"]),
|
277 |
+
"sub": str(data.get("sub", "")),
|
278 |
+
"obj": str(data.get("obj", "")),
|
279 |
+
"pred": str(data["pred"]),
|
280 |
+
"obj_label": str(data["obj_label"]),
|
281 |
+
"masked_sentence": str(masked_sentence),
|
282 |
+
"negated": str(""),
|
283 |
+
}
|
284 |
+
filepaths.remove(path)
|
285 |
elif self.config.name == "squad":
|
286 |
id_ = -1
|
287 |
+
for path, f in files:
|
288 |
+
if not filepaths:
|
289 |
+
break
|
290 |
+
if path in filepaths:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
for row in f:
|
292 |
data = json.loads(row)
|
293 |
for masked_sentence in data["masked_sentences"]:
|
294 |
id_ += 1
|
295 |
yield id_, {
|
296 |
+
"id": str(data["id"]),
|
|
|
|
|
|
|
|
|
|
|
297 |
"sub_label": str(data["sub_label"]),
|
|
|
|
|
298 |
"obj_label": str(data["obj_label"]),
|
299 |
+
"negated": str(data.get("negated", "")),
|
|
|
300 |
"masked_sentence": str(masked_sentence),
|
|
|
|
|
301 |
}
|
302 |
+
filepaths.remove(path)
|
303 |
+
elif self.config.name == "google_re":
|
304 |
+
id_ = -1
|
305 |
+
for path, f in files:
|
306 |
+
if path in filepaths:
|
307 |
+
if not filepaths:
|
308 |
+
break
|
309 |
+
if path in filepaths:
|
310 |
+
# from https://github.com/facebookresearch/LAMA/blob/master/scripts/run_experiments.py
|
311 |
+
if "place_of_birth" in path:
|
312 |
+
pred = {
|
313 |
+
"relation": "place_of_birth",
|
314 |
+
"template": "[X] was born in [Y] .",
|
315 |
+
"template_negated": "[X] was not born in [Y] .",
|
316 |
+
}
|
317 |
+
elif "date_of_birth" in path:
|
318 |
+
pred = {
|
319 |
+
"relation": "date_of_birth",
|
320 |
+
"template": "[X] (born [Y]).",
|
321 |
+
"template_negated": "[X] (not born [Y]).",
|
322 |
+
}
|
323 |
+
else:
|
324 |
+
pred = {
|
325 |
+
"relation": "place_of_death",
|
326 |
+
"template": "[X] died in [Y] .",
|
327 |
+
"template_negated": "[X] did not die in [Y] .",
|
328 |
+
}
|
329 |
+
for row in f:
|
330 |
+
data = json.loads(row)
|
331 |
+
for masked_sentence in data["masked_sentences"]:
|
332 |
+
id_ += 1
|
333 |
+
yield id_, {
|
334 |
+
"pred": str(data["pred"]),
|
335 |
+
"sub": str(data["sub"]),
|
336 |
+
"obj": str(data["obj"]),
|
337 |
+
"evidences": str(data["evidences"]),
|
338 |
+
"judgments": str(data["judgments"]),
|
339 |
+
"sub_w": str(data["sub_w"]),
|
340 |
+
"sub_label": str(data["sub_label"]),
|
341 |
+
"sub_aliases": str(data["sub_aliases"]),
|
342 |
+
"obj_w": str(data["obj_w"]),
|
343 |
+
"obj_label": str(data["obj_label"]),
|
344 |
+
"obj_aliases": str(data["obj_aliases"]),
|
345 |
+
"uuid": str(data["uuid"]),
|
346 |
+
"masked_sentence": str(masked_sentence),
|
347 |
+
"template": str(pred["template"]),
|
348 |
+
"template_negated": str(pred["template_negated"]),
|
349 |
+
}
|
350 |
+
filepaths.remove(path)
|