Datasets:

ArXiv:
License:
holylovenia commited on
Commit
6673ea5
·
verified ·
1 Parent(s): a12ec3a

Upload xstorycloze.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. xstorycloze.py +176 -0
xstorycloze.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from seacrowd.utils.configs import SEACrowdConfig
8
+ from seacrowd.utils.constants import SCHEMA_TO_FEATURES, Licenses, Tasks
9
+
10
+ _CITATION = """\
11
+ @inproceedings{lin2022fewshot,
12
+ author = {Xi Victoria Lin and
13
+ Todor Mihaylov and
14
+ Mikel Artetxe and
15
+ Tianlu Wang and
16
+ Shuohui Chen and
17
+ Daniel Simig and
18
+ Myle Ott and
19
+ Naman Goyal and
20
+ Shruti Bhosale and
21
+ Jingfei Du and
22
+ Ramakanth Pasunuru and
23
+ Sam Shleifer and
24
+ Punit Singh Koura and
25
+ Vishrav Chaudhary and
26
+ Brian O'Horo and
27
+ Jeff Wang and
28
+ Luke Zettlemoyer and
29
+ Zornitsa Kozareva and
30
+ Mona T. Diab and
31
+ Veselin Stoyanov and
32
+ Xian Li},
33
+ editor = {Yoav Goldberg and
34
+ Zornitsa Kozareva and
35
+ Yue Zhang},
36
+ title = {Few-shot Learning with Multilingual Generative Language Models},
37
+ booktitle = {Proceedings of the 2022 Conference on Empirical Methods in Natural
38
+ Language Processing, {EMNLP} 2022, Abu Dhabi, United Arab Emirates,
39
+ December 7-11, 2022},
40
+ pages = {9019--9052},
41
+ publisher = {Association for Computational Linguistics},
42
+ year = {2022},
43
+ url = {https://doi.org/10.18653/v1/2022.emnlp-main.616},
44
+ doi = {10.18653/V1/2022.EMNLP-MAIN.616},
45
+ }
46
+ """
47
+
48
+ _DATASETNAME = "xstorycloze"
49
+ _DESCRIPTION = """\
50
+ XStoryCloze consists of the professionally translated version of the English StoryCloze
51
+ dataset (Spring 2016 version) to 10 non-English languages. This dataset is released by
52
+ Meta AI.
53
+ """
54
+ _HOMEPAGE = "https://huggingface.co/datasets/juletxara/xstory_cloze"
55
+ _LANGUAGES = ["ind", "mya"]
56
+ _LICENSE = Licenses.CC_BY_SA_4_0.value
57
+
58
+ _LOCAL = False
59
+ _BASE_URL = "https://huggingface.co/datasets/juletxara/xstory_cloze/resolve/main/spring2016.val.{lang}.tsv.split_20_80_{split}.tsv"
60
+ _SUPPORTED_TASKS = [Tasks.COMMONSENSE_REASONING]
61
+ _SOURCE_VERSION = "1.0.0"
62
+ _SEACROWD_VERSION = "2024.06.20"
63
+
64
+
65
+ class XStoryClozeDataset(datasets.GeneratorBasedBuilder):
66
+ """XStoryCloze subset for Indonesian and Burmese language."""
67
+
68
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
69
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
70
+
71
+ SEACROWD_SUBSET = ["id", "my"]
72
+
73
+ BUILDER_CONFIGS = [
74
+ SEACrowdConfig(
75
+ name=f"{_DATASETNAME}_{subset}_source",
76
+ version=datasets.Version(_SOURCE_VERSION),
77
+ description=f"{_DATASETNAME} {subset} source schema",
78
+ schema="source",
79
+ subset_id=f"{_DATASETNAME}_{subset}",
80
+ )
81
+ for subset in SEACROWD_SUBSET
82
+ ] + [
83
+ SEACrowdConfig(
84
+ name=f"{_DATASETNAME}_{subset}_seacrowd_qa",
85
+ version=datasets.Version(_SEACROWD_VERSION),
86
+ description=f"{_DATASETNAME} {subset} SEACrowd schema",
87
+ schema="seacrowd_qa",
88
+ subset_id=f"{_DATASETNAME}_{subset}",
89
+ )
90
+ for subset in SEACROWD_SUBSET
91
+ ]
92
+
93
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_{SEACROWD_SUBSET[0]}_source"
94
+
95
+ def _info(self) -> datasets.DatasetInfo:
96
+ if self.config.schema == "source":
97
+ features = datasets.Features(
98
+ {
99
+ "story_id": datasets.Value("string"),
100
+ "input_sentence_1": datasets.Value("string"),
101
+ "input_sentence_2": datasets.Value("string"),
102
+ "input_sentence_3": datasets.Value("string"),
103
+ "input_sentence_4": datasets.Value("string"),
104
+ "sentence_quiz1": datasets.Value("string"),
105
+ "sentence_quiz2": datasets.Value("string"),
106
+ "answer_right_ending": datasets.Value("int32"),
107
+ }
108
+ )
109
+ elif self.config.schema == "seacrowd_qa":
110
+ features = SCHEMA_TO_FEATURES["QA"]
111
+
112
+ return datasets.DatasetInfo(
113
+ description=_DESCRIPTION,
114
+ features=features,
115
+ homepage=_HOMEPAGE,
116
+ license=_LICENSE,
117
+ citation=_CITATION,
118
+ )
119
+
120
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
121
+ lang = self.config.name.split("_")[1]
122
+ filepaths = dl_manager.download_and_extract(
123
+ {
124
+ "train": _BASE_URL.format(lang=lang, split="train"),
125
+ "test": _BASE_URL.format(lang=lang, split="eval"),
126
+ }
127
+ )
128
+
129
+ return [
130
+ datasets.SplitGenerator(
131
+ name=datasets.Split.TRAIN,
132
+ gen_kwargs={
133
+ "filepath": filepaths["train"],
134
+ "split": "train",
135
+ },
136
+ ),
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TEST,
139
+ gen_kwargs={
140
+ "filepath": filepaths["test"],
141
+ "split": "test",
142
+ },
143
+ ),
144
+ ]
145
+
146
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
147
+ with open(filepath, encoding="utf-8") as f:
148
+ data = csv.reader(f, quotechar='"', delimiter="\t", quoting=csv.QUOTE_ALL, skipinitialspace=True)
149
+ _ = next(data) # skip header
150
+ if self.config.schema == "source":
151
+ for id, row in enumerate(data):
152
+ yield id, {
153
+ "story_id": row[0],
154
+ "input_sentence_1": row[1],
155
+ "input_sentence_2": row[2],
156
+ "input_sentence_3": row[3],
157
+ "input_sentence_4": row[4],
158
+ "sentence_quiz1": row[5],
159
+ "sentence_quiz2": row[6],
160
+ "answer_right_ending": int(row[7]),
161
+ }
162
+ elif self.config.schema == "seacrowd_qa":
163
+ for id, row in enumerate(data):
164
+ question = " ".join(row[1:5])
165
+ choices = [row[5], row[6]]
166
+ yield id, {
167
+ "id": str(id),
168
+ "question_id": row[0],
169
+ "document_id": None,
170
+ "question": question,
171
+ "type": "multiple_choice",
172
+ "choices": choices,
173
+ "context": None,
174
+ "answer": [choices[int(row[7]) - 1]],
175
+ "meta": {},
176
+ }