Download BiSECT.py from GEM/BiSECT: direct link, hf CLI and curl.
- Browser
- Download file 5.93 kB
-
https://huggingface.co/datasets/GEM/BiSECT/resolve/main/BiSECT.py
- Command line
-
hf download hf://datasets/GEM/BiSECT/BiSECT.py
-
curl -L -o BiSECT.py https://huggingface.co/datasets/GEM/BiSECT/resolve/main/BiSECT.py
5.93 kB
| # coding=utf-8 | |
| # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. | |
| # | |
| # 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. | |
| """BiSECT is a Split and Rephrase corpus created via bilingual pivoting.""" | |
| import os | |
| import datasets | |
| _CITATION = """\ | |
| @inproceedings{kim-etal-2021-bisect, | |
| title = "{B}i{SECT}: Learning to Split and Rephrase Sentences with Bitexts", | |
| author = "Kim, Joongwon and | |
| Maddela, Mounica and | |
| Kriz, Reno and | |
| Xu, Wei and | |
| Callison-Burch, Chris", | |
| booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing", | |
| month = nov, | |
| year = "2021", | |
| address = "Online and Punta Cana, Dominican Republic", | |
| publisher = "Association for Computational Linguistics", | |
| url = "https://aclanthology.org/2021.emnlp-main.500", | |
| pages = "6193--6209" | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| BiSECT is a Split and Rephrase corpus created via bilingual pivoting. | |
| """ | |
| _HOMEPAGE = "https://github.com/mounicam/BiSECT" | |
| _URL = "https://raw.githubusercontent.com/mounicam/BiSECT/main/" | |
| _URL_MAIN = _URL + "bisect/" | |
| _URL_CHALLENGE = _URL + "bisect_challenge/" | |
| _URLs = { | |
| datasets.Split.TRAIN: { | |
| "src": _URL_MAIN + "train.src.gz", | |
| "dst": _URL_MAIN + "train.dst.gz", | |
| }, | |
| datasets.Split.VALIDATION: { | |
| "src": _URL_MAIN + "valid.src.gz", | |
| "dst": _URL_MAIN + "valid.dst.gz", | |
| }, | |
| datasets.Split.TEST: { | |
| "src": _URL_MAIN + "test.src.gz", | |
| "dst": _URL_MAIN + "test.dst.gz", | |
| }, | |
| "challenge_hsplit": { | |
| "src": "https://raw.githubusercontent.com/cocoxu/simplification/master/data/turkcorpus/test.8turkers.tok.norm", | |
| "dst": "https://raw.githubusercontent.com/eliorsulem/HSplit-corpus/master/HSplit/HSplit2_full", | |
| }, | |
| "challenge_bisect": { | |
| "src": _URL_CHALLENGE + "challenge_test.src", | |
| "dst": _URL_CHALLENGE + "challenge_test.dst", | |
| }, | |
| } | |
| class BiSECT(datasets.GeneratorBasedBuilder): | |
| """The BiSECT Split and Rephrase corpus.""" | |
| VERSION = datasets.Version("1.1.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig( | |
| name="en", | |
| version=VERSION, | |
| description="English data described in the BiSECT paper", | |
| ), | |
| datasets.BuilderConfig( | |
| name="de", | |
| version=VERSION, | |
| description="German data described in the BiSECT paper", | |
| ), | |
| datasets.BuilderConfig( | |
| name="es", | |
| version=VERSION, | |
| description="Spanish data described in the BiSECT paper", | |
| ), | |
| datasets.BuilderConfig( | |
| name="fr", | |
| version=VERSION, | |
| description="French data described in the BiSECT paper", | |
| ), | |
| ] | |
| DEFAULT_CONFIG_NAME = "en" | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "gem_id": datasets.Value("string"), | |
| "source": datasets.Value("string"), | |
| "target": datasets.Value("string"), | |
| "references": [datasets.Value("string")], | |
| } | |
| ), | |
| supervised_keys=None, | |
| homepage=_HOMEPAGE, | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| """Returns SplitGenerators.""" | |
| if self.config.name == "en": | |
| data_dir = dl_manager.download_and_extract(_URLs) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=split_name, | |
| gen_kwargs={"filepath": data_dir[split_name], "split": split_name}, | |
| ) | |
| for split_name in data_dir | |
| ] | |
| else: | |
| lang = self.config.name | |
| url = _URL + "bisect_multilingual/" + f"bisect_{lang}.gz" | |
| data_dir = dl_manager.download_and_extract(url) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=f"{split}", | |
| gen_kwargs={ | |
| "filepath": os.path.join(data_dir, lang), | |
| "split": split, | |
| }, | |
| ) | |
| for split in ( | |
| datasets.Split.TRAIN, | |
| datasets.Split.VALIDATION, | |
| datasets.Split.TEST, | |
| ) | |
| ] | |
| def _generate_examples(self, filepath, split): | |
| """Yields examples as (key, example) tuples.""" | |
| if self.config.name == "en": | |
| source_filepath = filepath["src"] | |
| target_filepath = filepath["dst"] | |
| else: | |
| source_filepath = os.path.join(filepath, f"{split}.complex") | |
| target_filepath = os.path.join(filepath, f"{split}.simple") | |
| with open(source_filepath, encoding="utf-8") as f: | |
| source_lines = [line.strip() for line in f if line.strip()] | |
| with open(target_filepath, encoding="utf-8") as f: | |
| target_lines = [ | |
| line.strip().replace(" <SEP>", "") for line in f if line.strip() | |
| ] | |
| for id_ in range(len(source_lines)): | |
| yield id_, { | |
| "gem_id": f"BiSECT_{self.config.name}-{split}-{id_}", | |
| "source": source_lines[id_], | |
| "target": target_lines[id_], | |
| "references": [target_lines[id_]], | |
| } | |