"hip/local_exchange.hip" did not exist on "295a615aacce7e54a37e7935274ba15e901c78e4"
arithmetic.py 3.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
"""
Language Models are Few-Shot Learners
https://arxiv.org/pdf/2005.14165.pdf

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
"""
&'s avatar
& committed
10
11
from lm_eval.base import Task, rf
from lm_eval.metrics import mean
Jonathan Tow's avatar
Jonathan Tow committed
12

13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
_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}
}
"""


29
class Arithmetic(Task):
Leo Gao's avatar
Leo Gao committed
30
    VERSION = 0
bzantium's avatar
bzantium committed
31
    DATASET_PATH = "EleutherAI/arithmetic"
32

33
    def has_training_docs(self):
Leo Gao's avatar
Leo Gao committed
34
        return False
35
36
37
38
39
40
41
42

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return False

    def training_docs(self):
Leo Gao's avatar
Leo Gao committed
43
        return NotImplemented
44
45

    def validation_docs(self):
Jonathan Tow's avatar
Jonathan Tow committed
46
        return self.dataset["validation"]
47
48
49

    def test_docs(self):
        return NotImplemented
bzantium's avatar
bzantium committed
50

51
    def doc_to_text(self, doc):
Jonathan Tow's avatar
Jonathan Tow committed
52
        return doc["context"]
53

bzantium's avatar
bzantium committed
54
55
56
57
58
59
    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["context"]

60
    def doc_to_target(self, doc):
Jonathan Tow's avatar
Jonathan Tow committed
61
        return doc["completion"]
62
63

    def construct_requests(self, doc, ctx):
Jonathan Tow's avatar
Jonathan Tow committed
64
        ll, is_prediction = rf.loglikelihood(ctx, doc["completion"])
65
66
67
        return is_prediction

    def process_results(self, doc, results):
bzantium's avatar
bzantium committed
68
69
        (is_prediction,) = results
        return {"acc": is_prediction}
70
71
72
73
74
75
76

    def aggregation(self):
        return {
            "acc": mean,
        }

    def higher_is_better(self):
bzantium's avatar
bzantium committed
77
        return {"acc": True}
78
79
80


class Arithmetic2DPlus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
81
82
    DATASET_NAME = "arithmetic_2da"

83
84

class Arithmetic2DMinus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
85
86
    DATASET_NAME = "arithmetic_2ds"

87
88

class Arithmetic3DPlus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
89
90
    DATASET_NAME = "arithmetic_3da"

91
92

class Arithmetic3DMinus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
93
94
    DATASET_NAME = "arithmetic_3ds"

95
96

class Arithmetic4DPlus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
97
98
    DATASET_NAME = "arithmetic_4da"

99
100

class Arithmetic4DMinus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
101
102
    DATASET_NAME = "arithmetic_4ds"

103
104

class Arithmetic5DPlus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
105
106
    DATASET_NAME = "arithmetic_5da"

107
108

class Arithmetic5DMinus(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
109
110
    DATASET_NAME = "arithmetic_5ds"

111
112

class Arithmetic2DMultiplication(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
113
114
    DATASET_NAME = "arithmetic_2dm"

115
116

class Arithmetic1DComposite(Arithmetic):
Jonathan Tow's avatar
Jonathan Tow committed
117
    DATASET_NAME = "arithmetic_1dc"