numerical_reasoning_arithmetic / numerical_reasoning.py
lintang's picture
changed subset names
98a19ff
raw
history blame
6.65 kB
# 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" # It's not mandatory to have a default configuration. Just use one if it make sense.
def _info(self):
if ("multiplication" in self.config.name) or ("addition" in self.config.name): # This is the name of the configuration selected in BUILDER_CONFIGS above
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, # Here we define them above because they are different between the two configurations
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
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
# Yields examples as (key, example) tuples
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
# Yields examples as (key, example) tuples
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,
}