arc.py 2.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
"""
Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge
https://arxiv.org/pdf/1803.05457.pdf

The ARC dataset consists of 7,787 science exam questions drawn from a variety
of sources, including science questions provided under license by a research
partner affiliated with AI2. These are text-only, English language exam questions
that span several grade levels as indicated in the files. Each question has a
multiple choice structure (typically 4 answer options). The questions are sorted
into a Challenge Set of 2,590 “hard” questions (those that both a retrieval and
a co-occurrence method fail to answer correctly) and an Easy Set of 5,197 questions.

Homepage: https://allenai.org/data/arc
14
15
16
"""
from lm_eval.base import MultipleChoiceTask
from . common import HFTask
17

18
19

_CITATION = """
20
21
22
23
24
25
26
27
@article{Clark2018ThinkYH,
  title={Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge},
  author={Peter Clark and Isaac Cowhey and Oren Etzioni and Tushar Khot and Ashish Sabharwal and Carissa Schoenick and Oyvind Tafjord},
  journal={ArXiv},
  year={2018},
  volume={abs/1803.05457}
}
"""
Leo Gao's avatar
Leo Gao committed
28

Jonathan Tow's avatar
Jonathan Tow committed
29

30
class ARCEasy(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
31
    VERSION = 0
Leo Gao's avatar
Leo Gao committed
32
33
    DATASET_PATH = "ai2_arc"
    DATASET_NAME = "ARC-Easy"
Leo Gao's avatar
Leo Gao committed
34
35
36
37
38
39
40
41
42
43

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

44
45
46
47
48
49
50
51
52
53
54
55
    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
56

57
58
    def doc_to_text(self, doc):
        return doc["query"]
Jonathan Tow's avatar
Jonathan Tow committed
59

Leo Gao's avatar
Leo Gao committed
60
61

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