File size: 17,805 Bytes
4769742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b99a0b
b34b79d
0b99a0b
4769742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b99a0b
 
 
 
4769742
0b99a0b
4769742
 
 
0b99a0b
4769742
 
0b99a0b
 
 
 
 
 
 
 
4769742
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
0b99a0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4769742
0b99a0b
4769742
 
 
0b99a0b
4769742
 
0b99a0b
 
 
 
4769742
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
0b99a0b
4769742
 
 
 
0b99a0b
 
 
 
 
 
 
 
4769742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349ca84
4769742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b34b79d
 
 
4769742
 
b34b79d
4769742
 
 
 
b34b79d
4769742
b34b79d
4769742
 
 
 
 
 
 
b34b79d
4769742
 
 
 
 
 
 
b34b79d
4769742
 
 
 
 
 
 
b34b79d
4769742
 
 
 
 
 
 
 
 
 
 
b34b79d
 
 
 
4769742
 
 
 
b34b79d
 
4769742
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# 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.

"""MultiSim is a growing collection of Text Simplfication datasets in multiple languages.  Each dataset is a set of complex and simple sentence pairs."""

import pandas as pd
import os
from collections import defaultdict
import urllib.parse
from huggingface_hub import snapshot_download


import datasets

_CITATION = """\
@inproceedings{ryan-etal-2023-revisiting,
    title = "Revisiting non-{E}nglish Text Simplification: A Unified Multilingual Benchmark",
    author = "Ryan, Michael  and
      Naous, Tarek  and
      Xu, Wei",
    booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
    month = jul,
    year = "2023",
    address = "Toronto, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2023.acl-long.269",
    pages = "4898--4927",
    abstract = "Recent advancements in high-quality, large-scale English resources have pushed the frontier of English Automatic Text Simplification (ATS) research. However, less work has been done on multilingual text simplification due to the lack of a diverse evaluation benchmark that covers complex-simple sentence pairs in many languages. This paper introduces the MultiSim benchmark, a collection of 27 resources in 12 distinct languages containing over 1.7 million complex-simple sentence pairs. This benchmark will encourage research in developing more effective multilingual text simplification models and evaluation metrics. Our experiments using MultiSim with pre-trained multilingual language models reveal exciting performance improvements from multilingual training in non-English settings. We observe strong performance from Russian in zero-shot cross-lingual transfer to low-resource languages. We further show that few-shot prompting with BLOOM-176b achieves comparable quality to reference simplifications outperforming fine-tuned models in most languages. We validate these findings through human evaluation.",
}
"""

# TODO: Add description of the dataset here
# You can copy an official description
_DESCRIPTION = """\
MultiSim is a growing collection of Text Simplfication datasets in multiple languages.  Each dataset is a set of complex and simple sentence pairs.
"""

# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = "https://github.com/XenonMolecule/MultiSim"

# TODO: Add the licence for the dataset here if you can find it
_LICENSE = """MIT License

Copyright (c) 2023 Michael Ryan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE."""

_SUBCORPORA = {
    # "NewselaEN": {
    #     "path": "data/English/Newsela EN",
    #     "language": "en"
    # },
    "WikiAutoEN": {
        "path": "data/English/WikiAuto",
        "language": "en"
    },
    "ASSET": {
        "path": "data/English/ASSET",
        "language": "en"
    },
    # "Simplext": {
    #     "path": "data/Spanish/Simplext",
    #     "language": "es"
    # },
    # "NewselaES": {
    #     "path": "data/Spanish/Newsela ES",
    #     "language": "es"
    # },
    "Terence": {
        "path" : "data/Italian/Terence",
        "language": "it"
    },
    "Teacher": {
        "path": "data/Italian/Teacher",
        "language": "it"
    },
    "SimpitikiWiki": {
        "path": "data/Italian/Simpitiki Italian Wikipedia",
        "language": "it"
    },
    "AdminIt": {
        "path": "data/Italian/AdminIT",
        "language": "it"
    },
    "PaCCSS-IT": {
        "path": "data/Italian/PaCCSS-IT Corpus",
        "language": "it"
    },
    "CLEAR" : {
        "path" : "data/French/CLEAR Corpus",
        "language": "fr"
    },
    "WikiLargeFR": {
        "path" : "data/French/WikiLargeFR Corpus",
        "language": "fr"
    },
    "EasyJapanese": {
        "path": "data/Japanese/Easy Japanese Corpus",
        "language": "ja"
    },
    "EasyJapaneseExtended": {
        "path": "data/Japanese/Easy Japanese Extended",
        "language": "ja"
    },
    "PorSimples" : {
        "path": "data/Brazilian Portuguese/PorSimples",
        "language": "pt-br"
    },
    "TextComplexityDE" : {
        "path": "data/German/TextComplexityDE Parallel Corpus",
        "language": "de"
    },
    "GEOLinoTest" : {
        "path" : "data/German/GEOLino Corpus",
        "language": "de"
    },
    # "GermanNews" : {
    #     "path" : "data/German/German News",
    #     "language": "de"
    # },
    # "CBST": {
    #     "path" : "data/Basque/CBST",
    #     "language": "eu"
    # },
    # "DSim": {
    #     "path": "data/Danish/DSim Corpus",
    #     "language": "da"
    # },
    # "SimplifyUR": {
    #     "path": "data/Urdu/SimplifyUR",
    #     "language": "ur"
    # },
    "RuWikiLarge": {
        "path" : "data/Russian/RuWikiLarge",
        "language": "ru"
    },
    "RSSE" : {
        "path": "data/Russian/RSSE Corpus",
        "language": "ru"
    },
    # "RuAdaptLit" : {
    #     "path": "data/Russian/RuAdapt Literature",
    #     "language": "ru"
    # },
    "RuAdaptFairytales" : {
        "path": "data/Russian/RuAdapt Fairytales",
        "language": "ru"
    },
    "RuAdaptEncy" : {
        "path" : "data/Russian/RuAdapt Ency",
        "language": "ru"
    },
    "TSSlovene" : {
        "path" : "data/Slovene/Text Simplification Slovene",
        "language": "sl"
    }
}

