mathqa.py 1.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
"""
MathQA: Towards Interpretable Math Word Problem Solving with Operation-Based Formalisms
https://arxiv.org/pdf/1905.13319.pdf

MathQA is a large-scale dataset of 37k English multiple-choice math word problems
covering multiple math domain categories by modeling operation programs corresponding
to word problems in the AQuA dataset (Ling et al., 2017).

Homepage: https://math-qa.github.io/math-QA/
"""
11
import re
12
13
14
from lm_eval.base import MultipleChoiceTask
from . common import HFTask

15

16
17
18
19
20
21
22
23
24
25
26
27
_CITATION = """
@misc{amini2019mathqa,
    title={MathQA: Towards Interpretable Math Word Problem Solving with Operation-Based Formalisms}, 
    author={Aida Amini and Saadia Gabriel and Peter Lin and Rik Koncel-Kedziorski and Yejin Choi and Hannaneh Hajishirzi},
    year={2019},
    eprint={1905.13319},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}
"""


28
class MathQA(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
29
    VERSION = 0
30
31
32
33
34
35
36
37
38
39
40
41
    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

42
    def _convert_standard(self, doc):
43

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

47
        out_doc = {
48
49
50
            "query": "Question: " + doc['Problem'] +"\nAnswer:",
            "choices": choices,
            "gold": answer_idx,
51
52
        }
        return out_doc
53

54
55
    def doc_to_text(self, doc):
        return doc["query"]