arc.py 1.22 KB
Newer Older
1
from lm_eval.base import MultipleChoiceTask
2
from . common import HFTask
3
from lm_eval.mctask_experimental import MultipleChoiceDoc
Leo Gao's avatar
Leo Gao committed
4

Jonathan Tow's avatar
Jonathan Tow committed
5

6
class ARCEasy(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
7
    VERSION = 0
Leo Gao's avatar
Leo Gao committed
8
9
    DATASET_PATH = "ai2_arc"
    DATASET_NAME = "ARC-Easy"
Leo Gao's avatar
Leo Gao committed
10
11
12
13
14
15
16
17
18
19

    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
23
24
25
        question = doc["question"]
        keys = ["A", "B", "C", "D", "E"]
        options = doc["choices"]["text"]
        while len(options) < len(keys):
            options.append("")
26
27
28
29
        # NOTE: Some `doc["answerKey"]`s are in numeric string format being one
        # of {'1', '2', '3', '4', '5'}. We map them back to letters.
        num_to_letter = {"1": "A", "2": "B", "3": "C", "4": "D", "5": "E"}
        doc["answerKey"] = num_to_letter.get(doc["answerKey"], doc["answerKey"])
30
31
32
33
34
35
36
        gold = ["A", "B", "C", "D", "E"].index(doc["answerKey"])
        return MultipleChoiceDoc(
            question=question,
            options=options,
            gold=gold,
            keys=keys,
        )
Leo Gao's avatar
Leo Gao committed
37
38

class ARCChallenge(ARCEasy):
Leo Gao's avatar
Leo Gao committed
39
    DATASET_PATH = "ai2_arc"
Leo Gao's avatar
Leo Gao committed
40
    DATASET_NAME = "ARC-Challenge"