Datasets:

Tasks:
Other
Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
Muennighoff commited on
Commit
1cac472
1 Parent(s): 5c2ee1e

Create xP3mt.py

Browse files
Files changed (1) hide show
  1. xP3mt.py +75 -0
xP3mt.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """xP3 (Crosslingual Public Pool of Prompts)"""
2
+
3
+ import json
4
+
5
+ import datasets
6
+
7
+
8
+ logger = datasets.logging.get_logger(__name__)
9
+
10
+
11
+ _CITATION = """@misc{muennighoff2022crosslingual,
12
+ title={Crosslingual Generalization through Multitask Finetuning},
13
+ author={Niklas Muennighoff and Thomas Wang and Lintang Sutawika and Adam Roberts and Stella Biderman and Teven Le Scao and M Saiful Bari and Sheng Shen and Zheng-Xin Yong and Hailey Schoelkopf and Xiangru Tang and Dragomir Radev and Alham Fikri Aji and Khalid Almubarak and Samuel Albanie and Zaid Alyafeai and Albert Webson and Edward Raff and Colin Raffel},
14
+ year={2022},
15
+ eprint={2211.01786},
16
+ archivePrefix={arXiv},
17
+ primaryClass={cs.CL}
18
+ }"""
19
+
20
+ _DESCRIPTION = """\
21
+ xP3 (Crosslingual Public Pool of Prompts) is a collection of prompts & datasets across 46 of languages & 16 NLP tasks. It is used for the training of BLOOMZ and mT0, multilingual language models capable of following human instructions in dozens of languages zero-shot.
22
+ """
23
+
24
+ _LANG = ['ak', 'ar', 'as', 'bm', 'bn', 'ca', 'code', 'en', 'es', 'eu', 'fon', 'fr', 'gu', 'hi', 'id', 'ig', 'ki', 'kn', 'lg', 'ln', 'ml', 'mr', 'ne', 'nso', 'ny', 'or', 'pa', 'pt', 'rn', 'rw', 'sn', 'st', 'sw', 'ta', 'te', 'tn', 'ts', 'tum', 'tw', 'ur', 'vi', 'wo', 'xh', 'yo', 'zh', 'zu']
25
+
26
+ _LICENSE = "Apache License 2.0"
27
+ _URL = "{lang}/merged_{lang}.jsonl"
28
+ _VERSION = datasets.Version("1.0.0", "")
29
+
30
+
31
+ class xP3mt(datasets.GeneratorBasedBuilder):
32
+ BUILDER_CONFIGS = [
33
+ datasets.BuilderConfig(
34
+ name=lang,
35
+ description=f"xP3mt {lang} subset",
36
+ version=_VERSION,
37
+ )
38
+ for lang in _LANG
39
+ ]
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ description=_DESCRIPTION,
44
+ features=datasets.Features(
45
+ {
46
+ "inputs": datasets.Value("string"),
47
+ "targets": datasets.Value("string")
48
+ }
49
+ ),
50
+ supervised_keys=None,
51
+ citation=_CITATION,
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+
56
+ downloaded_files = dl_manager.download_and_extract(_URL.format(lang=self.config.name))
57
+ return [
58
+ datasets.SplitGenerator(
59
+ name=datasets.Split.TRAIN,
60
+ gen_kwargs={'filepath': downloaded_files}
61
+ )
62
+ ]
63
+
64
+ def _generate_examples(self, filepath):
65
+ """This function returns the examples in the raw (text) form."""
66
+ logger.info("Generating examples from = %s", filepath)
67
+
68
+ with open(filepath, encoding="utf-8") as f:
69
+ for id_, row in enumerate(f):
70
+ data = json.loads(row)
71
+
72
+ yield id_, {
73
+ "inputs": data["inputs"],
74
+ "targets": data["targets"],
75
+ }