|
| 1 | +""" |
| 2 | +HellaSwag: Can a Machine Really Finish Your Sentence? |
| 3 | +https://arxiv.org/pdf/1905.07830.pdf |
| 4 | +
|
| 5 | +Hellaswag is a commonsense inference challenge dataset. Though its questions are |
| 6 | +trivial for humans (>95% accuracy), state-of-the-art models struggle (<48%). This is |
| 7 | +achieved via Adversarial Filtering (AF), a data collection paradigm wherein a |
| 8 | +series of discriminators iteratively select an adversarial set of machine-generated |
| 9 | +wrong answers. AF proves to be surprisingly robust. The key insight is to scale up |
| 10 | +the length and complexity of the dataset examples towards a critical 'Goldilocks' |
| 11 | +zone wherein generated text is ridiculous to humans, yet often misclassified by |
| 12 | +state-of-the-art models. |
| 13 | +
|
| 14 | +Homepage: https://rowanzellers.com/hellaswag/ |
| 15 | +""" |
| 16 | +import re |
| 17 | +from lm_eval.base import MultipleChoiceTask |
| 18 | + |
| 19 | +_CITATION = """ |
| 20 | +@inproceedings{zellers2019hellaswag, |
| 21 | + title={HellaSwag: Can a Machine Really Finish Your Sentence?}, |
| 22 | + author={Zellers, Rowan and Holtzman, Ari and Bisk, Yonatan and Farhadi, Ali and Choi, Yejin}, |
| 23 | + booktitle ={Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics}, |
| 24 | + year={2019} |
| 25 | +} |
| 26 | +""" |
| 27 | + |
| 28 | +LANGS = "ar,bn,ca,da,de,es,eu,fr,gu,hi,hr,hu,hy,id,it,kn,ml,mr,ne,nl,pt,ro,ru,sk,sr,sv,ta,te,uk,vi,zh".split( |
| 29 | + "," |
| 30 | +) |
| 31 | + |
| 32 | + |
| 33 | +def create_all_tasks(): |
| 34 | + """Creates a dictionary of tasks from a list of subjects |
| 35 | + :return: {task_name: task} |
| 36 | + e.g. {hellaswag_vi: Task, hellaswag_en: Task} |
| 37 | + """ |
| 38 | + return {f"mlmm_hellaswag_{lang}": create_task(lang) for lang in LANGS} |
| 39 | + |
| 40 | + |
| 41 | +def create_task(lang): |
| 42 | + class ATest(HellaSwag): |
| 43 | + def __init__(self): |
| 44 | + super().__init__(lang) |
| 45 | + |
| 46 | + return ATest |
| 47 | + |
| 48 | + |
| 49 | +class HellaSwag(MultipleChoiceTask): |
| 50 | + def __init__(self, lang, **kwargs): |
| 51 | + self.VERSION = 1 |
| 52 | + self.lang = lang |
| 53 | + self.DATASET_NAME = f"hellaswag_{lang}" |
| 54 | + self.DATASET_PATH = "malteos/m_hellaswag" |
| 55 | + self.NUM_FEW_SHOT = 0 |
| 56 | + super().__init__(**kwargs) |
| 57 | + |
| 58 | + def has_training_docs(self): |
| 59 | + return False |
| 60 | + |
| 61 | + def has_validation_docs(self): |
| 62 | + return True |
| 63 | + |
| 64 | + def has_test_docs(self): |
| 65 | + return False |
| 66 | + |
| 67 | + def training_docs(self): |
| 68 | + if self._training_docs is None: |
| 69 | + self._training_docs = list(map(self._process_doc, self.dataset["train"])) |
| 70 | + return self._training_docs |
| 71 | + |
| 72 | + def validation_docs(self): |
| 73 | + return map(self._process_doc, self.dataset["validation"]) |
| 74 | + |
| 75 | + def _process_doc(self, doc): |
| 76 | + ctx = doc["ctx_a"] + " " + doc["ctx_b"].capitalize() |
| 77 | + out_doc = { |
| 78 | + "query": self.preprocess(doc["activity_label"] + ": " + ctx), |
| 79 | + "choices": [self.preprocess(ending) for ending in doc["endings"]], |
| 80 | + "gold": int(doc["label"]), |
| 81 | + } |
| 82 | + return out_doc |
| 83 | + |
| 84 | + @classmethod |
| 85 | + def preprocess(cls, text): |
| 86 | + text = text.strip() |
| 87 | + # NOTE: Brackets are artifacts of the WikiHow dataset portion of HellaSwag. |
| 88 | + text = text.replace(" [title]", ". ") |
| 89 | + text = re.sub("\\[.*?\\]", "", text) |
| 90 | + text = text.replace(" ", " ") |
| 91 | + return text |
| 92 | + |
| 93 | + def doc_to_text(self, doc): |
| 94 | + return doc["query"] |
| 95 | + |
| 96 | + def should_decontaminate(self): |
| 97 | + return True |
| 98 | + |
| 99 | + def doc_to_decontamination_query(self, doc): |
| 100 | + return doc["query"] |
0 commit comments