mathqa.py 890 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):
7
8
9
10
11
12
13
14
15
16
17
18
    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

19
    def _convert_standard(self, doc):
20

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

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

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

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