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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 3,
|
| 6 |
+
"id": "56c5bf21-53d3-4403-89b3-4cd0a5b0777b",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"/data/ebay/notebooks/haorzhang/examples/pusl_github\n"
|
| 14 |
+
]
|
| 15 |
+
}
|
| 16 |
+
],
|
| 17 |
+
"source": [
|
| 18 |
+
"from datasets import load_dataset, concatenate_datasets\n",
|
| 19 |
+
"import os"
|
| 20 |
+
]
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"cell_type": "code",
|
| 24 |
+
"execution_count": 11,
|
| 25 |
+
"id": "b6948f5d-bf4b-4704-8249-0bfe965bcccc",
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [],
|
| 28 |
+
"source": [
|
| 29 |
+
"\n",
|
| 30 |
+
"data_dir = \"data\"\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"def load_data_by_name(data_name, split):\n",
|
| 33 |
+
" postfix = \"csv\"\n",
|
| 34 |
+
" assert data_name in [\"Eurlex-4.3K\", \"AmazonCat-13K\"]\n",
|
| 35 |
+
" data_path = os.path.join(data_dir, data_name)\n",
|
| 36 |
+
" num_data_files = {}\n",
|
| 37 |
+
" num_path_list = []\n",
|
| 38 |
+
"\n",
|
| 39 |
+
" for file_name in os.listdir(data_path):\n",
|
| 40 |
+
" if file_name.startswith(\"num_\") and (split+\".\") in file_name:\n",
|
| 41 |
+
" file_path = os.path.join(data_path, file_name)\n",
|
| 42 |
+
" num_data_files[file_name] = file_path\n",
|
| 43 |
+
" num_path_list.append(file_path)\n",
|
| 44 |
+
" print(\"data list\", num_path_list)\n",
|
| 45 |
+
" \n",
|
| 46 |
+
" num_dataset_list = [\n",
|
| 47 |
+
" load_dataset(postfix, data_files=num_data, split=\"train\")\n",
|
| 48 |
+
" for num_data in num_path_list\n",
|
| 49 |
+
" ]\n",
|
| 50 |
+
" concat_dataset = concatenate_datasets(num_dataset_list)\n",
|
| 51 |
+
" return concat_dataset\n",
|
| 52 |
+
"\n"
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"cell_type": "code",
|
| 57 |
+
"execution_count": 5,
|
| 58 |
+
"id": "8f268925-b786-42bf-9192-5148fda9d75a",
|
| 59 |
+
"metadata": {},
|
| 60 |
+
"outputs": [],
|
| 61 |
+
"source": []
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"cell_type": "code",
|
| 65 |
+
"execution_count": 6,
|
| 66 |
+
"id": "ec8e19a0-8acd-4a8a-8d0e-ae53fad37443",
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"outputs": [
|
| 69 |
+
{
|
| 70 |
+
"name": "stderr",
|
| 71 |
+
"output_type": "stream",
|
| 72 |
+
"text": [
|
| 73 |
+
"/opt/conda/lib/python3.10/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.26.4\n",
|
| 74 |
+
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n"
|
| 75 |
+
]
|
| 76 |
+
}
|
| 77 |
+
],
|
| 78 |
+
"source": [
|
| 79 |
+
"eurlex_train = load_data_by_name(\"Eurlex-4.3K\", split=\"train\")\n",
|
| 80 |
+
"amazoncat_train = load_data_by_name(\"AmazonCat-13K\", split=\"train\")"
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"cell_type": "code",
|
| 85 |
+
"execution_count": 7,
|
| 86 |
+
"id": "310494b0-bdd6-40be-8ff5-30cffa4442ed",
|
| 87 |
+
"metadata": {},
|
| 88 |
+
"outputs": [],
|
| 89 |
+
"source": [
|
| 90 |
+
"# amazoncat_train[:10]"
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"cell_type": "code",
|
| 95 |
+
"execution_count": 12,
|
| 96 |
+
"id": "761906b8-6c1d-4d48-adcf-20589d9a0385",
|
| 97 |
+
"metadata": {},
|
| 98 |
+
"outputs": [
|
| 99 |
+
{
|
| 100 |
+
"name": "stdout",
|
| 101 |
+
"output_type": "stream",
|
| 102 |
+
"text": [
|
| 103 |
+
"data list ['data/AmazonCat-13K/num_1_test.csv', 'data/AmazonCat-13K/num_15_test.csv', 'data/AmazonCat-13K/num_3_test.csv', 'data/AmazonCat-13K/num_5_test.csv', 'data/AmazonCat-13K/num_7_test.csv', 'data/AmazonCat-13K/num_8_test.csv', 'data/AmazonCat-13K/num_14_test.csv', 'data/AmazonCat-13K/num_17_test.csv', 'data/AmazonCat-13K/num_18_test.csv', 'data/AmazonCat-13K/num_16_test.csv', 'data/AmazonCat-13K/num_4_test.csv', 'data/AmazonCat-13K/num_11_test.csv', 'data/AmazonCat-13K/num_19_test.csv', 'data/AmazonCat-13K/num_6_test.csv', 'data/AmazonCat-13K/num_9_test.csv', 'data/AmazonCat-13K/num_10_test.csv', 'data/AmazonCat-13K/num_13_test.csv', 'data/AmazonCat-13K/num_2_test.csv', 'data/AmazonCat-13K/num_12_test.csv']\n"
|
| 104 |
+
]
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"data": {
|
| 108 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 109 |
+
"model_id": "9b92cd88a7884f1b9d9195b7c93044f3",
|
| 110 |
+
"version_major": 2,
|
| 111 |
+
"version_minor": 0
|
| 112 |
+
},
|
| 113 |
+
"text/plain": [
|
| 114 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
"metadata": {},
|
| 118 |
+
"output_type": "display_data"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"data": {
|
| 122 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 123 |
+
"model_id": "be5bb6a3eaa2406eb863fa0db9591f6a",
|
| 124 |
+
"version_major": 2,
|
| 125 |
+
"version_minor": 0
|
| 126 |
+
},
|
| 127 |
+
"text/plain": [
|
| 128 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
"metadata": {},
|
| 132 |
+
"output_type": "display_data"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"data": {
|
| 136 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 137 |
+
"model_id": "40d1d323222b438296f6ca20469ad357",
|
| 138 |
+
"version_major": 2,
|
| 139 |
+
"version_minor": 0
|
| 140 |
+
},
|
| 141 |
+
"text/plain": [
|
| 142 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 143 |
+
]
|
| 144 |
+
},
|
| 145 |
+
"metadata": {},
|
| 146 |
+
"output_type": "display_data"
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"data": {
|
| 150 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 151 |
+
"model_id": "dc27865a734745d092f56404c073e775",
|
| 152 |
+
"version_major": 2,
|
| 153 |
+
"version_minor": 0
|
| 154 |
+
},
|
| 155 |
+
"text/plain": [
|
| 156 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
"metadata": {},
|
| 160 |
+
"output_type": "display_data"
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"data": {
|
| 164 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 165 |
+
"model_id": "ed08df72911f47d4934d883ca07e7075",
|
| 166 |
+
"version_major": 2,
|
| 167 |
+
"version_minor": 0
|
| 168 |
+
},
|
| 169 |
+
"text/plain": [
|
| 170 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"output_type": "display_data"
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"data": {
|
| 178 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 179 |
+
"model_id": "34df673160704fdea4ba0160b5322813",
|
| 180 |
+
"version_major": 2,
|
| 181 |
+
"version_minor": 0
|
| 182 |
+
},
|
| 183 |
+
"text/plain": [
|
| 184 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"output_type": "display_data"
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"data": {
|
| 192 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 193 |
+
"model_id": "9e9612f9473c4aefbfb5aeaa8275068f",
|
| 194 |
+
"version_major": 2,
|
| 195 |
+
"version_minor": 0
|
| 196 |
+
},
|
| 197 |
+
"text/plain": [
|
| 198 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 199 |
+
]
|
| 200 |
+
},
|
| 201 |
+
"metadata": {},
|
| 202 |
+
"output_type": "display_data"
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"data": {
|
| 206 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 207 |
+
"model_id": "3658e985c20e469086a326ab42fb62cb",
|
| 208 |
+
"version_major": 2,
|
| 209 |
+
"version_minor": 0
|
| 210 |
+
},
|
| 211 |
+
"text/plain": [
|
| 212 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 213 |
+
]
|
| 214 |
+
},
|
| 215 |
+
"metadata": {},
|
| 216 |
+
"output_type": "display_data"
|
| 217 |
+
},
|
| 218 |
+
{
|
| 219 |
+
"data": {
|
| 220 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 221 |
+
"model_id": "9d220cdc95cb4b448098a6abbdbf7bf7",
|
| 222 |
+
"version_major": 2,
|
| 223 |
+
"version_minor": 0
|
| 224 |
+
},
|
| 225 |
+
"text/plain": [
|
| 226 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 227 |
+
]
|
| 228 |
+
},
|
| 229 |
+
"metadata": {},
|
| 230 |
+
"output_type": "display_data"
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"data": {
|
| 234 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 235 |
+
"model_id": "173ec3de957b40aaaf02c70fca267108",
|
| 236 |
+
"version_major": 2,
|
| 237 |
+
"version_minor": 0
|
| 238 |
+
},
|
| 239 |
+
"text/plain": [
|
| 240 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
"metadata": {},
|
| 244 |
+
"output_type": "display_data"
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
"data": {
|
| 248 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 249 |
+
"model_id": "71eb62f31e4e4f4fab84d5168ac8c36a",
|
| 250 |
+
"version_major": 2,
|
| 251 |
+
"version_minor": 0
|
| 252 |
+
},
|
| 253 |
+
"text/plain": [
|
| 254 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 255 |
+
]
|
| 256 |
+
},
|
| 257 |
+
"metadata": {},
|
| 258 |
+
"output_type": "display_data"
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
"data": {
|
| 262 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 263 |
+
"model_id": "be4d2ec7d3054d75bf80cee8d477f480",
|
| 264 |
+
"version_major": 2,
|
| 265 |
+
"version_minor": 0
|
| 266 |
+
},
|
| 267 |
+
"text/plain": [
|
| 268 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
+
"metadata": {},
|
| 272 |
+
"output_type": "display_data"
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"data": {
|
| 276 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 277 |
+
"model_id": "a87c1ab290264b459eb1840b49e671c9",
|
| 278 |
+
"version_major": 2,
|
| 279 |
+
"version_minor": 0
|
| 280 |
+
},
|
| 281 |
+
"text/plain": [
|
| 282 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 283 |
+
]
|
| 284 |
+
},
|
| 285 |
+
"metadata": {},
|
| 286 |
+
"output_type": "display_data"
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"data": {
|
| 290 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 291 |
+
"model_id": "a5ab312c89104d1f94f84ef7d08afcb4",
|
| 292 |
+
"version_major": 2,
|
| 293 |
+
"version_minor": 0
|
| 294 |
+
},
|
| 295 |
+
"text/plain": [
|
| 296 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 297 |
+
]
|
| 298 |
+
},
|
| 299 |
+
"metadata": {},
|
| 300 |
+
"output_type": "display_data"
|
| 301 |
+
},
|
| 302 |
+
{
|
| 303 |
+
"data": {
|
| 304 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 305 |
+
"model_id": "96394096c6b54b918083eb39ecba76dd",
|
| 306 |
+
"version_major": 2,
|
| 307 |
+
"version_minor": 0
|
| 308 |
+
},
|
| 309 |
+
"text/plain": [
|
| 310 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 311 |
+
]
|
| 312 |
+
},
|
| 313 |
+
"metadata": {},
|
| 314 |
+
"output_type": "display_data"
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"data": {
|
| 318 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 319 |
+
"model_id": "9a25a2da1c30496db4679c422d7c05b3",
|
| 320 |
+
"version_major": 2,
|
| 321 |
+
"version_minor": 0
|
| 322 |
+
},
|
| 323 |
+
"text/plain": [
|
| 324 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 325 |
+
]
|
| 326 |
+
},
|
| 327 |
+
"metadata": {},
|
| 328 |
+
"output_type": "display_data"
|
| 329 |
+
},
|
| 330 |
+
{
|
| 331 |
+
"data": {
|
| 332 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 333 |
+
"model_id": "83193442191a48f4bd5811863e4cfb7e",
|
| 334 |
+
"version_major": 2,
|
| 335 |
+
"version_minor": 0
|
| 336 |
+
},
|
| 337 |
+
"text/plain": [
|
| 338 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 339 |
+
]
|
| 340 |
+
},
|
| 341 |
+
"metadata": {},
|
| 342 |
+
"output_type": "display_data"
|
| 343 |
+
},
|
| 344 |
+
{
|
| 345 |
+
"data": {
|
| 346 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 347 |
+
"model_id": "e2427fbeb4bc4fd48deb461459d7aaec",
|
| 348 |
+
"version_major": 2,
|
| 349 |
+
"version_minor": 0
|
| 350 |
+
},
|
| 351 |
+
"text/plain": [
|
| 352 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 353 |
+
]
|
| 354 |
+
},
|
| 355 |
+
"metadata": {},
|
| 356 |
+
"output_type": "display_data"
|
| 357 |
+
}
|
| 358 |
+
],
|
| 359 |
+
"source": [
|
| 360 |
+
"amazoncat_test = load_data_by_name(\"AmazonCat-13K\", split=\"test\")\n",
|
| 361 |
+
"df_amazoncat_test = amazoncat_test.to_pandas()\n",
|
| 362 |
+
"df_amazoncat_test_narrow = df_amazoncat_test[df_amazoncat_test[\"num_keyphrases\"] <= 2*5]\n",
|
| 363 |
+
"df_amazoncat_test_diverse = df_amazoncat_test[df_amazoncat_test[\"num_keyphrases\"] > 2*5]"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"cell_type": "code",
|
| 368 |
+
"execution_count": 19,
|
| 369 |
+
"id": "49f925bf-8bb3-492e-8fed-dd7cad5649f5",
|
| 370 |
+
"metadata": {},
|
| 371 |
+
"outputs": [
|
| 372 |
+
{
|
| 373 |
+
"name": "stdout",
|
| 374 |
+
"output_type": "stream",
|
| 375 |
+
"text": [
|
| 376 |
+
"data list ['data/Eurlex-4.3K/num_1_test.csv', 'data/Eurlex-4.3K/num_15_test.csv', 'data/Eurlex-4.3K/num_21_test.csv', 'data/Eurlex-4.3K/num_23_test.csv', 'data/Eurlex-4.3K/num_28_test.csv', 'data/Eurlex-4.3K/num_30_test.csv', 'data/Eurlex-4.3K/num_35_test.csv', 'data/Eurlex-4.3K/num_3_test.csv', 'data/Eurlex-4.3K/num_5_test.csv', 'data/Eurlex-4.3K/num_7_test.csv', 'data/Eurlex-4.3K/num_8_test.csv', 'data/Eurlex-4.3K/num_14_test.csv', 'data/Eurlex-4.3K/num_17_test.csv', 'data/Eurlex-4.3K/num_18_test.csv', 'data/Eurlex-4.3K/num_20_test.csv', 'data/Eurlex-4.3K/num_26_test.csv', 'data/Eurlex-4.3K/num_16_test.csv', 'data/Eurlex-4.3K/num_37_test.csv', 'data/Eurlex-4.3K/num_40_test.csv', 'data/Eurlex-4.3K/num_42_test.csv', 'data/Eurlex-4.3K/num_4_test.csv', 'data/Eurlex-4.3K/num_11_test.csv', 'data/Eurlex-4.3K/num_19_test.csv', 'data/Eurlex-4.3K/num_22_test.csv', 'data/Eurlex-4.3K/num_27_test.csv', 'data/Eurlex-4.3K/num_34_test.csv', 'data/Eurlex-4.3K/num_39_test.csv', 'data/Eurlex-4.3K/num_6_test.csv', 'data/Eurlex-4.3K/num_9_test.csv', 'data/Eurlex-4.3K/num_10_test.csv', 'data/Eurlex-4.3K/num_13_test.csv', 'data/Eurlex-4.3K/num_32_test.csv', 'data/Eurlex-4.3K/num_33_test.csv', 'data/Eurlex-4.3K/num_41_test.csv', 'data/Eurlex-4.3K/num_2_test.csv', 'data/Eurlex-4.3K/num_12_test.csv', 'data/Eurlex-4.3K/num_24_test.csv', 'data/Eurlex-4.3K/num_25_test.csv', 'data/Eurlex-4.3K/num_29_test.csv', 'data/Eurlex-4.3K/num_31_test.csv', 'data/Eurlex-4.3K/num_36_test.csv', 'data/Eurlex-4.3K/num_38_test.csv']\n"
|
| 377 |
+
]
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"data": {
|
| 381 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 382 |
+
"model_id": "ca6d22bba9be4a189429b351ea6ca6f4",
|
| 383 |
+
"version_major": 2,
|
| 384 |
+
"version_minor": 0
|
| 385 |
+
},
|
| 386 |
+
"text/plain": [
|
| 387 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 388 |
+
]
|
| 389 |
+
},
|
| 390 |
+
"metadata": {},
|
| 391 |
+
"output_type": "display_data"
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"data": {
|
| 395 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 396 |
+
"model_id": "8649ffd4855b4f64a9aa1b4e35ec0a9d",
|
| 397 |
+
"version_major": 2,
|
| 398 |
+
"version_minor": 0
|
| 399 |
+
},
|
| 400 |
+
"text/plain": [
|
| 401 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 402 |
+
]
|
| 403 |
+
},
|
| 404 |
+
"metadata": {},
|
| 405 |
+
"output_type": "display_data"
|
| 406 |
+
},
|
| 407 |
+
{
|
| 408 |
+
"data": {
|
| 409 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 410 |
+
"model_id": "29d94f1990e04a4b999a9342fbe1c04e",
|
| 411 |
+
"version_major": 2,
|
| 412 |
+
"version_minor": 0
|
| 413 |
+
},
|
| 414 |
+
"text/plain": [
|
| 415 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 416 |
+
]
|
| 417 |
+
},
|
| 418 |
+
"metadata": {},
|
| 419 |
+
"output_type": "display_data"
|
| 420 |
+
},
|
| 421 |
+
{
|
| 422 |
+
"data": {
|
| 423 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 424 |
+
"model_id": "ac71e14d40da4e34ab41e9990b4a1f67",
|
| 425 |
+
"version_major": 2,
|
| 426 |
+
"version_minor": 0
|
| 427 |
+
},
|
| 428 |
+
"text/plain": [
|
| 429 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 430 |
+
]
|
| 431 |
+
},
|
| 432 |
+
"metadata": {},
|
| 433 |
+
"output_type": "display_data"
|
| 434 |
+
},
|
| 435 |
+
{
|
| 436 |
+
"data": {
|
| 437 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 438 |
+
"model_id": "011ab1cecdcb4641bb21319e20360a17",
|
| 439 |
+
"version_major": 2,
|
| 440 |
+
"version_minor": 0
|
| 441 |
+
},
|
| 442 |
+
"text/plain": [
|
| 443 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 444 |
+
]
|
| 445 |
+
},
|
| 446 |
+
"metadata": {},
|
| 447 |
+
"output_type": "display_data"
|
| 448 |
+
},
|
| 449 |
+
{
|
| 450 |
+
"data": {
|
| 451 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 452 |
+
"model_id": "51bf0f8ed4ed4220891a0ac80122f2fe",
|
| 453 |
+
"version_major": 2,
|
| 454 |
+
"version_minor": 0
|
| 455 |
+
},
|
| 456 |
+
"text/plain": [
|
| 457 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 458 |
+
]
|
| 459 |
+
},
|
| 460 |
+
"metadata": {},
|
| 461 |
+
"output_type": "display_data"
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"data": {
|
| 465 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 466 |
+
"model_id": "47b1c5223cdd499881cf0968f1226854",
|
| 467 |
+
"version_major": 2,
|
| 468 |
+
"version_minor": 0
|
| 469 |
+
},
|
| 470 |
+
"text/plain": [
|
| 471 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 472 |
+
]
|
| 473 |
+
},
|
| 474 |
+
"metadata": {},
|
| 475 |
+
"output_type": "display_data"
|
| 476 |
+
},
|
| 477 |
+
{
|
| 478 |
+
"data": {
|
| 479 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 480 |
+
"model_id": "36eaa65b1e114154b886f3cbae44ba6a",
|
| 481 |
+
"version_major": 2,
|
| 482 |
+
"version_minor": 0
|
| 483 |
+
},
|
| 484 |
+
"text/plain": [
|
| 485 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 486 |
+
]
|
| 487 |
+
},
|
| 488 |
+
"metadata": {},
|
| 489 |
+
"output_type": "display_data"
|
| 490 |
+
},
|
| 491 |
+
{
|
| 492 |
+
"data": {
|
| 493 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 494 |
+
"model_id": "cc06d0aa3a1742e29ecb1ae03719bb28",
|
| 495 |
+
"version_major": 2,
|
| 496 |
+
"version_minor": 0
|
| 497 |
+
},
|
| 498 |
+
"text/plain": [
|
| 499 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 500 |
+
]
|
| 501 |
+
},
|
| 502 |
+
"metadata": {},
|
| 503 |
+
"output_type": "display_data"
|
| 504 |
+
},
|
| 505 |
+
{
|
| 506 |
+
"data": {
|
| 507 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 508 |
+
"model_id": "567be222a4914ce0ac899ea3283695a6",
|
| 509 |
+
"version_major": 2,
|
| 510 |
+
"version_minor": 0
|
| 511 |
+
},
|
| 512 |
+
"text/plain": [
|
| 513 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 514 |
+
]
|
| 515 |
+
},
|
| 516 |
+
"metadata": {},
|
| 517 |
+
"output_type": "display_data"
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
"data": {
|
| 521 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 522 |
+
"model_id": "308f4cb1d5974af19c6ed59c51dc11ab",
|
| 523 |
+
"version_major": 2,
|
| 524 |
+
"version_minor": 0
|
| 525 |
+
},
|
| 526 |
+
"text/plain": [
|
| 527 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 528 |
+
]
|
| 529 |
+
},
|
| 530 |
+
"metadata": {},
|
| 531 |
+
"output_type": "display_data"
|
| 532 |
+
},
|
| 533 |
+
{
|
| 534 |
+
"data": {
|
| 535 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 536 |
+
"model_id": "a2bc8d44ad7e45499ce188b47985f46e",
|
| 537 |
+
"version_major": 2,
|
| 538 |
+
"version_minor": 0
|
| 539 |
+
},
|
| 540 |
+
"text/plain": [
|
| 541 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 542 |
+
]
|
| 543 |
+
},
|
| 544 |
+
"metadata": {},
|
| 545 |
+
"output_type": "display_data"
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"data": {
|
| 549 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 550 |
+
"model_id": "e07b5cb0e12e411bbb4aafc517d48a81",
|
| 551 |
+
"version_major": 2,
|
| 552 |
+
"version_minor": 0
|
| 553 |
+
},
|
| 554 |
+
"text/plain": [
|
| 555 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 556 |
+
]
|
| 557 |
+
},
|
| 558 |
+
"metadata": {},
|
| 559 |
+
"output_type": "display_data"
|
| 560 |
+
},
|
| 561 |
+
{
|
| 562 |
+
"data": {
|
| 563 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 564 |
+
"model_id": "11db8dada8544432bc94d0612ff3ff27",
|
| 565 |
+
"version_major": 2,
|
| 566 |
+
"version_minor": 0
|
| 567 |
+
},
|
| 568 |
+
"text/plain": [
|
| 569 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 570 |
+
]
|
| 571 |
+
},
|
| 572 |
+
"metadata": {},
|
| 573 |
+
"output_type": "display_data"
|
| 574 |
+
},
|
| 575 |
+
{
|
| 576 |
+
"data": {
|
| 577 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 578 |
+
"model_id": "e4397ae0e4e14ebfaab0cc8bc0ee6e51",
|
| 579 |
+
"version_major": 2,
|
| 580 |
+
"version_minor": 0
|
| 581 |
+
},
|
| 582 |
+
"text/plain": [
|
| 583 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 584 |
+
]
|
| 585 |
+
},
|
| 586 |
+
"metadata": {},
|
| 587 |
+
"output_type": "display_data"
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"data": {
|
| 591 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 592 |
+
"model_id": "fae8cbce454d42a3a31d0d3661d9e4ed",
|
| 593 |
+
"version_major": 2,
|
| 594 |
+
"version_minor": 0
|
| 595 |
+
},
|
| 596 |
+
"text/plain": [
|
| 597 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 598 |
+
]
|
| 599 |
+
},
|
| 600 |
+
"metadata": {},
|
| 601 |
+
"output_type": "display_data"
|
| 602 |
+
},
|
| 603 |
+
{
|
| 604 |
+
"data": {
|
| 605 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 606 |
+
"model_id": "b32626755caf4a28a21eb5fb9fa72e7f",
|
| 607 |
+
"version_major": 2,
|
| 608 |
+
"version_minor": 0
|
| 609 |
+
},
|
| 610 |
+
"text/plain": [
|
| 611 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 612 |
+
]
|
| 613 |
+
},
|
| 614 |
+
"metadata": {},
|
| 615 |
+
"output_type": "display_data"
|
| 616 |
+
},
|
| 617 |
+
{
|
| 618 |
+
"data": {
|
| 619 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 620 |
+
"model_id": "dadfe9eb07004d85a86223911c05c353",
|
| 621 |
+
"version_major": 2,
|
| 622 |
+
"version_minor": 0
|
| 623 |
+
},
|
| 624 |
+
"text/plain": [
|
| 625 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 626 |
+
]
|
| 627 |
+
},
|
| 628 |
+
"metadata": {},
|
| 629 |
+
"output_type": "display_data"
|
| 630 |
+
},
|
| 631 |
+
{
|
| 632 |
+
"data": {
|
| 633 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 634 |
+
"model_id": "16e0b00a6dcd4f748db4ceaba6ce0f61",
|
| 635 |
+
"version_major": 2,
|
| 636 |
+
"version_minor": 0
|
| 637 |
+
},
|
| 638 |
+
"text/plain": [
|
| 639 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 640 |
+
]
|
| 641 |
+
},
|
| 642 |
+
"metadata": {},
|
| 643 |
+
"output_type": "display_data"
|
| 644 |
+
},
|
| 645 |
+
{
|
| 646 |
+
"data": {
|
| 647 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 648 |
+
"model_id": "f9efa8cef0524848ad40bf91ff819338",
|
| 649 |
+
"version_major": 2,
|
| 650 |
+
"version_minor": 0
|
| 651 |
+
},
|
| 652 |
+
"text/plain": [
|
| 653 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 654 |
+
]
|
| 655 |
+
},
|
| 656 |
+
"metadata": {},
|
| 657 |
+
"output_type": "display_data"
|
| 658 |
+
},
|
| 659 |
+
{
|
| 660 |
+
"data": {
|
| 661 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 662 |
+
"model_id": "d9a8f0b997ee49fb93d920bdca102c6e",
|
| 663 |
+
"version_major": 2,
|
| 664 |
+
"version_minor": 0
|
| 665 |
+
},
|
| 666 |
+
"text/plain": [
|
| 667 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 668 |
+
]
|
| 669 |
+
},
|
| 670 |
+
"metadata": {},
|
| 671 |
+
"output_type": "display_data"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"data": {
|
| 675 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 676 |
+
"model_id": "dfc32b7f1b6c43ad87df5cb93d74509e",
|
| 677 |
+
"version_major": 2,
|
| 678 |
+
"version_minor": 0
|
| 679 |
+
},
|
| 680 |
+
"text/plain": [
|
| 681 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 682 |
+
]
|
| 683 |
+
},
|
| 684 |
+
"metadata": {},
|
| 685 |
+
"output_type": "display_data"
|
| 686 |
+
},
|
| 687 |
+
{
|
| 688 |
+
"data": {
|
| 689 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 690 |
+
"model_id": "8032caba97b0401594899337b348dc6f",
|
| 691 |
+
"version_major": 2,
|
| 692 |
+
"version_minor": 0
|
| 693 |
+
},
|
| 694 |
+
"text/plain": [
|
| 695 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 696 |
+
]
|
| 697 |
+
},
|
| 698 |
+
"metadata": {},
|
| 699 |
+
"output_type": "display_data"
|
| 700 |
+
},
|
| 701 |
+
{
|
| 702 |
+
"data": {
|
| 703 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 704 |
+
"model_id": "e4849fd7c62941719928969fa67cfac5",
|
| 705 |
+
"version_major": 2,
|
| 706 |
+
"version_minor": 0
|
| 707 |
+
},
|
| 708 |
+
"text/plain": [
|
| 709 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 710 |
+
]
|
| 711 |
+
},
|
| 712 |
+
"metadata": {},
|
| 713 |
+
"output_type": "display_data"
|
| 714 |
+
},
|
| 715 |
+
{
|
| 716 |
+
"data": {
|
| 717 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 718 |
+
"model_id": "fbae7fbc47724893a3dc85aa4788f529",
|
| 719 |
+
"version_major": 2,
|
| 720 |
+
"version_minor": 0
|
| 721 |
+
},
|
| 722 |
+
"text/plain": [
|
| 723 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 724 |
+
]
|
| 725 |
+
},
|
| 726 |
+
"metadata": {},
|
| 727 |
+
"output_type": "display_data"
|
| 728 |
+
},
|
| 729 |
+
{
|
| 730 |
+
"data": {
|
| 731 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 732 |
+
"model_id": "8143b83308284ef98de8fdaa13cdbafb",
|
| 733 |
+
"version_major": 2,
|
| 734 |
+
"version_minor": 0
|
| 735 |
+
},
|
| 736 |
+
"text/plain": [
|
| 737 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 738 |
+
]
|
| 739 |
+
},
|
| 740 |
+
"metadata": {},
|
| 741 |
+
"output_type": "display_data"
|
| 742 |
+
},
|
| 743 |
+
{
|
| 744 |
+
"data": {
|
| 745 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 746 |
+
"model_id": "3165953202584c3db9c5b41a8bbc1707",
|
| 747 |
+
"version_major": 2,
|
| 748 |
+
"version_minor": 0
|
| 749 |
+
},
|
| 750 |
+
"text/plain": [
|
| 751 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 752 |
+
]
|
| 753 |
+
},
|
| 754 |
+
"metadata": {},
|
| 755 |
+
"output_type": "display_data"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"data": {
|
| 759 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 760 |
+
"model_id": "4823e131bbf4436895a04c577123998c",
|
| 761 |
+
"version_major": 2,
|
| 762 |
+
"version_minor": 0
|
| 763 |
+
},
|
| 764 |
+
"text/plain": [
|
| 765 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 766 |
+
]
|
| 767 |
+
},
|
| 768 |
+
"metadata": {},
|
| 769 |
+
"output_type": "display_data"
|
| 770 |
+
},
|
| 771 |
+
{
|
| 772 |
+
"data": {
|
| 773 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 774 |
+
"model_id": "89e32dd82687487d9391d7d938378cb3",
|
| 775 |
+
"version_major": 2,
|
| 776 |
+
"version_minor": 0
|
| 777 |
+
},
|
| 778 |
+
"text/plain": [
|
| 779 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 780 |
+
]
|
| 781 |
+
},
|
| 782 |
+
"metadata": {},
|
| 783 |
+
"output_type": "display_data"
|
| 784 |
+
},
|
| 785 |
+
{
|
| 786 |
+
"data": {
|
| 787 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 788 |
+
"model_id": "aa3199550dfd46eb81b610275dc2c077",
|
| 789 |
+
"version_major": 2,
|
| 790 |
+
"version_minor": 0
|
| 791 |
+
},
|
| 792 |
+
"text/plain": [
|
| 793 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 794 |
+
]
|
| 795 |
+
},
|
| 796 |
+
"metadata": {},
|
| 797 |
+
"output_type": "display_data"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"data": {
|
| 801 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 802 |
+
"model_id": "3df62eccd0ea4093ab641aafa55ffd89",
|
| 803 |
+
"version_major": 2,
|
| 804 |
+
"version_minor": 0
|
| 805 |
+
},
|
| 806 |
+
"text/plain": [
|
| 807 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 808 |
+
]
|
| 809 |
+
},
|
| 810 |
+
"metadata": {},
|
| 811 |
+
"output_type": "display_data"
|
| 812 |
+
},
|
| 813 |
+
{
|
| 814 |
+
"data": {
|
| 815 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 816 |
+
"model_id": "235c176234a6464a8d5a88edf397dde4",
|
| 817 |
+
"version_major": 2,
|
| 818 |
+
"version_minor": 0
|
| 819 |
+
},
|
| 820 |
+
"text/plain": [
|
| 821 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 822 |
+
]
|
| 823 |
+
},
|
| 824 |
+
"metadata": {},
|
| 825 |
+
"output_type": "display_data"
|
| 826 |
+
},
|
| 827 |
+
{
|
| 828 |
+
"data": {
|
| 829 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 830 |
+
"model_id": "3426003bb9fd4631a87f4802435b3ac6",
|
| 831 |
+
"version_major": 2,
|
| 832 |
+
"version_minor": 0
|
| 833 |
+
},
|
| 834 |
+
"text/plain": [
|
| 835 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 836 |
+
]
|
| 837 |
+
},
|
| 838 |
+
"metadata": {},
|
| 839 |
+
"output_type": "display_data"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"data": {
|
| 843 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 844 |
+
"model_id": "b68e30bbce624b20a1f83c037e9b8681",
|
| 845 |
+
"version_major": 2,
|
| 846 |
+
"version_minor": 0
|
| 847 |
+
},
|
| 848 |
+
"text/plain": [
|
| 849 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 850 |
+
]
|
| 851 |
+
},
|
| 852 |
+
"metadata": {},
|
| 853 |
+
"output_type": "display_data"
|
| 854 |
+
},
|
| 855 |
+
{
|
| 856 |
+
"data": {
|
| 857 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 858 |
+
"model_id": "4ec3e04a59d94d54b34517a3bd5de1dc",
|
| 859 |
+
"version_major": 2,
|
| 860 |
+
"version_minor": 0
|
| 861 |
+
},
|
| 862 |
+
"text/plain": [
|
| 863 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 864 |
+
]
|
| 865 |
+
},
|
| 866 |
+
"metadata": {},
|
| 867 |
+
"output_type": "display_data"
|
| 868 |
+
},
|
| 869 |
+
{
|
| 870 |
+
"data": {
|
| 871 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 872 |
+
"model_id": "8fc2181ab29e41b8b49e5e527f75b09e",
|
| 873 |
+
"version_major": 2,
|
| 874 |
+
"version_minor": 0
|
| 875 |
+
},
|
| 876 |
+
"text/plain": [
|
| 877 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 878 |
+
]
|
| 879 |
+
},
|
| 880 |
+
"metadata": {},
|
| 881 |
+
"output_type": "display_data"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"data": {
|
| 885 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 886 |
+
"model_id": "566f002d194246a082f2216fc4ba53d6",
|
| 887 |
+
"version_major": 2,
|
| 888 |
+
"version_minor": 0
|
| 889 |
+
},
|
| 890 |
+
"text/plain": [
|
| 891 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 892 |
+
]
|
| 893 |
+
},
|
| 894 |
+
"metadata": {},
|
| 895 |
+
"output_type": "display_data"
|
| 896 |
+
},
|
| 897 |
+
{
|
| 898 |
+
"data": {
|
| 899 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 900 |
+
"model_id": "4e283eaffd8d428c860d6264bcbd3cc9",
|
| 901 |
+
"version_major": 2,
|
| 902 |
+
"version_minor": 0
|
| 903 |
+
},
|
| 904 |
+
"text/plain": [
|
| 905 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 906 |
+
]
|
| 907 |
+
},
|
| 908 |
+
"metadata": {},
|
| 909 |
+
"output_type": "display_data"
|
| 910 |
+
},
|
| 911 |
+
{
|
| 912 |
+
"data": {
|
| 913 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 914 |
+
"model_id": "2050cda0af144794a2dc417c648a23bd",
|
| 915 |
+
"version_major": 2,
|
| 916 |
+
"version_minor": 0
|
| 917 |
+
},
|
| 918 |
+
"text/plain": [
|
| 919 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 920 |
+
]
|
| 921 |
+
},
|
| 922 |
+
"metadata": {},
|
| 923 |
+
"output_type": "display_data"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"data": {
|
| 927 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 928 |
+
"model_id": "6ad38712f3fd44ee9245d5869cf45c0e",
|
| 929 |
+
"version_major": 2,
|
| 930 |
+
"version_minor": 0
|
| 931 |
+
},
|
| 932 |
+
"text/plain": [
|
| 933 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 934 |
+
]
|
| 935 |
+
},
|
| 936 |
+
"metadata": {},
|
| 937 |
+
"output_type": "display_data"
|
| 938 |
+
},
|
| 939 |
+
{
|
| 940 |
+
"data": {
|
| 941 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 942 |
+
"model_id": "e23b74600bf3483da0ee0739f2eb4243",
|
| 943 |
+
"version_major": 2,
|
| 944 |
+
"version_minor": 0
|
| 945 |
+
},
|
| 946 |
+
"text/plain": [
|
| 947 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 948 |
+
]
|
| 949 |
+
},
|
| 950 |
+
"metadata": {},
|
| 951 |
+
"output_type": "display_data"
|
| 952 |
+
},
|
| 953 |
+
{
|
| 954 |
+
"data": {
|
| 955 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 956 |
+
"model_id": "c08764520d8b46f1a4a253717ab08807",
|
| 957 |
+
"version_major": 2,
|
| 958 |
+
"version_minor": 0
|
| 959 |
+
},
|
| 960 |
+
"text/plain": [
|
| 961 |
+
"Generating train split: 0 examples [00:00, ? examples/s]"
|
| 962 |
+
]
|
| 963 |
+
},
|
| 964 |
+
"metadata": {},
|
| 965 |
+
"output_type": "display_data"
|
| 966 |
+
}
|
| 967 |
+
],
|
| 968 |
+
"source": [
|
| 969 |
+
"eurlex_test = load_data_by_name(\"Eurlex-4.3K\", split=\"test\")\n",
|
| 970 |
+
"df_eurlex_test = eurlex_test.to_pandas()\n",
|
| 971 |
+
"df_eurlex_test_narrow = df_eurlex_test[df_eurlex_test[\"num_keyphrases\"] <= 2*15]\n",
|
| 972 |
+
"df_eurlex_test_diverse = df_eurlex_test[df_eurlex_test[\"num_keyphrases\"] > 2*15]"
|
| 973 |
+
]
|
| 974 |
+
},
|
| 975 |
+
{
|
| 976 |
+
"cell_type": "code",
|
| 977 |
+
"execution_count": 17,
|
| 978 |
+
"id": "16165803-a38b-434b-baf4-ac4b7d5a0eb5",
|
| 979 |
+
"metadata": {},
|
| 980 |
+
"outputs": [
|
| 981 |
+
{
|
| 982 |
+
"data": {
|
| 983 |
+
"text/plain": [
|
| 984 |
+
"10000"
|
| 985 |
+
]
|
| 986 |
+
},
|
| 987 |
+
"execution_count": 17,
|
| 988 |
+
"metadata": {},
|
| 989 |
+
"output_type": "execute_result"
|
| 990 |
+
}
|
| 991 |
+
],
|
| 992 |
+
"source": [
|
| 993 |
+
"def return_eval(pred2score, target2score, mean):\n",
|
| 994 |
+
" mean2 = 2 * mean\n",
|
| 995 |
+
" pred = [p.lower() for p in pred2score]\n",
|
| 996 |
+
" target = [p.lower() for p in target2score]\n",
|
| 997 |
+
" o = len(set(target))\n",
|
| 998 |
+
"\n",
|
| 999 |
+
" intersect = len(set(pred[:o]).intersection(set(target)))\n",
|
| 1000 |
+
" budgetaccone = len(set(pred[:mean]).intersection(set(target)))/mean\n",
|
| 1001 |
+
" budgetacctwo = len(set(pred[:mean2]).intersection(set(target)))/mean2\n",
|
| 1002 |
+
" prec = intersect/len(set(pred[:o])) if len(pred) > 0 else 0.0\n",
|
| 1003 |
+
" rec = intersect/len(target)\n",
|
| 1004 |
+
"\n",
|
| 1005 |
+
" \n",
|
| 1006 |
+
" kmean = len(set(pred[:mean]))\n",
|
| 1007 |
+
" k2mean = len(set(pred[:mean2]))\n",
|
| 1008 |
+
"\n",
|
| 1009 |
+
" if prec==0 and rec==0:\n",
|
| 1010 |
+
" f1=0\n",
|
| 1011 |
+
" else:\n",
|
| 1012 |
+
" f1 = 2*prec*rec/(prec+rec)\n",
|
| 1013 |
+
" \n",
|
| 1014 |
+
" return {\"P@O\":100*prec, \"R@O\": 100*rec, \"F1@O\":100*f1, \"B@mean\": budgetaccone, \"B@2mean\": budgetacctwo, \"#k@mean\": kmean, \"#k@2mean\": k2mean}\n",
|
| 1015 |
+
"\n",
|
| 1016 |
+
"def final_metric_results(preds_keyphrases, labels_keyphrases, mean):\n",
|
| 1017 |
+
" avg_scores = defaultdict(list)\n",
|
| 1018 |
+
" for pred, target in zip(preds_keyphrases, labels_keyphrases):\n",
|
| 1019 |
+
"\n",
|
| 1020 |
+
" all_exact_results = return_eval(pred, target, mean)\n",
|
| 1021 |
+
" \n",
|
| 1022 |
+
" for m_name, value in all_exact_results.items():\n",
|
| 1023 |
+
" avg_scores[m_name].append(value)\n",
|
| 1024 |
+
"\n",
|
| 1025 |
+
" avg_scores[\"pred_kpnum\"].append(len(set(pred)))\n",
|
| 1026 |
+
" avg_scores[\"gt_kpnum\"].append(len(set(target)))\n",
|
| 1027 |
+
" \n",
|
| 1028 |
+
" avg_scores = {m_name: round(np.mean(values),2) for m_name, values in avg_scores.items()}\n",
|
| 1029 |
+
"\n",
|
| 1030 |
+
" return avg_scores\n",
|
| 1031 |
+
" \n",
|
| 1032 |
+
"def generate_results(df, mean):\n",
|
| 1033 |
+
" \n",
|
| 1034 |
+
" labels_keyphrases = [p.lower().split(\";\") for p in df[\"target\"]]\n",
|
| 1035 |
+
" preds_keyphrases = []\n",
|
| 1036 |
+
" for i in range(len(df)):\n",
|
| 1037 |
+
" # preds_keyphrases.append(post_process(df.iloc[i][\"keyword\"])[:k])\n",
|
| 1038 |
+
" preds_keyphrases.append(post_process(df.iloc[i][\"keyword\"]))\n",
|
| 1039 |
+
" \n",
|
| 1040 |
+
" print(\"@\",mean) \n",
|
| 1041 |
+
" return final_metric_results(preds_keyphrases, labels_keyphrases, mean)"
|
| 1042 |
+
]
|
| 1043 |
+
},
|
| 1044 |
+
{
|
| 1045 |
+
"cell_type": "code",
|
| 1046 |
+
"execution_count": 18,
|
| 1047 |
+
"id": "2a99636a-3950-495a-bf1b-68344e994088",
|
| 1048 |
+
"metadata": {},
|
| 1049 |
+
"outputs": [
|
| 1050 |
+
{
|
| 1051 |
+
"data": {
|
| 1052 |
+
"text/plain": [
|
| 1053 |
+
"4313"
|
| 1054 |
+
]
|
| 1055 |
+
},
|
| 1056 |
+
"execution_count": 18,
|
| 1057 |
+
"metadata": {},
|
| 1058 |
+
"output_type": "execute_result"
|
| 1059 |
+
}
|
| 1060 |
+
],
|
| 1061 |
+
"source": [
|
| 1062 |
+
"return_eval()"
|
| 1063 |
+
]
|
| 1064 |
+
},
|
| 1065 |
+
{
|
| 1066 |
+
"cell_type": "code",
|
| 1067 |
+
"execution_count": null,
|
| 1068 |
+
"id": "2ac7d00a-da2c-4e23-a384-c197c99b11bb",
|
| 1069 |
+
"metadata": {},
|
| 1070 |
+
"outputs": [],
|
| 1071 |
+
"source": []
|
| 1072 |
+
}
|
| 1073 |
+
],
|
| 1074 |
+
"metadata": {
|
| 1075 |
+
"kernelspec": {
|
| 1076 |
+
"display_name": "Python 3 (ipykernel)",
|
| 1077 |
+
"language": "python",
|
| 1078 |
+
"name": "python3"
|
| 1079 |
+
},
|
| 1080 |
+
"language_info": {
|
| 1081 |
+
"codemirror_mode": {
|
| 1082 |
+
"name": "ipython",
|
| 1083 |
+
"version": 3
|
| 1084 |
+
},
|
| 1085 |
+
"file_extension": ".py",
|
| 1086 |
+
"mimetype": "text/x-python",
|
| 1087 |
+
"name": "python",
|
| 1088 |
+
"nbconvert_exporter": "python",
|
| 1089 |
+
"pygments_lexer": "ipython3",
|
| 1090 |
+
"version": "3.10.12"
|
| 1091 |
+
}
|
| 1092 |
+
},
|
| 1093 |
+
"nbformat": 4,
|
| 1094 |
+
"nbformat_minor": 5
|
| 1095 |
+
}
|
evaluation.ipynb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 6,
|
| 6 |
+
"id": "b6948f5d-bf4b-4704-8249-0bfe965bcccc",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"def return_eval(pred2score, target2score, mean):\n",
|
| 11 |
+
" mean2 = 2 * mean\n",
|
| 12 |
+
" pred = [p.lower() for p in pred2score]\n",
|
| 13 |
+
" target = [p.lower() for p in target2score]\n",
|
| 14 |
+
" o = len(set(target))\n",
|
| 15 |
+
"\n",
|
| 16 |
+
" intersect = len(set(pred[:o]).intersection(set(target)))\n",
|
| 17 |
+
" budgetaccone = len(set(pred[:mean]).intersection(set(target)))/mean\n",
|
| 18 |
+
" budgetacctwo = len(set(pred[:mean2]).intersection(set(target)))/mean2\n",
|
| 19 |
+
" prec = intersect/len(set(pred[:o])) if len(pred) > 0 else 0.0\n",
|
| 20 |
+
" rec = intersect/len(target)\n",
|
| 21 |
+
"\n",
|
| 22 |
+
" \n",
|
| 23 |
+
" kmean = len(set(pred[:mean]))\n",
|
| 24 |
+
" k2mean = len(set(pred[:mean2]))\n",
|
| 25 |
+
"\n",
|
| 26 |
+
" if prec==0 and rec==0:\n",
|
| 27 |
+
" f1=0\n",
|
| 28 |
+
" else:\n",
|
| 29 |
+
" f1 = 2*prec*rec/(prec+rec)\n",
|
| 30 |
+
" \n",
|
| 31 |
+
" return {\"P@O\":100*prec, \"R@O\": 100*rec, \"F1@O\":100*f1, \"B@mean\": budgetaccone, \"B@2mean\": budgetacctwo, \"#k@mean\": kmean, \"#k@2mean\": k2mean}\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"def final_metric_results(preds_keyphrases, labels_keyphrases, mean):\n",
|
| 34 |
+
" avg_scores = defaultdict(list)\n",
|
| 35 |
+
" for pred, target in zip(preds_keyphrases, labels_keyphrases):\n",
|
| 36 |
+
"\n",
|
| 37 |
+
" all_exact_results = return_eval(pred, target, mean)\n",
|
| 38 |
+
" \n",
|
| 39 |
+
" for m_name, value in all_exact_results.items():\n",
|
| 40 |
+
" avg_scores[m_name].append(value)\n",
|
| 41 |
+
"\n",
|
| 42 |
+
" avg_scores[\"pred_kpnum\"].append(len(set(pred)))\n",
|
| 43 |
+
" avg_scores[\"gt_kpnum\"].append(len(set(target)))\n",
|
| 44 |
+
" \n",
|
| 45 |
+
" avg_scores = {m_name: round(np.mean(values),2) for m_name, values in avg_scores.items()}\n",
|
| 46 |
+
"\n",
|
| 47 |
+
" return avg_scores\n",
|
| 48 |
+
" \n",
|
| 49 |
+
"def generate_results(df, mean):\n",
|
| 50 |
+
" \n",
|
| 51 |
+
" labels_keyphrases = [p.lower().split(\";\") for p in df[\"target\"]]\n",
|
| 52 |
+
" preds_keyphrases = []\n",
|
| 53 |
+
" for i in range(len(df)):\n",
|
| 54 |
+
" # preds_keyphrases.append(post_process(df.iloc[i][\"keyword\"])[:k])\n",
|
| 55 |
+
" preds_keyphrases.append(post_process(df.iloc[i][\"keyword\"]))\n",
|
| 56 |
+
" \n",
|
| 57 |
+
" print(\"@\",mean) \n",
|
| 58 |
+
" return final_metric_results(preds_keyphrases, labels_keyphrases, mean)"
|
| 59 |
+
]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"cell_type": "code",
|
| 63 |
+
"execution_count": null,
|
| 64 |
+
"id": "761906b8-6c1d-4d48-adcf-20589d9a0385",
|
| 65 |
+
"metadata": {},
|
| 66 |
+
"outputs": [],
|
| 67 |
+
"source": []
|
| 68 |
+
}
|
| 69 |
+
],
|
| 70 |
+
"metadata": {
|
| 71 |
+
"kernelspec": {
|
| 72 |
+
"display_name": "Python 3 (ipykernel)",
|
| 73 |
+
"language": "python",
|
| 74 |
+
"name": "python3"
|
| 75 |
+
},
|
| 76 |
+
"language_info": {
|
| 77 |
+
"codemirror_mode": {
|
| 78 |
+
"name": "ipython",
|
| 79 |
+
"version": 3
|
| 80 |
+
},
|
| 81 |
+
"file_extension": ".py",
|
| 82 |
+
"mimetype": "text/x-python",
|
| 83 |
+
"name": "python",
|
| 84 |
+
"nbconvert_exporter": "python",
|
| 85 |
+
"pygments_lexer": "ipython3",
|
| 86 |
+
"version": "3.10.12"
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
"nbformat": 4,
|
| 90 |
+
"nbformat_minor": 5
|
| 91 |
+
}
|