Datasets:

Multilinguality:
multilingual
Language Creators:
found
Annotations Creators:
no-annotation
Source Datasets:
original
ArXiv:
License:
versae commited on
Commit
aa99455
1 Parent(s): c555645

Dataset files

Browse files
Files changed (3) hide show
  1. README.md +531 -0
  2. dummy/af/0.0.0/dummy_data.zip +0 -0
  3. mc4-sampling.py +429 -0
README.md ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: mC4-sampling
3
+ annotations_creators:
4
+ - no-annotation
5
+ language_creators:
6
+ - found
7
+ languages:
8
+ - af
9
+ - am
10
+ - ar
11
+ - az
12
+ - be
13
+ - bg
14
+ - bg-Latn
15
+ - bn
16
+ - ca
17
+ - ceb
18
+ - co
19
+ - cs
20
+ - cy
21
+ - da
22
+ - de
23
+ - el
24
+ - el-Latn
25
+ - en
26
+ - eo
27
+ - es
28
+ - et
29
+ - eu
30
+ - fa
31
+ - fi
32
+ - fil
33
+ - fr
34
+ - fy
35
+ - ga
36
+ - gd
37
+ - gl
38
+ - gu
39
+ - ha
40
+ - haw
41
+ - hi
42
+ - hi-Latn
43
+ - hmn
44
+ - ht
45
+ - hu
46
+ - hy
47
+ - id
48
+ - ig
49
+ - is
50
+ - it
51
+ - iw
52
+ - ja
53
+ - ja-Latn
54
+ - jv
55
+ - ka
56
+ - kk
57
+ - km
58
+ - kn
59
+ - ko
60
+ - ku
61
+ - ky
62
+ - la
63
+ - lb
64
+ - lo
65
+ - lt
66
+ - lv
67
+ - mg
68
+ - mi
69
+ - mk
70
+ - ml
71
+ - mn
72
+ - mr
73
+ - ms
74
+ - mt
75
+ - my
76
+ - ne
77
+ - nl
78
+ - "no"
79
+ - ny
80
+ - pa
81
+ - pl
82
+ - ps
83
+ - pt
84
+ - ro
85
+ - ru
86
+ - ru-Latn
87
+ - sd
88
+ - si
89
+ - sk
90
+ - sl
91
+ - sm
92
+ - sn
93
+ - so
94
+ - sq
95
+ - sr
96
+ - st
97
+ - su
98
+ - sv
99
+ - sw
100
+ - ta
101
+ - te
102
+ - tg
103
+ - th
104
+ - tr
105
+ - uk
106
+ - und
107
+ - ur
108
+ - uz
109
+ - vi
110
+ - xh
111
+ - yi
112
+ - yo
113
+ - zh
114
+ - zh-Latn
115
+ - zu
116
+ licenses:
117
+ - odc-by-1.0
118
+ multilinguality:
119
+ - multilingual
120
+ size_categories:
121
+ - n<1K
122
+ - 1K<n<10K
123
+ - 10K<n<100K
124
+ - 100K<n<1M
125
+ - 1M<n<10M
126
+ - 10M<n<100M
127
+ - 100M<n<1B
128
+ - 1B<n<10B
129
+ source_datasets:
130
+ - original
131
+ task_categories:
132
+ - sequence-modeling
133
+ task_ids:
134
+ - language-modeling
135
+ paperswithcode_id: mc4
136
+ ---
137
+
138
+ # Dataset Card for mC4
139
+
140
+ ## Table of Contents
141
+
142
+ - [Dataset Card for mC4](#dataset-card-for-mc4)
143
+ - [Table of Contents](#table-of-contents)
144
+ - [Dataset Description](#dataset-description)
145
+ - [Dataset Summary](#dataset-summary)
146
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
147
+ - [Languages](#languages)
148
+ - [Dataset Structure](#dataset-structure)
149
+ - [Data Instances](#data-instances)
150
+ - [Data Fields](#data-fields)
151
+ - [Data Splits](#data-splits)
152
+ - [Dataset Creation](#dataset-creation)
153
+ - [Curation Rationale](#curation-rationale)
154
+ - [Source Data](#source-data)
155
+ - [Initial Data Collection and Normalization](#initial-data-collection-and-normalization)
156
+ - [Who are the source language producers?](#who-are-the-source-language-producers)
157
+ - [Annotations](#annotations)
158
+ - [Annotation process](#annotation-process)
159
+ - [Who are the annotators?](#who-are-the-annotators)
160
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
161
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
162
+ - [Social Impact of Dataset](#social-impact-of-dataset)
163
+ - [Discussion of Biases](#discussion-of-biases)
164
+ - [Other Known Limitations](#other-known-limitations)
165
+ - [Additional Information](#additional-information)
166
+ - [Dataset Curators](#dataset-curators)
167
+ - [Licensing Information](#licensing-information)
168
+ - [Citation Information](#citation-information)
169
+ - [Contributions](#contributions)
170
+
171
+ ## Dataset Description
172
+
173
+ - **Homepage:** https://huggingface.co/datasets/allenai/c4
174
+ - **Paper:** https://arxiv.org/abs/1910.10683
175
+
176
+ ### Dataset Summary
177
+
178
+ This dataset builds upon the original mC4 and adds perplexity sampling methods to perform filtering on the fly. Please, refer to [BERTIN Project](https://huggingface.co/bertin-project/bertin-roberta-base-spanish).
179
+
180
+ [ADD MORE DETAILS ON PERPLEXITY SAMPLING!]
181
+
182
+ The original dataset is the multilingual colossal, cleaned version of Common Crawl's web crawl corpus. Based on Common Crawl dataset: "https://commoncrawl.org".
183
+
184
+ This is the version prepared by AllenAI, hosted at this address: https://huggingface.co/datasets/allenai/c4
185
+
186
+ 108 languages are available and are reported in the table below.
187
+
188
+ Note that the languages that end with "-Latn" are simply romanized variants, i.e. written using the Latin script.
189
+
190
+ | language code | language name |
191
+ |:----------------|:---------------------|
192
+ | af | Afrikaans |
193
+ | am | Amharic |
194
+ | ar | Arabic |
195
+ | az | Azerbaijani |
196
+ | be | Belarusian |
197
+ | bg | Bulgarian |
198
+ | bg-Latn | Bulgarian (Latin) |
199
+ | bn | Bangla |
200
+ | ca | Catalan |
201
+ | ceb | Cebuano |
202
+ | co | Corsican |
203
+ | cs | Czech |
204
+ | cy | Welsh |
205
+ | da | Danish |
206
+ | de | German |
207
+ | el | Greek |
208
+ | el-Latn | Greek (Latin) |
209
+ | en | English |
210
+ | eo | Esperanto |
211
+ | es | Spanish |
212
+ | et | Estonian |
213
+ | eu | Basque |
214
+ | fa | Persian |
215
+ | fi | Finnish |
216
+ | fil | Filipino |
217
+ | fr | French |
218
+ | fy | Western Frisian |
219
+ | ga | Irish |
220
+ | gd | Scottish Gaelic |
221
+ | gl | Galician |
222
+ | gu | Gujarati |
223
+ | ha | Hausa |
224
+ | haw | Hawaiian |
225
+ | hi | Hindi |
226
+ | hi-Latn | Hindi (Latin script) |
227
+ | hmn | Hmong, Mong |
228
+ | ht | Haitian |
229
+ | hu | Hungarian |
230
+ | hy | Armenian |
231
+ | id | Indonesian |
232
+ | ig | Igbo |
233
+ | is | Icelandic |
234
+ | it | Italian |
235
+ | iw | former Hebrew |
236
+ | ja | Japanese |
237
+ | ja-Latn | Japanese (Latin) |
238
+ | jv | Javanese |
239
+ | ka | Georgian |
240
+ | kk | Kazakh |
241
+ | km | Khmer |
242
+ | kn | Kannada |
243
+ | ko | Korean |
244
+ | ku | Kurdish |
245
+ | ky | Kyrgyz |
246
+ | la | Latin |
247
+ | lb | Luxembourgish |
248
+ | lo | Lao |
249
+ | lt | Lithuanian |
250
+ | lv | Latvian |
251
+ | mg | Malagasy |
252
+ | mi | Maori |
253
+ | mk | Macedonian |
254
+ | ml | Malayalam |
255
+ | mn | Mongolian |
256
+ | mr | Marathi |
257
+ | ms | Malay |
258
+ | mt | Maltese |
259
+ | my | Burmese |
260
+ | ne | Nepali |
261
+ | nl | Dutch |
262
+ | no | Norwegian |
263
+ | ny | Nyanja |
264
+ | pa | Punjabi |
265
+ | pl | Polish |
266
+ | ps | Pashto |
267
+ | pt | Portuguese |
268
+ | ro | Romanian |
269
+ | ru | Russian |
270
+ | ru-Latn | Russian (Latin) |
271
+ | sd | Sindhi |
272
+ | si | Sinhala |
273
+ | sk | Slovak |
274
+ | sl | Slovenian |
275
+ | sm | San Marino |
276
+ | sn | Shona |
277
+ | so | Somali |
278
+ | sq | Albanian |
279
+ | sr | Serbian |
280
+ | st | Southern Sotho |
281
+ | su | Sundanese |
282
+ | sv | Swedish |
283
+ | sw | Swahili |
284
+ | ta | Tamil |
285
+ | te | Telugu |
286
+ | tg | Tajik |
287
+ | th | Thai |
288
+ | tr | Turkish |
289
+ | uk | Ukrainian |
290
+ | und | Unknown language |
291
+ | ur | Urdu |
292
+ | uz | Uzbek |
293
+ | vi | Vietnamese |
294
+ | xh | Xhosa |
295
+ | yi | Yiddish |
296
+ | yo | Yoruba |
297
+ | zh | Chinese |
298
+ | zh-Latn | Chinese (Latin) |
299
+ | zu | Zulu |
300
+
301
+ You can load the mC4 subset of any language like this:
302
+
303
+ ```python
304
+ from datasets import load_dataset
305
+
306
+ en_mc4 = load_dataset("mc4", "en")
307
+ ```
308
+
309
+ And if you can even specify a list of languages:
310
+
311
+ ```python
312
+ from datasets import load_dataset
313
+
314
+ mc4_subset_with_five_languages = load_dataset("mc4", languages=["en", "fr", "es", "de", "zh"])
315
+ ```
316
+
317
+ ### Supported Tasks and Leaderboards
318
+
319
+ mC4 is mainly intended to pretrain language models and word representations.
320
+
321
+ ### Languages
322
+
323
+ The dataset supports 108 languages.
324
+
325
+ ## Dataset Structure
326
+
327
+ ### Data Instances
328
+
329
+ An example form the `en` config is:
330
+
331
+ ```
332
+ {'timestamp': '2018-06-24T01:32:39Z',
333
+ 'text': 'Farm Resources in Plumas County\nShow Beginning Farmer Organizations & Professionals (304)\nThere are 304 resources serving Plumas County in the following categories:\nMap of Beginning Farmer Organizations & Professionals serving Plumas County\nVictoria Fisher - Office Manager - Loyalton, CA\nAmy Lynn Rasband - UCCE Plumas-Sierra Administrative Assistant II - Quincy , CA\nShow Farm Income Opportunities Organizations & Professionals (353)\nThere are 353 resources serving Plumas County in the following categories:\nFarm Ranch And Forest Retailers (18)\nMap of Farm Income Opportunities Organizations & Professionals serving Plumas County\nWarner Valley Wildlife Area - Plumas County\nShow Farm Resources Organizations & Professionals (297)\nThere are 297 resources serving Plumas County in the following categories:\nMap of Farm Resources Organizations & Professionals serving Plumas County\nThere are 57 resources serving Plumas County in the following categories:\nMap of Organic Certification Organizations & Professionals serving Plumas County',
334
+ 'url': 'http://www.californialandcan.org/Plumas/Farm-Resources/'}
335
+ ```
336
+
337
+ ### Data Fields
338
+
339
+ The data have several fields:
340
+
341
+ - `url`: url of the source as a string
342
+ - `text`: text content as a string
343
+ - `timestamp`: timestamp as a string
344
+
345
+ ### Data Splits
346
+
347
+ To build mC4, the authors used [CLD3](https://github.com/google/cld3) to identify over 100 languages. The resulting mC4 subsets for each language are reported in this table:
348
+
349
+ | config | train | validation |
350
+ |:---------|:--------|:-------------|
351
+ | af | ? | ? |
352
+ | am | ? | ? |
353
+ | ar | ? | ? |
354
+ | az | ? | ? |
355
+ | be | ? | ? |
356
+ | bg | ? | ? |
357
+ | bg-Latn | ? | ? |
358
+ | bn | ? | ? |
359
+ | ca | ? | ? |
360
+ | ceb | ? | ? |
361
+ | co | ? | ? |
362
+ | cs | ? | ? |
363
+ | cy | ? | ? |
364
+ | da | ? | ? |
365
+ | de | ? | ? |
366
+ | el | ? | ? |
367
+ | el-Latn | ? | ? |
368
+ | en | ? | ? |
369
+ | eo | ? | ? |
370
+ | es | ? | ? |
371
+ | et | ? | ? |
372
+ | eu | ? | ? |
373
+ | fa | ? | ? |
374
+ | fi | ? | ? |
375
+ | fil | ? | ? |
376
+ | fr | ? | ? |
377
+ | fy | ? | ? |
378
+ | ga | ? | ? |
379
+ | gd | ? | ? |
380
+ | gl | ? | ? |
381
+ | gu | ? | ? |
382
+ | ha | ? | ? |
383
+ | haw | ? | ? |
384
+ | hi | ? | ? |
385
+ | hi-Latn | ? | ? |
386
+ | hmn | ? | ? |
387
+ | ht | ? | ? |
388
+ | hu | ? | ? |
389
+ | hy | ? | ? |
390
+ | id | ? | ? |
391
+ | ig | ? | ? |
392
+ | is | ? | ? |
393
+ | it | ? | ? |
394
+ | iw | ? | ? |
395
+ | ja | ? | ? |
396
+ | ja-Latn | ? | ? |
397
+ | jv | ? | ? |
398
+ | ka | ? | ? |
399
+ | kk | ? | ? |
400
+ | km | ? | ? |
401
+ | kn | ? | ? |
402
+ | ko | ? | ? |
403
+ | ku | ? | ? |
404
+ | ky | ? | ? |
405
+ | la | ? | ? |
406
+ | lb | ? | ? |
407
+ | lo | ? | ? |
408
+ | lt | ? | ? |
409
+ | lv | ? | ? |
410
+ | mg | ? | ? |
411
+ | mi | ? | ? |
412
+ | mk | ? | ? |
413
+ | ml | ? | ? |
414
+ | mn | ? | ? |
415
+ | mr | ? | ? |
416
+ | ms | ? | ? |
417
+ | mt | ? | ? |
418
+ | my | ? | ? |
419
+ | ne | ? | ? |
420
+ | nl | ? | ? |
421
+ | no | ? | ? |
422
+ | ny | ? | ? |
423
+ | pa | ? | ? |
424
+ | pl | ? | ? |
425
+ | ps | ? | ? |
426
+ | pt | ? | ? |
427
+ | ro | ? | ? |
428
+ | ru | ? | ? |
429
+ | ru-Latn | ? | ? |
430
+ | sd | ? | ? |
431
+ | si | ? | ? |
432
+ | sk | ? | ? |
433
+ | sl | ? | ? |
434
+ | sm | ? | ? |
435
+ | sn | ? | ? |
436
+ | so | ? | ? |
437
+ | sq | ? | ? |
438
+ | sr | ? | ? |
439
+ | st | ? | ? |
440
+ | su | ? | ? |
441
+ | sv | ? | ? |
442
+ | sw | ? | ? |
443
+ | ta | ? | ? |
444
+ | te | ? | ? |
445
+ | tg | ? | ? |
446
+ | th | ? | ? |
447
+ | tr | ? | ? |
448
+ | uk | ? | ? |
449
+ | und | ? | ? |
450
+ | ur | ? | ? |
451
+ | uz | ? | ? |
452
+ | vi | ? | ? |
453
+ | xh | ? | ? |
454
+ | yi | ? | ? |
455
+ | yo | ? | ? |
456
+ | zh | ? | ? |
457
+ | zh-Latn | ? | ? |
458
+ | zu | ? | ? |
459
+
460
+ ## Dataset Creation
461
+
462
+ ### Curation Rationale
463
+
464
+ [More Information Needed]
465
+
466
+ ### Source Data
467
+
468
+ #### Initial Data Collection and Normalization
469
+
470
+ [More Information Needed]
471
+
472
+ #### Who are the source language producers?
473
+
474
+ [More Information Needed]
475
+
476
+ ### Annotations
477
+
478
+ #### Annotation process
479
+
480
+ [More Information Needed]
481
+
482
+ #### Who are the annotators?
483
+
484
+ [More Information Needed]
485
+
486
+ ### Personal and Sensitive Information
487
+
488
+ [More Information Needed]
489
+
490
+ ## Considerations for Using the Data
491
+
492
+ ### Social Impact of Dataset
493
+
494
+ [More Information Needed]
495
+
496
+ ### Discussion of Biases
497
+
498
+ [More Information Needed]
499
+
500
+ ### Other Known Limitations
501
+
502
+ [More Information Needed]
503
+
504
+ ## Additional Information
505
+
506
+ ### Dataset Curators
507
+
508
+ [More Information Needed]
509
+
510
+ ### Licensing Information
511
+
512
+ AllenAI are releasing this dataset under the terms of ODC-BY. By using this, you are also bound by the Common Crawl terms of use in respect of the content contained in the dataset.
513
+
514
+ ### Citation Information
515
+
516
+ ```
517
+ @article{2019t5,
518
+ author = {Colin Raffel and Noam Shazeer and Adam Roberts and Katherine Lee and Sharan Narang and Michael Matena and Yanqi Zhou and Wei Li and Peter J. Liu},
519
+ title = {Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer},
520
+ journal = {arXiv e-prints},
521
+ year = {2019},
522
+ archivePrefix = {arXiv},
523
+ eprint = {1910.10683},
524
+ }
525
+ ```
526
+
527
+ ### Contributions
528
+
529
+ Dataset contributed by [@versae](https://github.com/versae).
530
+
531
+ Thanks to [@dirkgr](https://github.com/dirkgr) and [@lhoestq](https://github.com/lhoestq) for adding the original mC4 dataset.
dummy/af/0.0.0/dummy_data.zip ADDED
Binary file (8.54 kB). View file
 
mc4-sampling.py ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Perplexity Sampled mC4 dataset based on Common Crawl."""
2
+
3
+
4
+ import gzip
5
+ import json
6
+
7
+ import datasets
8
+ import kenlm # pip install https://github.com/kpu/kenlm/archive/master.zip
9
+ import numpy as np
10
+ from numpy.random import default_rng
11
+
12
+
13
+ logger = datasets.logging.get_logger(__name__)
14
+
15
+
16
+ _DESCRIPTION = """\
17
+ A sampling-enabled version of mC4, the colossal, cleaned version of Common Crawl's web crawl corpus.
18
+
19
+ Based on Common Crawl dataset: "https://commoncrawl.org".
20
+
21
+ This is a version of the processed version of Google's mC4 dataset by AllenAI, in which sampling methods are implemented to perform on the fly.
22
+ """
23
+
24
+ _CITATION = """
25
+ @article{2019t5,
26
+ author = {Colin Raffel and Noam Shazeer and Adam Roberts and Katherine Lee and Sharan Narang and Michael Matena and Yanqi Zhou and Wei Li and Peter J. Liu},
27
+ title = {Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer},
28
+ journal = {arXiv e-prints},
29
+ year = {2019},
30
+ archivePrefix = {arXiv},
31
+ eprint = {1910.10683},
32
+ }
33
+ """
34
+
35
+ _URL = "https://github.com/allenai/allennlp/discussions/5056"
36
+
37
+ _DATA_URL = "https://huggingface.co/datasets/allenai/c4/resolve/1ddc917116b730e1859edef32896ec5c16be51d0/multilingual/c4-{language}{split_suffix}.tfrecord-{index:05d}-of-{n_shards:05d}.json.gz"
38
+
39
+ _LANGUAGES = [
40
+ "af",
41
+ "am",
42
+ "ar",
43
+ "az",
44
+ "be",
45
+ "bg",
46
+ "bg-Latn",
47
+ "bn",
48
+ "ca",
49
+ "ceb",
50
+ "co",
51
+ "cs",
52
+ "cy",
53
+ "da",
54
+ "de",
55
+ "el",
56
+ "el-Latn",
57
+ "en",
58
+ "eo",
59
+ "es",
60
+ "et",
61
+ "eu",
62
+ "fa",
63
+ "fi",
64
+ "fil",
65
+ "fr",
66
+ "fy",
67
+ "ga",
68
+ "gd",
69
+ "gl",
70
+ "gu",
71
+ "ha",
72
+ "haw",
73
+ "hi",
74
+ "hi-Latn",
75
+ "hmn",
76
+ "ht",
77
+ "hu",
78
+ "hy",
79
+ "id",
80
+ "ig",
81
+ "is",
82
+ "it",
83
+ "iw",
84
+ "ja",
85
+ "ja-Latn",
86
+ "jv",
87
+ "ka",
88
+ "kk",
89
+ "km",
90
+ "kn",
91
+ "ko",
92
+ "ku",
93
+ "ky",
94
+ "la",
95
+ "lb",
96
+ "lo",
97
+ "lt",
98
+ "lv",
99
+ "mg",
100
+ "mi",
101
+ "mk",
102
+ "ml",
103
+ "mn",
104
+ "mr",
105
+ "ms",
106
+ "mt",
107
+ "my",
108
+ "ne",
109
+ "nl",
110
+ "no",
111
+ "ny",
112
+ "pa",
113
+ "pl",
114
+ "ps",
115
+ "pt",
116
+ "ro",
117
+ "ru",
118
+ "ru-Latn",
119
+ "sd",
120
+ "si",
121
+ "sk",
122
+ "sl",
123
+ "sm",
124
+ "sn",
125
+ "so",
126
+ "sq",
127
+ "sr",
128
+ "st",
129
+ "su",
130
+ "sv",
131
+ "sw",
132
+ "ta",
133
+ "te",
134
+ "tg",
135
+ "th",
136
+ "tr",
137
+ "uk",
138
+ "und",
139
+ "ur",
140
+ "uz",
141
+ "vi",
142
+ "xh",
143
+ "yi",
144
+ "yo",
145
+ "zh",
146
+ "zh-Latn",
147
+ "zu",
148
+ ]
149
+
150
+ _N_SHARDS_PER_SPLIT = {
151
+ "af": {"train": 64, "validation": 1},
152
+ "am": {"train": 16, "validation": 1},
153
+ "ar": {"train": 1024, "validation": 4},
154
+ "az": {"train": 256, "validation": 1},
155
+ "be": {"train": 128, "validation": 1},
156
+ "bg": {"train": 1024, "validation": 1},
157
+ "bg-Latn": {"train": 4, "validation": 1},
158
+ "bn": {"train": 512, "validation": 1},
159
+ "ca": {"train": 512, "validation": 1},
160
+ "ceb": {"train": 8, "validation": 1},
161
+ "co": {"train": 8, "validation": 1},
162
+ "cs": {"train": 1024, "validation": 2},
163
+ "cy": {"train": 256, "validation": 1},
164
+ "da": {"train": 1024, "validation": 1},
165
+ "de": {"train": 2048, "validation": 16},
166
+ "el": {"train": 1024, "validation": 2},
167
+ "el-Latn": {"train": 16, "validation": 1},
168
+ "en": {"train": 11264, "validation": 128},
169
+ "eo": {"train": 32, "validation": 1},
170
+ "es": {"train": 2048, "validation": 16},
171
+ "et": {"train": 256, "validation": 1},
172
+ "eu": {"train": 64, "validation": 1},
173
+ "fa": {"train": 1024, "validation": 2},
174
+ "fi": {"train": 1024, "validation": 1},
175
+ "fil": {"train": 64, "validation": 1},
176
+ "fr": {"train": 2048, "validation": 16},
177
+ "fy": {"train": 16, "validation": 1},
178
+ "ga": {"train": 16, "validation": 1},
179
+ "gd": {"train": 16, "validation": 1},
180
+ "gl": {"train": 128, "validation": 1},
181
+ "gu": {"train": 64, "validation": 1},
182
+ "ha": {"train": 8, "validation": 1},
183
+ "haw": {"train": 2, "validation": 1},
184
+ "hi": {"train": 1024, "validation": 2},
185
+ "hi-Latn": {"train": 16, "validation": 1},
186
+ "hmn": {"train": 8, "validation": 1},
187
+ "ht": {"train": 8, "validation": 1},
188
+ "hu": {"train": 1024, "validation": 2},
189
+ "hy": {"train": 128, "validation": 1},
190
+ "id": {"train": 1024, "validation": 4},
191
+ "ig": {"train": 4, "validation": 1},
192
+ "is": {"train": 128, "validation": 1},
193
+ "it": {"train": 1024, "validation": 8},
194
+ "iw": {"train": 1024, "validation": 1},
195
+ "ja": {"train": 1024, "validation": 8},
196
+ "ja-Latn": {"train": 8, "validation": 1},
197
+ "jv": {"train": 8, "validation": 1},
198
+ "ka": {"train": 256, "validation": 1},
199
+ "kk": {"train": 256, "validation": 1},
200
+ "km": {"train": 64, "validation": 1},
201
+ "kn": {"train": 64, "validation": 1},
202
+ "ko": {"train": 1024, "validation": 1},
203
+ "ku": {"train": 16, "validation": 1},
204
+ "ky": {"train": 64, "validation": 1},
205
+ "la": {"train": 64, "validation": 1},
206
+ "lb": {"train": 32, "validation": 1},
207
+ "lo": {"train": 8, "validation": 1},
208
+ "lt": {"train": 512, "validation": 1},
209
+ "lv": {"train": 256, "validation": 1},
210
+ "mg": {"train": 8, "validation": 1},
211
+ "mi": {"train": 4, "validation": 1},
212
+ "mk": {"train": 128, "validation": 1},
213
+ "ml": {"train": 128, "validation": 1},
214
+ "mn": {"train": 128, "validation": 1},
215
+ "mr": {"train": 1024, "validation": 1},
216
+ "ms": {"train": 512, "validation": 1},
217
+ "mt": {"train": 128, "validation": 1},
218
+ "my": {"train": 64, "validation": 1},
219
+ "ne": {"train": 256, "validation": 1},
220
+ "nl": {"train": 1024, "validation": 4},
221
+ "no": {"train": 1024, "validation": 1},
222
+ "ny": {"train": 4, "validation": 1},
223
+ "pa": {"train": 32, "validation": 1},
224
+ "pl": {"train": 1024, "validation": 4},
225
+ "ps": {"train": 16, "validation": 1},
226
+ "pt": {"train": 1024, "validation": 4},
227
+ "ro": {"train": 1024, "validation": 2},
228
+ "ru": {"train": 4096, "validation": 32},
229
+ "ru-Latn": {"train": 32, "validation": 1},
230
+ "sd": {"train": 64, "validation": 1},
231
+ "si": {"train": 64, "validation": 1},
232
+ "sk": {"train": 512, "validation": 1},
233
+ "sl": {"train": 256, "validation": 1},
234
+ "sm": {"train": 4, "validation": 1},
235
+ "sn": {"train": 8, "validation": 1},
236
+ "so": {"train": 64, "validation": 1},
237
+ "sq": {"train": 128, "validation": 1},
238
+ "sr": {"train": 256, "validation": 1},
239
+ "st": {"train": 2, "validation": 1},
240
+ "su": {"train": 4, "validation": 1},
241
+ "sv": {"train": 1024, "validation": 2},
242
+ "sw": {"train": 32, "validation": 1},
243
+ "ta": {"train": 256, "validation": 1},
244
+ "te": {"train": 128, "validation": 1},
245
+ "tg": {"train": 64, "validation": 1},
246
+ "th": {"train": 1024, "validation": 1},
247
+ "tr": {"train": 1024, "validation": 4},
248
+ "uk": {"train": 1024, "validation": 2},
249
+ "und": {"train": 3072, "validation": 32},
250
+ "ur": {"train": 128, "validation": 1},
251
+ "uz": {"train": 32, "validation": 1},
252
+ "vi": {"train": 1024, "validation": 4},
253
+ "xh": {"train": 2, "validation": 1},
254
+ "yi": {"train": 16, "validation": 1},
255
+ "yo": {"train": 2, "validation": 1},
256
+ "zh": {"train": 1024, "validation": 2},
257
+ "zh-Latn": {"train": 8, "validation": 1},
258
+ "zu": {"train": 8, "validation": 1},
259
+ }
260
+
261
+
262
+ class Mc4SamplingConfig(datasets.BuilderConfig):
263
+ """BuilderConfig for mC4 Sampling."""
264
+
265
+ def __init__(self, *args, languages, **kwargs):
266
+ """BuilderConfig for mC4 Sampling.
267
+ Args:
268
+ languages (:obj:`List[str]`): list of languages to load
269
+ **kwargs: keyword arguments forwarded to super.
270
+ """
271
+ super().__init__(
272
+ *args,
273
+ name="+".join(languages),
274
+ **kwargs,
275
+ )
276
+ self.languages = languages
277
+
278
+
279
+ class Mc4Sampling(datasets.GeneratorBasedBuilder):
280
+ """mC4 Sampling, a colossal, cleaned version of Common Crawl's web crawl corpus."""
281
+
282
+ BUILDER_CONFIGS = [Mc4SamplingConfig(languages=[lang]) for lang in _LANGUAGES]
283
+ BUILDER_CONFIG_CLASS = Mc4SamplingConfig
284
+
285
+ def __init__(self, *args, writer_batch_size=None, **kwargs):
286
+ self.data_files = kwargs.pop("data_files", {})
287
+ self.sampling_method = kwargs.pop("sampling_method", None)
288
+ self.perplexity_model = kwargs.pop("perplexity_model", None)
289
+ self.sampling_factor = kwargs.pop("sampling_factor", None)
290
+ self.boundaries = kwargs.pop("boundaries", None)
291
+ self.seed = kwargs.pop("seed", None)
292
+ self.kwargs = kwargs
293
+ if self.sampling_method:
294
+ if self.seed is not None:
295
+ self.rng = default_rng(self.seed)
296
+ else:
297
+ self.rng = default_rng()
298
+ if self.sampling_method == "random":
299
+ self.should_keep_doc = self._should_keep_doc_random
300
+ else:
301
+ # Loading 5-gram model
302
+ # http://dl.fbaipublicfiles.com/cc_net/lm/es.arpa.bin
303
+ logger.info("loading model = %s", self.perplexity_model)
304
+ self.pp_model = kenlm.Model(self.perplexity_model)
305
+ if self.sampling_method == "gaussian":
306
+ self.should_keep_doc = self._should_keep_doc_gaussian
307
+ else:
308
+ self.should_keep_doc = self._should_keep_doc_step
309
+ super().__init__(*args, writer_batch_size=writer_batch_size, **kwargs)
310
+
311
+ def get_perplexity(self, doc):
312
+ doc_log_score, doc_length = 0, 0
313
+ for line in doc.split("\n"):
314
+ log_score = self.pp_model.score(line)
315
+ length = len(line.split()) + 1
316
+ doc_log_score += log_score
317
+ doc_length += length
318
+ return 10.0 ** (-doc_log_score / doc_length)
319
+
320
+ def _should_keep_doc_step(self, doc, factor=1.5e5, boundaries=None, **kwargs):
321
+ perplexity = self.get_perplexity(doc)
322
+ if boundaries is None:
323
+ boundaries = [536394.99320948, 662247.50212365, 919250.87225178]
324
+ if perplexity <= boundaries[0]:
325
+ quartile_range = boundaries[0]
326
+ elif boundaries[0] < perplexity < boundaries[1]:
327
+ quartile_range = boundaries[1] - boundaries[0]
328
+ elif boundaries[1] < perplexity < boundaries[2]:
329
+ quartile_range = boundaries[2] - boundaries[1]
330
+ elif perplexity >= boundaries[2]:
331
+ quartile_range = 10 * boundaries[2]
332
+ probability = factor / quartile_range
333
+ return self.rng.uniform() < probability
334
+
335
+ def _should_keep_doc_gaussian(self, doc, factor=0.78, boundaries=None, **kwargs):
336
+ width = kwargs.get("width", 9 / 2) # width (spread) of the exponential curve
337
+ perplexity = self.get_perplexity(doc)
338
+ if boundaries is not None:
339
+ m = boundaries[1]
340
+ else:
341
+ m = 662247.50212365
342
+ exponential = np.exp((-1 / width) * ((perplexity - m) / m) ** 2)
343
+ weighted_perplexity = factor * exponential
344
+ return self.rng.uniform() < weighted_perplexity
345
+
346
+ def _should_keep_doc_random(self, doc, factor=None, boundaries=None, **kwargs):
347
+ if factor is None:
348
+ factor = 0.5
349
+ return self.rng.uniform() <= factor
350
+
351
+ def _info(self):
352
+ return datasets.DatasetInfo(
353
+ description=_DESCRIPTION,
354
+ features=datasets.Features(
355
+ {
356
+ "text": datasets.Value("string"),
357
+ "timestamp": datasets.Value("string"),
358
+ "url": datasets.Value("string"),
359
+ }
360
+ ),
361
+ supervised_keys=None,
362
+ homepage=_URL,
363
+ citation=_CITATION,
364
+ )
365
+
366
+ def _split_generators(self, dl_manager):
367
+ data_urls = {}
368
+ for split in ["train", "validation"]:
369
+ data_urls[split] = [
370
+ _DATA_URL.format(
371
+ language=self.config.name,
372
+ split_suffix="-validation" if split == "validation" else "",
373
+ index=index,
374
+ n_shards=_N_SHARDS_PER_SPLIT[lang][split],
375
+ )
376
+ for lang in self.config.languages
377
+ for index in range(_N_SHARDS_PER_SPLIT[lang][split])
378
+ ]
379
+ if self.data_files and "train" in self.data_files:
380
+ train_downloaded_files = self.data_files["train"]
381
+ if not isinstance(train_downloaded_files, (tuple, list)):
382
+ train_downloaded_files = [train_downloaded_files]
383
+ else:
384
+ train_downloaded_files = dl_manager.download(data_urls["train"])
385
+ if self.data_files and "validation" in self.data_files:
386
+ validation_downloaded_files = self.data_files["validation"]
387
+ if not isinstance(validation_downloaded_files, (tuple, list)):
388
+ validation_downloaded_files = [validation_downloaded_files]
389
+ else:
390
+ validation_downloaded_files = dl_manager.download(data_urls["validation"])
391
+ return [
392
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": train_downloaded_files}),
393
+ datasets.SplitGenerator(
394
+ name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": validation_downloaded_files}
395
+ ),
396
+ ]
397
+
398
+ def _generate_examples(self, filepaths):
399
+ """This function returns the examples in the raw (text) form by iterating on all the files."""
400
+ id_ = 0
401
+ for filepath in filepaths:
402
+ logger.info("generating examples from = %s", filepath)
403
+ if filepath.endswith("jsonl") or filepath.endswith("json"):
404
+ with open(filepath, "r", encoding="utf-8") as f:
405
+ for line in f:
406
+ if line:
407
+ example = json.loads(line)
408
+ yield id_, example
409
+ id_ += 1
410
+ else:
411
+ with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
412
+ if self.sampling_method:
413
+ logger.info("sampling method = %s", self.sampling_method)
414
+ for line in f:
415
+ if line:
416
+ example = json.loads(line)
417
+ if self.should_keep_doc(
418
+ example["text"],
419
+ factor=self.sampling_factor,
420
+ boundaries=self.boundaries
421
+ **self.kwargs):
422
+ yield id_, example
423
+ id_ += 1
424
+ else:
425
+ for line in f:
426
+ if line:
427
+ example = json.loads(line)
428
+ yield id_, example
429
+ id_ += 1