headqa.py 2.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
"""
Interpretable Multi-Step Reasoning with Knowledge Extraction on Complex Healthcare Question Answering
https://aclanthology.org/P19-1092.pdf

HEAD-QA is a multi-choice HEAlthcare Dataset. The questions come from exams to 
access a specialized position in the Spanish healthcare system, and are challenging
even for highly specialized humans.

Homepage: https://aghie.github.io/head-qa/
10
11
"""
from lm_eval.base import MultipleChoiceTask
12

13
14

_CITATION = """
15
@misc{liu2020interpretable,
16
17
18
19
20
21
    title={Interpretable Multi-Step Reasoning with Knowledge Extraction on Complex Healthcare Question Answering}, 
    author={Ye Liu and Shaika Chowdhury and Chenwei Zhang and Cornelia Caragea and Philip S. Yu},
    year={2020},
    eprint={2008.02434},
    archivePrefix={arXiv},
    primaryClass={cs.AI}
22
23
}
"""
24

25

Jonathan Tow's avatar
Jonathan Tow committed
26
class HeadQABase(MultipleChoiceTask):
Leo Gao's avatar
Leo Gao committed
27
    VERSION = 0
28
29
30
31
32
33
34
35
36
37
38
    DATASET_PATH = "head_qa"

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

Jonathan Tow's avatar
Jonathan Tow committed
39
40
    def training_docs(self):
        if self._training_docs is None:
Jon Tow's avatar
Jon Tow committed
41
42
            self._training_docs = list(map(self._convert_standard, self.dataset["train"]))
        return self._training_docs
Jonathan Tow's avatar
Jonathan Tow committed
43
44
45
46
47
48
49

    def validation_docs(self):
        return map(self._convert_standard, self.dataset["validation"])

    def test_docs(self):
        return map(self._convert_standard, self.dataset["test"])

50
51
52
53
54
55
56
57
    def _convert_standard(self, doc):
        out_doc = {
            "id": doc["qid"],
            "query": "Question: " + doc["qtext"] + "\nAnswer:",
            "choices": [answer["atext"] for answer in doc["answers"]],
            "gold": int(doc["ra"]) - 1,
        }
        return out_doc
58

59
60
    def doc_to_text(self, doc):
        return doc["query"]
61

Jonathan Tow's avatar
Jonathan Tow committed
62

63
64
65
class HeadQAEn(HeadQABase):
    DATASET_NAME = "en"

Jonathan Tow's avatar
Jonathan Tow committed
66

67
class HeadQAEs(HeadQABase):
68
69
    DATASET_NAME = "es"

Jonathan Tow's avatar
Jonathan Tow committed
70

71
72
73
74
# for backwards compatibility
class HeadQAEsDeprecated(HeadQABase):
    DATASET_NAME = "es"

75
76
77
    def __init__(self):
        super().__init__()
        print("WARNING: headqa is deprecated. Please use headqa_es or headqa_en instead. See https://github.com/EleutherAI/lm-evaluation-harness/pull/240 for more info.")