Datasets:
Modalities:
Text
Sub-tasks:
masked-language-modeling
Languages:
English
Size:
1M - 10M
ArXiv:
License:
| # coding=utf-8 | |
| # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # Lint as: python3 | |
| """The FTRACE benchmark.""" | |
| import json | |
| import os | |
| import textwrap | |
| import datasets | |
| _FTRACE_CITATION = """\ | |
| """ | |
| _FTRACE_DESCRIPTION = """\ | |
| Factual Tracing Dataset that contains queries and abstracts, and their corresponding ground truth. | |
| """ | |
| _FTRACE_ABSTRACTS_DESCRIPTION = """\ | |
| Abstracts based on TREx dataset. | |
| """ | |
| _FTRACE_ABSTRACTS_LICENSE = """\ | |
| Creative Commons Attribution-ShareAlike 4.0 International License. | |
| see https://creativecommons.org/licenses/by-sa/4.0/""" | |
| _FTRACE_ABSTRACTS_CITATION = """\ | |
| @inproceedings{elsahar2018t, | |
| title={T-rex: A large scale alignment of natural language with knowledge base triples}, | |
| author={Elsahar, Hady and Vougiouklis, Pavlos and Remaci, Arslen and Gravier, Christophe and Hare, Jonathon and Laforest, Frederique and Simperl, Elena}, | |
| booktitle={Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC 2018)}, | |
| year={2018} | |
| }""" | |
| _FTRACE_QUERIES_DESCRIPTION = """\ | |
| Queries based on LAMA dataset. | |
| """ | |
| _FTRACE_QUERIES_CITATION = """\ | |
| @inproceedings{petroni2019language, | |
| title={Language Models as Knowledge Bases?}, | |
| author={F. Petroni, T. Rockt{\"{a}}schel, A. H. Miller, P. Lewis, A. Bakhtin, Y. Wu and S. Riedel}, | |
| booktitle={In: Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2019}, | |
| year={2019} | |
| }""" | |
| FTRACE_QUERIES_LICENSE = """\ | |
| The Creative Commons Attribution-Noncommercial 4.0 International License. | |
| see https://github.com/facebookresearch/LAMA/blob/master/LICENSE""" | |
| class FTRACEConfig(datasets.BuilderConfig): | |
| """BuilderConfig for FTRACE.""" | |
| def __init__( | |
| self, | |
| features, | |
| data_url, | |
| citation, | |
| license, | |
| url, | |
| **kwargs, | |
| ): | |
| """BuilderConfig for FTRACE. | |
| Args: | |
| features: `list[string]`, list of the features that will appear in the | |
| feature dict. Should not include "label". | |
| data_url: `string`, url to download the zip file from. | |
| citation: `string`, citation for the data set. | |
| url: `string`, url for information about the data set. | |
| **kwargs: keyword arguments forwarded to super. | |
| """ | |
| # Version history: | |
| # 0.0.2: Initial version. | |
| super(FTRACEConfig, self).__init__( | |
| version=datasets.Version("0.0.2"), **kwargs | |
| ) | |
| self.features = features | |
| self.data_url = data_url | |
| self.citation = citation | |
| self.license = license | |
| self.url = url | |
| class FTRACE(datasets.GeneratorBasedBuilder): | |
| """The SuperFTRACE benchmark.""" | |
| BUILDER_CONFIGS = [ | |
| FTRACEConfig( | |
| name="abstracts", | |
| description=_FTRACE_ABSTRACTS_DESCRIPTION, | |
| features=[ | |
| "inputs_pretokenized", | |
| "targets_pretokenized", | |
| "masked_uri", | |
| "masked_type", | |
| "facts", | |
| "id", | |
| "example_uris", | |
| "page_uri", | |
| ], | |
| data_url="https://people.csail.mit.edu/akyurek/ftrace/abstracts.zip", | |
| citation=textwrap.dedent(_FTRACE_ABSTRACTS_CITATION), | |
| license=_FTRACE_ABSTRACTS_LICENSE, | |
| url="https://hadyelsahar.github.io/t-rex/", | |
| ), | |
| FTRACEConfig( | |
| name="queries", | |
| description=_FTRACE_QUERIES_DESCRIPTION, | |
| features=[ | |
| "inputs_pretokenized", | |
| "targets_pretokenized", | |
| "uuid", | |
| "obj_uri", | |
| "sub_uri", | |
| "predicate_id", | |
| "sub_surface", | |
| "obj_surface", | |
| ], | |
| data_url="https://people.csail.mit.edu/akyurek/ftrace/queries.zip", | |
| citation=textwrap.dedent(_FTRACE_QUERIES_CITATION), | |
| license=FTRACE_QUERIES_LICENSE, | |
| url="https://github.com/facebookresearch/LAMA", | |
| ), | |
| ] | |
| def _info(self): | |
| features = { | |
| feature: datasets.Value("string") | |
| for feature in self.config.features | |
| } | |
| return datasets.DatasetInfo( | |
| description=_FTRACE_DESCRIPTION + self.config.description, | |
| features=datasets.Features(features), | |
| homepage=self.config.url, | |
| citation=self.config.citation + "\n" + _FTRACE_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| dl_dir = dl_manager.download_and_extract(self.config.data_url) or "" | |
| task_name = _get_task_name_from_data_url(self.config.data_url) | |
| dl_dir = os.path.join(dl_dir, task_name) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={ | |
| "data_file": os.path.join(dl_dir, "train.jsonl"), | |
| "split": "train", | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, data_file, split): | |
| with open(data_file, encoding="utf-8") as f: | |
| for idx, line in enumerate(f): | |
| row = json.loads(line) | |
| yield idx, row | |
| def _get_task_name_from_data_url(data_url): | |
| if "queries" in data_url: | |
| return "queries" | |
| elif "abstracts" in data_url: | |
| return "abstracts" | |
| return "queries" | |