arc.py 1.63 KB
Newer Older
Jonathan Tow's avatar
Jonathan Tow committed
1
import numpy as np
2
from lm_eval.base import MultipleChoiceTask
&'s avatar
& committed
3
from ..metrics import mean
4
from . common import HFTask
Leo Gao's avatar
Leo Gao committed
5

Jonathan Tow's avatar
Jonathan Tow committed
6

7
class ARCEasy(HFTask, MultipleChoiceTask):
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
21
22
23
24
25
26
27
28
29
30
31
    def _convert_standard(self, doc):
        # 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"])
        out_doc = {
            "id": doc["id"],
            "query": "Question: " + doc["question"] + "\nAnswer:",
            "choices": doc["choices"]["text"],
            "gold": ["A", "B", "C", "D", "E"].index(doc["answerKey"]),
        }
        return out_doc
Leo Gao's avatar
Leo Gao committed
32

33
34
35
    def _load_docs(self, docs):
        for record in docs:
            yield self._convert_standard(record)
Leo Gao's avatar
Leo Gao committed
36

37
38
39
    def training_docs(self):
        docs = super().training_docs()
        return self._load_docs(docs)
Jonathan Tow's avatar
Jonathan Tow committed
40

41
42
43
    def validation_docs(self):
        docs = super().validation_docs()
        return self._load_docs(docs)
Leo Gao's avatar
Leo Gao committed
44

45
46
47
    def test_docs(self):
        docs = super().test_docs()
        return self._load_docs(docs)
Leo Gao's avatar
Leo Gao committed
48

49
50
51
    def fewshot_description(self):
        # TODO: figure out description
        return ""
Leo Gao's avatar
Leo Gao committed
52

53
54
    def doc_to_text(self, doc):
        return doc["query"]
Jonathan Tow's avatar
Jonathan Tow committed
55

Leo Gao's avatar
Leo Gao committed
56
57

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