lintang commited on
Commit
f838d5a
1 Parent(s): d1c418c

a sythetic generate dataset for testing numerical reasoning

Browse files
Files changed (2) hide show
  1. README.md +1 -0
  2. numerical_reasoning.py +157 -0
README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ # Numerical Reasoning
numerical_reasoning.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+
29
+ """
30
+
31
+ # TODO: Add description of the dataset here
32
+ # You can copy an official description
33
+ _DESCRIPTION = """\
34
+ Generated dataset for testing numerical reasoning
35
+ """
36
+
37
+ # TODO: Add a link to an official homepage for the dataset here
38
+ _HOMEPAGE = ""
39
+
40
+ # TODO: Add the licence for the dataset here if you can find it
41
+ _LICENSE = ""
42
+
43
+ # TODO: Add link to the official dataset URLs here
44
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
45
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
46
+ _URLS = {
47
+ "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
48
+ "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
49
+ }
50
+
51
+
52
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
53
+ class NewDataset(datasets.GeneratorBasedBuilder):
54
+ """TODO: Short description of my dataset."""
55
+
56
+ VERSION = datasets.Version("0.1.0")
57
+
58
+ BUILDER_CONFIGS = [
59
+ datasets.BuilderConfig(name="arithmetic_multiplication", version=VERSION, description="x1 x x2 = y"),
60
+ datasets.BuilderConfig(name="arithmetic_addition", version=VERSION, description="x1 + x2 = y"),
61
+ datasets.BuilderConfig(name="op_infer_mult", version=VERSION, description="x1 # x2 = y, must infer that # is multiplication"),
62
+ datasets.BuilderConfig(name="op_infer_add", version=VERSION, description="x1 # x2 = y, must infer that # is addition"),
63
+ datasets.BuilderConfig(name="time_unit_min_sec", version=VERSION, description="x minutes equals y seconds"),
64
+ datasets.BuilderConfig(name="time_unit_hour_min", version=VERSION, description="x hours equals y minutes"),
65
+ datasets.BuilderConfig(name="time_unit_day_hour", version=VERSION, description="x days equals y hours"),
66
+ datasets.BuilderConfig(name="time_unit_week_day", version=VERSION, description="x minutes equals y seconds"),
67
+ datasets.BuilderConfig(name="time_unit_month_week", version=VERSION, description="x months equals y weeks"),
68
+ datasets.BuilderConfig(name="time_unit_year_month", version=VERSION, description="x years equals y months"),
69
+ datasets.BuilderConfig(name="time_unit_decade_year", version=VERSION, description="x decades equals y years"),
70
+ ]
71
+
72
+ DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
73
+
74
+ def _info(self):
75
+ if ("arithmetic" in self.config.name) or ("op_infer" in self.config.name): # This is the name of the configuration selected in BUILDER_CONFIGS above
76
+ features = datasets.Features(
77
+ {
78
+ "x1": datasets.Value("int32"),
79
+ "x2": datasets.Value("int32"),
80
+ "y": datasets.Value("int32")
81
+ }
82
+ )
83
+ else:
84
+ features = datasets.Features(
85
+ {
86
+ "x1": datasets.Value("int32"),
87
+ "time_unit": datasets.Value("string"),
88
+ "y": datasets.Value("int32")
89
+ }
90
+ )
91
+ return datasets.DatasetInfo(
92
+ description=_DESCRIPTION,
93
+ features=features, # Here we define them above because they are different between the two configurations
94
+ homepage=_HOMEPAGE,
95
+ license=_LICENSE,
96
+ citation=_CITATION,
97
+ )
98
+
99
+ def _split_generators(self, dl_manager):
100
+ return [
101
+ datasets.SplitGenerator(
102
+ name=datasets.Split.TEST,
103
+ # These kwargs will be passed to _generate_examples
104
+ gen_kwargs={
105
+ "split": "test"
106
+ },
107
+ ),
108
+ ]
109
+
110
+ def _generate_examples(self, split):
111
+
112
+ if ("arithmetic" in self.config.name) or ("op_infer" in self.config.name):
113
+ key = 0
114
+ for x1 in range(0,100):
115
+ for x2 in range(1,51):
116
+ key += 1
117
+ # Yields examples as (key, example) tuples
118
+ yield key, {
119
+ "x1": x1,
120
+ "x2": x2,
121
+ "y": x1*x2,
122
+ }
123
+ else:
124
+ if "min_sec" in self.config.name:
125
+ time_unit = "minutes"
126
+ multiplier = 60
127
+
128
+ elif "hour_min" in self.config.name:
129
+ time_unit = "hours"
130
+ multiplier = 60
131
+
132
+ elif "day_hour" in self.config.name:
133
+ time_unit = "days"
134
+ multiplier = 24
135
+
136
+ elif "week_day" in self.config.name:
137
+ time_unit = "weeks"
138
+ multiplier = 7
139
+
140
+ elif "month_week" in self.config.name:
141
+ time_unit = "months"
142
+ multiplier = 30
143
+
144
+ elif "year_month" in self.config.name:
145
+ time_unit = "years"
146
+ multiplier = 12
147
+
148
+ elif "decade_year" in self.config.name:
149
+ time_unit = "decades"
150
+ multiplier = 10
151
+
152
+ for key, x1 in enumerate(range(0, 100)):
153
+ yield key, {
154
+ "x1": x1,
155
+ "time_unit": time_unit,
156
+ "y": multiplier*x1,
157
+ }