File size: 6,213 Bytes
f838d5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98a19ff
f838d5a
 
 
 
 
98a19ff
 
 
 
 
 
 
 
 
f838d5a
 
0308c2e
f838d5a
 
0308c2e
f838d5a
 
 
 
06ad559
f838d5a
 
 
 
 
98a19ff
 
06ad559
98a19ff
f838d5a
 
 
 
0308c2e
f838d5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98a19ff
f838d5a
 
 
 
 
 
 
 
 
98a19ff
 
 
 
 
 
 
 
 
 
 
f838d5a
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
 
98a19ff
 
f838d5a
 
3b0cca7
f838d5a
3b0cca7
98a19ff
3b0cca7
98a19ff
f838d5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: Address all TODOs and remove all explanatory comments
"""TODO: Add a description here."""

import csv
import json
import os

import datasets


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\

"""

# TODO: Add description of the dataset here
# You can copy an official description
_DESCRIPTION = """\
    Generated dataset for testing numerical reasoning
"""

# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = ""

# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URLS = {
    "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
    "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
}


# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
class NumericalReasoning(datasets.GeneratorBasedBuilder):
    """TODO: Short description of my dataset."""

    VERSION = datasets.Version("0.1.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="multiplication", version=VERSION, description="x1 x x2 = y"),
        datasets.BuilderConfig(name="addition", version=VERSION, description="x1 + x2 = y"),
        datasets.BuilderConfig(name="convert_min_sec", version=VERSION, description="x minutes equals y seconds"),
        datasets.BuilderConfig(name="convert_hour_min", version=VERSION, description="x hours equals y minutes"),
        datasets.BuilderConfig(name="convert_day_hour", version=VERSION, description="x days equals y hours"),
        datasets.BuilderConfig(name="convert_week_day", version=VERSION, description="x minutes equals y seconds"),
        datasets.BuilderConfig(name="convert_month_week", version=VERSION, description="x months equals y weeks"),
        datasets.BuilderConfig(name="convert_year_month", version=VERSION, description="x years equals y months"),
        datasets.BuilderConfig(name="convert_decade_year", version=VERSION, description="x decades equals y years"),
    ]

    DEFAULT_CONFIG_NAME = "multiplication"

    def _info(self):
        if (self.config.name == "multiplication") or (self.config.name == "addition"):
            features = datasets.Features(
                {
                    "x1": datasets.Value("int32"),
                    "x2": datasets.Value("int32"),
                    "y": datasets.Value("int32"),
                }
            )
        else:
            features = datasets.Features(
                {
                    "x": datasets.Value("int32"),
                    "x_time_unit": datasets.Value("string"),
                    "y": datasets.Value("int32"),
                    "y_time_unit": datasets.Value("string"),
                }
            )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "split": "test"
                },
            ),
        ]

    def _generate_examples(self, split):

        if self.config.name == "multiplication":
            key = 0
            for x1 in range(0,100):
                for x2 in range(1,51):
                    key += 1
                    yield key, {
                        "x1": x1,
                        "x2": x2,
                        "y": x1*x2,
                    }

        elif self.config.name == "addition":
            key = 0
            for x1 in range(0,100):
                for x2 in range(1,51):
                    key += 1
                    yield key, {
                        "x1": x1,
                        "x2": x2,
                        "y": x1+x2,
                    }
        else:
            if "min_sec" in self.config.name:
                x_time_unit = "minutes"
                y_time_unit = "seconds"
                multiplier = 60

            elif "hour_min" in self.config.name:
                x_time_unit = "hours"
                y_time_unit = "minutes"
                multiplier = 60

            elif "day_hour" in self.config.name:
                x_time_unit = "days"
                y_time_unit = "hours"
                multiplier = 24

            elif "week_day" in self.config.name:
                x_time_unit = "weeks"
                y_time_unit = "days"
                multiplier = 7

            elif "month_week" in self.config.name:
                x_time_unit = "months"
                y_time_unit = "weeks"
                multiplier = 30

            elif "year_month" in self.config.name:
                x_time_unit = "years"
                y_time_unit = "months"
                multiplier = 12

            elif "decade_year" in self.config.name:
                x_time_unit = "decades"
                y_time_unit = "years"
                multiplier = 10

            for key, x in enumerate(range(0, 100)):
                yield key, {
                    "x": x,
                    "x_time_unit": x_time_unit,
                    "y": multiplier*x,
                    "y_time_unit": y_time_unit,
                }