File size: 6,560 Bytes
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
 
 
 
 
 
 
b9e00cb
 
2f9157a
 
 
 
 
b9e00cb
 
 
 
 
 
 
2f9157a
 
 
b9e00cb
2f9157a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from intel_evaluate_extension.evaluation_suite.model_card_suite import ModelCardSuiteResults

from evaluate.evaluation_suite import SubTask
from evaluate.visualization import radar_plot


_HEADER = "GLUE/AdvGlue Evaluation Results"

_DESCRIPTION = """
The suite compares the GLUE results with Adversarial GLUE (AdvGLUE), a
multi-task benchmark that tests the vulnerability of modern large-scale
language models againstvarious adversarial attacks."""


class Suite(ModelCardSuiteResults):
    def __init__(self, name):
        super().__init__(name)
        self.result_keys = ["accuracy", "f1"]
        self.preprocessor = lambda x: {"text": x["text"].lower()}
        self.suite = [
            SubTask(
                task_type="text-classification",
                data="glue",
                subset="sst2",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "sentence",
                    "label_column": "label",
                    "config_name": "sst2",
                    "label_mapping": {"LABEL_0": 0.0, "LABEL_1": 1.0},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="adv_glue",
                subset="adv_sst2",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "sentence",
                    "label_column": "label",
                    "config_name": "sst2",
                    "label_mapping": {"LABEL_0": 0.0, "LABEL_1": 1.0},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="glue",
                subset="qqp",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "question1",
                    "second_input_column": "question2",
                    "label_column": "label",
                    "config_name": "qqp",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="adv_glue",
                subset="adv_qqp",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "question1",
                    "second_input_column": "question2",
                    "label_column": "label",
                    "config_name": "qqp",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="glue",
                subset="qnli",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "question",
                    "second_input_column": "sentence",
                    "label_column": "label",
                    "config_name": "qnli",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="adv_glue",
                subset="adv_qnli",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "question",
                    "second_input_column": "sentence",
                    "label_column": "label",
                    "config_name": "qnli",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="glue",
                subset="rte",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "sentence1",
                    "second_input_column": "sentence2",
                    "label_column": "label",
                    "config_name": "rte",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="adv_glue",
                subset="adv_rte",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "sentence1",
                    "second_input_column": "sentence2",
                    "label_column": "label",
                    "config_name": "rte",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="glue",
                subset="mnli",
                split="validation_mismatched[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "premise",
                    "second_input_column": "hypothesis",
                    "config_name": "mnli",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2},
                },
            ),
            SubTask(
                task_type="text-classification",
                data="adv_glue",
                subset="adv_mnli",
                split="validation[:5]",
                args_for_task={
                    "metric": "glue",
                    "input_column": "premise",
                    "second_input_column": "hypothesis",
                    "config_name": "mnli",
                    "label_mapping": {"LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2},
                },
            ),
        ]

    def process_results(self, results):
        radar_data = [
            {"accuracy " + result["task_name"].split("/")[-1]: result["accuracy"] for result in results[::2]},
            {
                "accuracy " + result["task_name"].replace("adv_", "").split("/")[-1]: result["accuracy"]
                for result in results[1::2]
            },
        ]
        return radar_plot(radar_data, ["GLUE", "AdvGLUE"])

    def plot_results(self, results, model_or_pipeline):
        radar_data = self.process_results(results)
        graphic = radar_plot(radar_data, ["GLUE " + model_or_pipeline, "AdvGLUE " + model_or_pipeline])
        return graphic