_URL = "https://huggingface.co/datasets/MichaelR207/MultiSim/raw/main"

_URLS = {
    dataset+"-"+split: urllib.parse.quote(os.path.join(_URL, _SUBCORPORA[dataset]["path"] + "_" + split + ".csv"), safe=':/') 
    for split in ["train", "val", "test"] 
    for dataset in _SUBCORPORA.keys()
}

_LANGUAGES = {
    "English":'en',
    "Spanish":'es', 
    "Italian":'it', 
    "French" : 'fr',
    "Japanese": 'ja',
    "Brazilian Portuguese": 'pt-br',
    "German": 'de',
    "Basque": 'eu',
    "Danish": 'da',
    "Urdu": 'ur',
    "Russian": 'ru',
    "Slovene": 'sl'
}


class MultiSim(datasets.GeneratorBasedBuilder):
    """MultiSim is a growing collection of Text Simplfication datasets in multiple languages.  Each dataset is a set of complex and simple sentence pairs."""

    VERSION = datasets.Version("1.0.0")

    # This is an example of a dataset with multiple configurations.
    # If you don't want/need to define several sub-sets in your dataset,
    # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

    # If you need to make complex sub-parts in the datasets with configurable options
    # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
    # BUILDER_CONFIG_CLASS = MyBuilderConfig

    # You will be able to load one or the other configurations in the following list with
    # data = datasets.load_dataset('my_dataset', 'first_domain')
    # data = datasets.load_dataset('my_dataset', 'second_domain')
    BUILDER_CONFIGS = [
        # datasets.BuilderConfig(name="NewselaEN", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="WikiAutoEN", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="ASSET", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="Simplext", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="NewselaES", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Terence", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Teacher", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="SimpitikiWiki", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="AdminIt", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="PaCCSS-IT", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="CLEAR", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="WikiLargeFR", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="EasyJapanese", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="EasyJapaneseExtended", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="PorSimples", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="TextComplexityDE", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="GEOLinoTest", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="GermanNews", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="CBST", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="DSim", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="SimplifyUR", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="RuWikiLarge", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="RSSE", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="RuAdaptLit", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="RuAdaptFairytales", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="RuAdaptEncy", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="TSSlovene", version=VERSION, description="TODO: Descriptions"),
        
        datasets.BuilderConfig(name="English", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="Spanish", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Italian", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="French", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Japanese", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Brazilian Portuguese", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="German", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="Basque", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="Danish", version=VERSION, description="TODO: Descriptions"),
        # datasets.BuilderConfig(name="Urdu", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Russian", version=VERSION, description="TODO: Descriptions"),
        datasets.BuilderConfig(name="Slovene", version=VERSION, description="TODO: Descriptions"),

        datasets.BuilderConfig(name="all", version=VERSION, description="TODO: Descriptions"),
    ]

    DEFAULT_CONFIG_NAME = "all"  # It's not mandatory to have a default configuration. Just use one if it make sense.

    def _info(self):
        # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
        features = datasets.Features(
            {
                "original": datasets.Value("string"),
                "simple": datasets.Sequence(feature={"simplifications" : datasets.Value("string")})
            }
        )
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features=features,  # Here we define them above because they are different between the two configurations
            # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
            # specify them. They'll be used if as_supervised=True in builder.as_dataset.
            # supervised_keys=("sentence", "label"),
            # Homepage of the dataset for documentation
            homepage=_HOMEPAGE,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
        # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name

        # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
        # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
        # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
        dataset_path = snapshot_download(repo_id="MichaelR207/MultiSim", repo_type="dataset")
        
        filepaths = []
        if (self.config.name == 'all'):
            for subcorpus in _SUBCORPORA:
                filepaths.append(os.path.join(dataset_path,_SUBCORPORA[subcorpus]['path']))
        elif (self.config.name in _LANGUAGES):
            lang_code = _LANGUAGES[self.config.name]
            for subcorpus in _SUBCORPORA:
                if _SUBCORPORA[subcorpus]['language'] == lang_code:
                    filepaths.append(os.path.join(dataset_path,_SUBCORPORA[subcorpus]['path']))
        elif (self.config.name in _SUBCORPORA):
            filepaths = [os.path.join(dataset_path,_SUBCORPORA[self.config.name]['path'])]
        else:
            print("Invalid configuration name: " + self.config.name + ".  Try 'all', 'English', 'ASSET', etc.")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepaths": filepaths,
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepaths": filepaths,
                    "split": "val",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepaths": filepaths,
                    "split": "test"
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepaths, split):
        # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
        # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
        df = pd.DataFrame()

        if (len(filepaths) > 1):
            for filepath in filepaths:
                if os.path.exists(filepath + "_" + split + ".csv"):
                    df = pd.concat([df, pd.read_csv(filepath + "_" + split + ".csv")])

            # shuffle the combined dataset
            df = df.sample(frac=1, random_state=3600).reset_index(drop=True)
        else:
            if os.path.exists(filepaths[0] + "_" + split + ".csv"):
                df = pd.read_csv(filepaths[0] + "_" + split + ".csv")

        if len(df) > 0:
            for key, row in df.iterrows():
                # Yields examples as (key, example) tuples
                original = row["original"]
                simple = []
                for label,content in row.items():
                    if label != "original" and type(content) != float:
                        simple.append({"simplifications": content})
                yield key, {
                    "original": original,
                    "simple": simple
                }