arithmetic / arithmetic.py
bfattori's picture
change _BASE_URL_ for transfer to eleuther org
cf5ec45
# 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.
"""GPT-3 Arithmetic Test Dataset."""
import json
import datasets
_CITATION = """\
@inproceedings{NEURIPS2020_1457c0d6,
author = {Brown, Tom and Mann, Benjamin and Ryder, Nick and Subbiah, Melanie and Kaplan, Jared D and Dhariwal, Prafulla and Neelakantan, Arvind and Shyam, Pranav and Sastry, Girish and Askell, Amanda and Agarwal, Sandhini and Herbert-Voss, Ariel and Krueger, Gretchen and Henighan, Tom and Child, Rewon and Ramesh, Aditya and Ziegler, Daniel and Wu, Jeffrey and Winter, Clemens and Hesse, Chris and Chen, Mark and Sigler, Eric and Litwin, Mateusz and Gray, Scott and Chess, Benjamin and Clark, Jack and Berner, Christopher and McCandlish, Sam and Radford, Alec and Sutskever, Ilya and Amodei, Dario},
booktitle = {Advances in Neural Information Processing Systems},
editor = {H. Larochelle and M. Ranzato and R. Hadsell and M. F. Balcan and H. Lin},
pages = {1877--1901},
publisher = {Curran Associates, Inc.},
title = {Language Models are Few-Shot Learners},
url = {https://proceedings.neurips.cc/paper/2020/file/1457c0d6bfcb4967418bfb8ac142f64a-Paper.pdf},
volume = {33},
year = {2020}
}
"""
_DESCRIPTION = """\
A small battery of 10 tests that involve asking language models a simple arithmetic
problem in natural language.
"""
_HOMEPAGE = "https://github.com/openai/gpt-3/tree/master/data"
# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""
_BASE_URL = "https://huggingface.co/datasets/EleutherAI/arithmetic/resolve/main/data"
_URLS = {
"arithmetic_2da": f"{_BASE_URL}/two_digit_addition.jsonl",
"arithmetic_2ds": f"{_BASE_URL}/two_digit_subtraction.jsonl",
"arithmetic_3da": f"{_BASE_URL}/three_digit_addition.jsonl",
"arithmetic_3ds": f"{_BASE_URL}/three_digit_subtraction.jsonl",
"arithmetic_4da": f"{_BASE_URL}/four_digit_addition.jsonl",
"arithmetic_4ds": f"{_BASE_URL}/four_digit_subtraction.jsonl",
"arithmetic_5da": f"{_BASE_URL}/five_digit_addition.jsonl",
"arithmetic_5ds": f"{_BASE_URL}/five_digit_subtraction.jsonl",
"arithmetic_2dm": f"{_BASE_URL}/two_digit_multiplication.jsonl",
"arithmetic_1dc": f"{_BASE_URL}/single_digit_three_ops.jsonl"
}
class Arithmetic(datasets.GeneratorBasedBuilder):
"""A small battery of 10 tests involving simple arithmetic problems."""
VERSION = datasets.Version("0.0.1")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name = "arithmetic_2da",
version = VERSION,
description = "2-digit addition"
),
datasets.BuilderConfig(
name = "arithmetic_2ds",
version = VERSION,
description = "2-digit subtraction"
),
datasets.BuilderConfig(
name = "arithmetic_3da",
version = VERSION,
description = "3-digit addition"
),
datasets.BuilderConfig(
name = "arithmetic_3ds",
version = VERSION,
description = "3-digit subtraction"
),
datasets.BuilderConfig(
name = "arithmetic_4da",
version = VERSION,
description = "4-digit addition"
),
datasets.BuilderConfig(
name = "arithmetic_4ds",
version = VERSION,
description = "4-digit subtraction"
),
datasets.BuilderConfig(
name = "arithmetic_5da",
version = VERSION,
description = "5-digit addition"
),
datasets.BuilderConfig(
name = "arithmetic_5ds",
version = VERSION,
description = "5-digit subtraction"
),
datasets.BuilderConfig(
name = "arithmetic_2dm",
version = VERSION,
description = "2-digit multiplication"
),
datasets.BuilderConfig(
name = "arithmetic_1dc",
version = VERSION,
description = "Single digit 3 operations"
)
]
def _info(self):
features = datasets.Features(
{
"context": datasets.Value("string"),
"completion": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=f"{_DESCRIPTION}\n{self.config.description}",
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URLS[self.config.name]
data_dir = dl_manager.download_and_extract(urls)
return [
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_dir,
"split": datasets.Split.VALIDATION,
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, split):
with open(filepath, encoding="utf-8") as f:
for key, row in enumerate(f):
data = json.loads(row)
context = (
data["context"]
.strip()
.replace("\n\n", "\n")
.replace("Q:", "Question:")
.replace("A:", "Answer:")
)
completion = data["completion"]
yield key, {"context": context, "completion": completion}