hellaswag.py 1.33 KB
Newer Older
Jonathan Tow's avatar
Jonathan Tow committed
1
import re
2
from lm_eval.base import MultipleChoiceTask
3
4
from . common import HFTask

Charles Foster's avatar
Charles Foster committed
5

6
class HellaSwag(HFTask, MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
7
    VERSION = 0
Charles Foster's avatar
Charles Foster committed
8
9
10
11
12
13
14
15
16
17
    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
18
        return False
Charles Foster's avatar
Charles Foster committed
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    @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):
        ctx = doc["ctx_a"] + " " + doc["ctx_b"].capitalize()
        out_doc = {
            "query": self.preprocess(doc['activity_label'] + ': ' + ctx),
            "choices": [self.preprocess(ending) for ending in doc['endings']],
            "gold": int(doc['label']),
        }
        return out_doc

Charles Foster's avatar
Charles Foster committed
38
    def fewshot_description(self):
39
40
41
        return "Label for the relevant action: Sentences describing the " \
            "context, with an incomplete sentence trailing\nanswer that " \
            "plausibly completes the situation."
Charles Foster's avatar
Charles Foster committed
42

43
    def doc_to_text(self, doc):
44
        return doc["query"]