Datasets:

Modalities:
Text
License:
yslim0726 commited on
Commit
06e7f81
β€’
1 Parent(s): d4df7c2

Upload ai2_arc.py

Browse files
Files changed (1) hide show
  1. ai2_arc.py +127 -0
ai2_arc.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import datasets
4
+ from datasets import BuilderConfig, Features, ClassLabel, Value, Sequence
5
+
6
+
7
+ _DESCRIPTION = """
8
+ # ν•œκ΅­μ–΄ μ§€μ‹œν•™μŠ΅ 데이터셋
9
+ - ai2_arc 데이터셋을 ν•œκ΅­μ–΄λ‘œ λ³€μ—­ν•œ 데이터셋
10
+ """
11
+
12
+ _CITATION = """
13
+ @inproceedings{KITD,
14
+ title={μ–Έμ–΄ λ²ˆμ—­ λͺ¨λΈμ„ ν†΅ν•œ ν•œκ΅­μ–΄ μ§€μ‹œ ν•™μŠ΅ 데이터 μ„ΈνŠΈ ꡬ좕},
15
+ author={μž„μ˜μ„œ, μΆ”ν˜„μ°½, κΉ€μ‚°, μž₯μ§„μ˜ˆ, μ •λ―Όμ˜, μ‹ μ‚¬μž„},
16
+ booktitle={제 35회 ν•œκΈ€ 및 ν•œκ΅­μ–΄ μ •λ³΄μ²˜λ¦¬ ν•™μˆ λŒ€νšŒ},
17
+ pages={591--595},
18
+ month=oct,
19
+ year={2023}
20
+ }
21
+ """
22
+
23
+ # BASE CODE
24
+ def _list(data_list):
25
+ result = list()
26
+ for data in data_list:
27
+ result.append(data)
28
+ return result
29
+
30
+ # ai2_arc
31
+ _AI2_ARC_FEATURES = Features({
32
+ "data_index_by_user": Value(dtype="int32"),
33
+ "id": Value(dtype="string"),
34
+ "question": Value(dtype="string"),
35
+ "choices": {
36
+ "text": Sequence(Value(dtype="string")),
37
+ "label": Sequence(Value(dtype="string")),
38
+ },
39
+ "answerKey": Value(dtype="string"),
40
+ })
41
+
42
+ def _parsing_ai2_arc(file_path):
43
+ with open(file_path, mode="r") as f:
44
+ dataset = json.load(f)
45
+ for _idx, data in enumerate(dataset):
46
+ _data_index_by_user = data["data_index_by_user"]
47
+ _id = data["id"]
48
+ _question = data["question"]
49
+ _choices = {
50
+ "text": _list(data["choices"]["text"]),
51
+ "label": _list(data["choices"]["label"]),
52
+ }
53
+ _answerKey = data["answerKey"]
54
+
55
+ yield _idx, {
56
+ "data_index_by_user": _data_index_by_user,
57
+ "id": _id,
58
+ "question": _question,
59
+ "choices": _choices,
60
+ "answerKey": _answerKey,
61
+ }
62
+
63
+ class Ai2_arcConfig(BuilderConfig):
64
+ def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
65
+ super(Ai2_arcConfig, self).__init__(
66
+ name = name,
67
+ version=datasets.Version("1.0.0"),
68
+ **kwargs)
69
+ self.feature = feature
70
+ self.reading_fn = reading_fn
71
+ self.parsing_fn = parsing_fn
72
+ self.citation = citation
73
+
74
+ class RACE(datasets.GeneratorBasedBuilder):
75
+ BUILDER_CONFIGS = [
76
+ Ai2_arcConfig(
77
+ name = "ARC-Challenge",
78
+ data_dir = "./ai2_arc",
79
+ feature = _AI2_ARC_FEATURES,
80
+ reading_fn = _parsing_ai2_arc,
81
+ parsing_fn = lambda x:x,
82
+ citation = _CITATION,
83
+ ),
84
+ Ai2_arcConfig(
85
+ name = "ARC-Easy",
86
+ data_dir = "./ai2_arc",
87
+ feature = _AI2_ARC_FEATURES,
88
+ reading_fn = _parsing_ai2_arc,
89
+ parsing_fn = lambda x:x,
90
+ citation = _CITATION,
91
+ ),
92
+ ]
93
+
94
+ def _info(self) -> datasets.DatasetInfo:
95
+ """Returns the dataset metadata."""
96
+ return datasets.DatasetInfo(
97
+ description=_DESCRIPTION,
98
+ features=_AI2_ARC_FEATURES,
99
+ citation=_CITATION,
100
+ )
101
+
102
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
103
+ """Returns SplitGenerators"""
104
+ path_kv = {
105
+ datasets.Split.TRAIN:[
106
+ os.path.join(dl_manager.manual_dir, f"{self.config.name}/train.json")
107
+ ],
108
+ datasets.Split.VALIDATION:[
109
+ os.path.join(dl_manager.manual_dir, f"{self.config.name}/validation.json")
110
+ ],
111
+ datasets.Split.TEST:[
112
+ os.path.join(dl_manager.manual_dir, f"{self.config.name}/test.json")
113
+ ],
114
+ }
115
+ return [
116
+ datasets.SplitGenerator(name=k, gen_kwargs={"path_list": v})
117
+ for k, v in path_kv.items()
118
+ ]
119
+
120
+ def _generate_examples(self, path_list):
121
+ """Yields examples."""
122
+ for path in path_list:
123
+ try:
124
+ for example in iter(self.config.reading_fn(path)):
125
+ yield self.config.parsing_fn(example)
126
+ except Exception as e:
127
+ print(e)