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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from datasets import load_dataset, DatasetDict, concatenate_datasets\n",
|
10 |
+
"\n",
|
11 |
+
"columns = set(['premise', 'hypothesis', 'subset', 'label_name'])"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "markdown",
|
16 |
+
"metadata": {},
|
17 |
+
"source": [
|
18 |
+
"# SNLI\n"
|
19 |
+
]
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"cell_type": "code",
|
23 |
+
"execution_count": null,
|
24 |
+
"metadata": {},
|
25 |
+
"outputs": [],
|
26 |
+
"source": [
|
27 |
+
"snli = load_dataset('snli')\n",
|
28 |
+
"snli = DatasetDict({'train': snli['train'], 'test': snli['validation']})\n",
|
29 |
+
"snli"
|
30 |
+
]
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"cell_type": "code",
|
34 |
+
"execution_count": null,
|
35 |
+
"metadata": {},
|
36 |
+
"outputs": [],
|
37 |
+
"source": [
|
38 |
+
"mapping = {0: 'entailment', 1: 'non-entailment', 2: 'non-entailment'}\n",
|
39 |
+
"\n",
|
40 |
+
"def label_name(sample):\n",
|
41 |
+
" sample['label_name'] = mapping[sample['label']]\n",
|
42 |
+
" sample['subset'] = 'snli'\n",
|
43 |
+
" return sample\n",
|
44 |
+
"\n",
|
45 |
+
"snli = snli.filter(lambda x: x['label'] != -1, batched=False)\n",
|
46 |
+
"snli = snli.map(label_name, batched=False, remove_columns=list(set(snli['train'].column_names) - columns))\n",
|
47 |
+
"snli"
|
48 |
+
]
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"cell_type": "markdown",
|
52 |
+
"metadata": {},
|
53 |
+
"source": [
|
54 |
+
"# MNLI"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": null,
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"mnli = load_dataset('multi_nli')\n",
|
64 |
+
"mnli = DatasetDict({'train': mnli['train'], 'test': mnli['validation_matched']})\n",
|
65 |
+
"mnli"
|
66 |
+
]
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"cell_type": "code",
|
70 |
+
"execution_count": null,
|
71 |
+
"metadata": {},
|
72 |
+
"outputs": [],
|
73 |
+
"source": [
|
74 |
+
"mapping = {0: 'entailment', 1: 'non-entailment', 2: 'non-entailment'}\n",
|
75 |
+
"\n",
|
76 |
+
"def label_name(sample):\n",
|
77 |
+
" sample['label_name'] = mapping[sample['label']]\n",
|
78 |
+
" sample['subset'] = 'mnli'\n",
|
79 |
+
" return sample\n",
|
80 |
+
"\n",
|
81 |
+
"mnli = mnli.map(label_name, batched=False, remove_columns=list(set(mnli['train'].column_names) - columns))\n",
|
82 |
+
"mnli"
|
83 |
+
]
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "markdown",
|
87 |
+
"metadata": {},
|
88 |
+
"source": [
|
89 |
+
"# FEVER"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"cell_type": "code",
|
94 |
+
"execution_count": null,
|
95 |
+
"metadata": {},
|
96 |
+
"outputs": [],
|
97 |
+
"source": [
|
98 |
+
"fever = load_dataset('pietrolesci/nli_fever')\n",
|
99 |
+
"fever = DatasetDict({'train': fever['train'], 'test': fever['dev']})\n",
|
100 |
+
"fever"
|
101 |
+
]
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"cell_type": "code",
|
105 |
+
"execution_count": null,
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [],
|
108 |
+
"source": [
|
109 |
+
"mapping = {'SUPPORTS': 'entailment', 'REFUTES': 'non-entailment', 'NOT ENOUGH INFO': 'non-entailment'}\n",
|
110 |
+
"\n",
|
111 |
+
"def label_name(sample):\n",
|
112 |
+
" sample['label_name'] = mapping[sample['fever_gold_label']]\n",
|
113 |
+
" sample['subset'] = 'fever'\n",
|
114 |
+
" return sample\n",
|
115 |
+
"\n",
|
116 |
+
"fever = fever.map(label_name, batched=False, remove_columns=list(set(fever['train'].column_names) - columns))\n",
|
117 |
+
"fever"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"cell_type": "markdown",
|
122 |
+
"metadata": {},
|
123 |
+
"source": [
|
124 |
+
"# SciTail"
|
125 |
+
]
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"cell_type": "code",
|
129 |
+
"execution_count": null,
|
130 |
+
"metadata": {},
|
131 |
+
"outputs": [],
|
132 |
+
"source": [
|
133 |
+
"scitail = load_dataset('scitail', 'snli_format')\n",
|
134 |
+
"scitail = DatasetDict({'train': scitail['train'], 'test': scitail['validation']})\n",
|
135 |
+
"scitail"
|
136 |
+
]
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"cell_type": "code",
|
140 |
+
"execution_count": null,
|
141 |
+
"metadata": {},
|
142 |
+
"outputs": [],
|
143 |
+
"source": [
|
144 |
+
"mapping = {'entailment': 'entailment', 'neutral': 'non-entailment'}\n",
|
145 |
+
"\n",
|
146 |
+
"def label_name(sample):\n",
|
147 |
+
" sample['label_name'] = mapping[sample['gold_label']]\n",
|
148 |
+
" sample['premise'] = sample['sentence1']\n",
|
149 |
+
" sample['hypothesis'] = sample['sentence2']\n",
|
150 |
+
" sample['subset'] = 'scitail'\n",
|
151 |
+
" return sample\n",
|
152 |
+
"\n",
|
153 |
+
"scitail = scitail.map(label_name, batched=False, remove_columns=list(set(scitail['train'].column_names) - columns))\n",
|
154 |
+
"scitail"
|
155 |
+
]
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"cell_type": "markdown",
|
159 |
+
"metadata": {},
|
160 |
+
"source": [
|
161 |
+
"# PAWS"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"cell_type": "code",
|
166 |
+
"execution_count": null,
|
167 |
+
"metadata": {},
|
168 |
+
"outputs": [],
|
169 |
+
"source": [
|
170 |
+
"paws = load_dataset('paws', 'labeled_final')\n",
|
171 |
+
"paws = DatasetDict({'train': paws['train'], 'test': paws['validation']})\n",
|
172 |
+
"paws"
|
173 |
+
]
|
174 |
+
},
|
175 |
+
{
|
176 |
+
"cell_type": "code",
|
177 |
+
"execution_count": null,
|
178 |
+
"metadata": {},
|
179 |
+
"outputs": [],
|
180 |
+
"source": [
|
181 |
+
"mapping = {1: 'entailment', 0: 'non-entailment'}\n",
|
182 |
+
"\n",
|
183 |
+
"def label_name(sample):\n",
|
184 |
+
" sample['label_name'] = mapping[sample['label']]\n",
|
185 |
+
" sample['premise'] = sample['sentence1']\n",
|
186 |
+
" sample['hypothesis'] = sample['sentence2']\n",
|
187 |
+
" sample['subset'] = 'paws'\n",
|
188 |
+
" return sample\n",
|
189 |
+
"\n",
|
190 |
+
"paws = paws.map(label_name, batched=False, remove_columns=list(set(paws['train'].column_names) - columns))\n",
|
191 |
+
"paws"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "markdown",
|
196 |
+
"metadata": {},
|
197 |
+
"source": [
|
198 |
+
"# VitaminC"
|
199 |
+
]
|
200 |
+
},
|
201 |
+
{
|
202 |
+
"cell_type": "code",
|
203 |
+
"execution_count": null,
|
204 |
+
"metadata": {},
|
205 |
+
"outputs": [],
|
206 |
+
"source": [
|
207 |
+
"vitaminc = load_dataset('tals/vitaminc')\n",
|
208 |
+
"vitaminc = DatasetDict({'train': vitaminc['train'], 'test': vitaminc['validation']})\n",
|
209 |
+
"vitaminc"
|
210 |
+
]
|
211 |
+
},
|
212 |
+
{
|
213 |
+
"cell_type": "code",
|
214 |
+
"execution_count": null,
|
215 |
+
"metadata": {},
|
216 |
+
"outputs": [],
|
217 |
+
"source": [
|
218 |
+
"mapping = {'SUPPORTS': 'entailment', 'REFUTES': 'non-entailment', 'NOT ENOUGH INFO': 'non-entailment'}\n",
|
219 |
+
"\n",
|
220 |
+
"def label_name(sample):\n",
|
221 |
+
" sample['label_name'] = mapping[sample['label']]\n",
|
222 |
+
" sample['premise'] = sample['evidence']\n",
|
223 |
+
" sample['hypothesis'] = sample['claim']\n",
|
224 |
+
" sample['subset'] = 'vitaminc'\n",
|
225 |
+
" return sample\n",
|
226 |
+
"\n",
|
227 |
+
"vitaminc = vitaminc.map(label_name, batched=False, remove_columns=list(set(vitaminc['train'].column_names) - columns))\n",
|
228 |
+
"vitaminc"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "markdown",
|
233 |
+
"metadata": {},
|
234 |
+
"source": [
|
235 |
+
"# NLI Mixture"
|
236 |
+
]
|
237 |
+
},
|
238 |
+
{
|
239 |
+
"cell_type": "code",
|
240 |
+
"execution_count": null,
|
241 |
+
"metadata": {},
|
242 |
+
"outputs": [],
|
243 |
+
"source": [
|
244 |
+
"nli_train = concatenate_datasets([snli['train'], mnli['train'], fever['train'], scitail['train'], paws['train'], vitaminc['train']])\n",
|
245 |
+
"nli_test = concatenate_datasets([snli['test'], mnli['test'], fever['test'], scitail['test'], paws['test'], vitaminc['test']])\n",
|
246 |
+
"\n",
|
247 |
+
"nli_dataset = DatasetDict({'train': nli_train, 'test': nli_test})\n",
|
248 |
+
"nli_dataset"
|
249 |
+
]
|
250 |
+
},
|
251 |
+
{
|
252 |
+
"cell_type": "code",
|
253 |
+
"execution_count": null,
|
254 |
+
"metadata": {},
|
255 |
+
"outputs": [],
|
256 |
+
"source": [
|
257 |
+
"nli_dataset.push_to_hub('AntoineBlanot/nli_mixture')"
|
258 |
+
]
|
259 |
+
}
|
260 |
+
],
|
261 |
+
"metadata": {
|
262 |
+
"kernelspec": {
|
263 |
+
"display_name": "nlp-train",
|
264 |
+
"language": "python",
|
265 |
+
"name": "python3"
|
266 |
+
},
|
267 |
+
"language_info": {
|
268 |
+
"codemirror_mode": {
|
269 |
+
"name": "ipython",
|
270 |
+
"version": 3
|
271 |
+
},
|
272 |
+
"file_extension": ".py",
|
273 |
+
"mimetype": "text/x-python",
|
274 |
+
"name": "python",
|
275 |
+
"nbconvert_exporter": "python",
|
276 |
+
"pygments_lexer": "ipython3",
|
277 |
+
"version": "3.10.13"
|
278 |
+
}
|
279 |
+
},
|
280 |
+
"nbformat": 4,
|
281 |
+
"nbformat_minor": 2
|
282 |
+
}
|