hellaswag.py 1.26 KB
Newer Older
1
from ast import Mult
Jonathan Tow's avatar
Jonathan Tow committed
2
import re
3
from lm_eval.base import MultipleChoiceTask
4
from . common import HFTask
5
from lm_eval.mctask_experimental import MultipleChoiceDoc
6

Charles Foster's avatar
Charles Foster committed
7

8
class HellaSwag(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
9
    VERSION = 0
Charles Foster's avatar
Charles Foster committed
10
11
12
13
14
15
16
17
18
19
    DATASET_PATH = "hellaswag"
    DATASET_NAME = None

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
Jon Tow's avatar
Jon Tow committed
20
        return False
Charles Foster's avatar
Charles Foster committed
21

22
23
24
25
26
27
28
29
30
31
    @classmethod
    def preprocess(cls, text):
        text = text.strip()
        # NOTE: Brackets are artifacts of the WikiHow dataset portion of HellaSwag.
        text = text.replace(" [title]", ". ")
        text = re.sub('\\[.*?\\]', '', text)
        text = text.replace("  ", " ")
        return text

    def _convert_standard(self, doc):
32
33
34
35
36
37
38
39
40
41
42
43
        question = self.preprocess(doc["ctx_a"] + " " + doc["ctx_b"].capitalize())
        options = [self.preprocess(ending) for ending in doc['endings']]
        gold = int(doc["label"])
        keys = ["A", "B", "C", "D"]
        context = self.preprocess(doc['activity_label'])
        return MultipleChoiceDoc(
            question=question,
            options=options,
            gold=gold,
            keys=keys,
            context=context
        )