mathqa.py 906 Bytes
Newer Older
1
import re
2
3
4
from lm_eval.base import MultipleChoiceTask
from . common import HFTask

5
6

class MathQA(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
7
    VERSION = 0
8
9
10
11
12
13
14
15
16
17
18
19
    DATASET_PATH = "math_qa"
    DATASET_NAME = None

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

20
    def _convert_standard(self, doc):
21

22
        answer_idx = ['a', 'b', 'c', 'd', 'e'].index(doc['correct'])
Anthony DiPofi's avatar
Anthony DiPofi committed
23
        choices = [c[4:].rstrip(" ,") for c in re.findall(r"[abcd] \) .*?, |e \) .*?$", doc['options'])]
24

25
        out_doc = {
26
27
28
            "query": "Question: " + doc['Problem'] +"\nAnswer:",
            "choices": choices,
            "gold": answer_idx,
29
30
        }
        return out_doc
31

32
33
34
    def fewshot_description(self):
        # TODO: figure out description
        return ""
35

36
37
    def doc_to_text(self, doc):
        return doc["query"]