1059 lines
260 KiB
Text
1059 lines
260 KiB
Text
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"id": "initial_id",
|
||
"metadata": {
|
||
"collapsed": true,
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:42.541639835Z",
|
||
"start_time": "2026-05-29T15:19:40.265547407Z"
|
||
}
|
||
},
|
||
"source": [
|
||
"import torch\n",
|
||
"from d2l import torch as d2l\n"
|
||
],
|
||
"outputs": [],
|
||
"execution_count": 2
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:42.593785744Z",
|
||
"start_time": "2026-05-29T15:19:42.545273168Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"def show_heatmaps(matrices,xlabel,ylabel,titles=None,figsize=(2.5,2.5),cmap='Reds'):\n",
|
||
" d2l.use_svg_display()\n",
|
||
" num_rows,num_cols = matrices.shape[0],matrices.shape[1]\n",
|
||
" fig,axes = d2l.plt.subplots(num_rows,num_cols,figsize=figsize,sharex=True,squeeze=False)\n",
|
||
" for i,(row_axes,row_matrices) in enumerate(zip(axes,matrices)):\n",
|
||
" for j,(ax,matrix) in enumerate(zip(row_axes,row_matrices)):\n",
|
||
" pcm = ax.imshow(matrix.detach().numpy(),cmap=cmap)\n",
|
||
" if i == num_rows - 1:\n",
|
||
" ax.set_xlabel(xlabel)\n",
|
||
" if j == 0:\n",
|
||
" ax.set_ylabel(ylabel)\n",
|
||
" if titles:\n",
|
||
" ax.set_title(titles[j])\n",
|
||
" fig.colorbar(pcm,ax=axes,shrink=0.6)"
|
||
],
|
||
"id": "a0e3f725b7764f08",
|
||
"outputs": [],
|
||
"execution_count": 3
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:42.832298248Z",
|
||
"start_time": "2026-05-29T15:19:42.594979091Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"attention_weights = torch.eye(10).reshape((1, 1, 10, 10))\n",
|
||
"\n",
|
||
"show_heatmaps(attention_weights, xlabel='Keys', ylabel='Queries')"
|
||
],
|
||
"id": "bb798de34fc4d0fa",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 250x250 with 2 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"193.43925pt\" height=\"156.35625pt\" viewBox=\"0 0 193.43925 156.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:42.792345</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M -0 156.35625 \nL 193.43925 156.35625 \nL 193.43925 0 \nL -0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 34.240625 118.8 \nL 145.840625 118.8 \nL 145.840625 7.2 \nL 34.240625 7.2 \nz\n\"/>\n </g>\n <g clip-path=\"url(#pfba67317e4)\">\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAJsAAACbCAYAAAB1YemMAAAB+ElEQVR4nO3csY3CQBBAUUBkXAn0ByVRIAWQEPtKuDOL/srye7nlDb4mGs1xeb+WA/zD/XId+v70pXfAn8RGRmxkxEZGbGTERkZsZMRGRmxkxEZGbGTERkZsZMRGRmxkzrMfQGtkJ+3xfg7922QjIzYyYiMjNjJiIyM2MmIjIzYyYiMjNjJiIyM2MmIjIzYyVow2ZvRs1eia0AiTjYzYyIiNjNjIiI2M2MiIjYzYyIiNjNjIiI2M2MiIjYzYyIiNjH22CWaerZrJZCMjNjJiIyM2MmIjIzYyYiMjNjJiIyM2MmIjIzYyYiMjNjJWjD6w5bNVM5lsZMRGRmxkxEZGbGTERkZsZMRGRmxkxEZGbGTERkZsZMRGRmxkdrvPttezVTOZbGTERkZsZMRGRmxkxEZGbGTERkZsZMRGRmxkxEZGbGTERmazK0bOVm2PyUZGbGTERkZsZMRGRmxkxEZGbGTERkZsZMRGRmxkxEZGbGTERmbqPpuzVftispERGxmxkREbGbGRERsZsZERGxmxkREbGbGRERsZsZERG5mhFSNnq1jDZCMjNjJiIyM2MmIjIzYyYiMjNjJiIyM2MmIjIzYyYiMjNjJiI3O8HX6WTz+2j8YaJhsZsZERGxmxkREbGbGRERsZsZERGxmxkREbGbGRERsZsZH5BQ6wIZohMfZYAAAAAElFTkSuQmCC\" id=\"image1909f28e1e\" transform=\"scale(1 -1) translate(0 -111.6)\" x=\"34.240625\" y=\"-7.2\" width=\"111.6\" height=\"111.6\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path id=\"m8989ca978a\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m8989ca978a\" x=\"39.820625\" y=\"118.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(36.639375 133.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use xlink:href=\"#m8989ca978a\" x=\"95.620625\" y=\"118.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(92.439375 133.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- Keys -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.371094 147.076563) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \nL 1259 4666 \nL 1259 2694 \nL 3353 4666 \nL 4166 4666 \nL 1850 2491 \nL 4331 0 \nL 3500 0 \nL 1259 2247 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-4b\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_3\">\n <defs>\n <path id=\"mc17b1648ba\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mc17b1648ba\" x=\"34.240625\" y=\"12.78\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 16.579219) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#mc17b1648ba\" x=\"34.240625\" y=\"35.1\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 38.899219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_5\">\n <g>\n <use xlink:href=\"#mc17b1648ba\" x=\"34.240625\" y=\"57.42\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 61.219219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#mc17b1648ba\" x=\"34.240625\" y=\"79.74\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 6 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 83.539219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-36\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_7\">\n <g>\n <use xlink:href=\"#mc17b1648ba\" x=\"34.240625\" y=\"102.06\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 8 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 105.859219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-38\"/>\n </g>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- Queries -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 82.307031) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \nQ 1834 4238 1429 3725 \nQ 1025 3213 1025 2328 \nQ 1025 1447 1429 934 \nQ 1834 422 2522 422 \nQ 3209 422 3611 934 \nQ 4013 1447 4013 2328 \nQ 4013 3213 3611 3725 \nQ 3209 4238 2522 4238 \nz\nM 3406 84 \nL 4238 -825 \nL 3475 -825 \nL 2784 -78 \nQ 2681 -84 2626 -87 \nQ 2572 -91 2522 -91 \nQ 1538 -91 948 567 \nQ 359 1225 359 2328 \nQ 359 3434 948 4092 \nQ 1538 4750 2522 4750 \nQ 3503 4750 4090 4092 \nQ 4678 3434 4678 2328 \nQ 4678 1516 4351 937 \nQ 4025 359 3406 84 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-51\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 34.240625 118.8 \nL 34.240625 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 145.840625 118.8 \nL 145.840625 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 34.240625 118.8 \nL 145.840625 118.8 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 34.240625 7.2 \nL 145.840625 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n <g id=\"axes_2\">\n <g id=\"patch_7\">\n <path d=\"M 152.815625 104.58 \nL 156.973625 104.58 \nL 156.973625 21.42 \nL 152.815625 21.42 \nz\n\"/>\n </g>\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAYAAABzCAYAAAC7I3M6AAAAv0lEQVR4nNWVQQrDQAwDXfD/v9pLT1l71Q/sBBQMpTmukMbWhuSlz1txeDK0T+d3wrYFmyFm9BTjZsFjVY/g6GgSyKFaLsOHt82gKPlT+QvaJUbVWNS/waldjqKXGh24oB9lO/RL+AOBGGoSFjLsqDm4mj6W/lSFDDcK4ZvGbXTQ36BJQAa0Hlk2nAWCF081xsBKWiQcjyNykwM6jCx0nM8jO2wH74GbQ5S/IMIXMbASnAodFwllR/mOy76Puam+t3oOUronbv0AAAAASUVORK5CYII=\" id=\"image82b8e60cff\" transform=\"scale(1 -1) translate(0 -82.8)\" x=\"152.64\" y=\"-21.6\" width=\"4.32\" height=\"82.8\"/>\n <g id=\"matplotlib.axis_3\"/>\n <g id=\"matplotlib.axis_4\">\n <g id=\"ytick_6\">\n <g id=\"line2d_8\">\n <defs>\n <path id=\"m5755c5adc8\" d=\"M 0 0 \nL 3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m5755c5adc8\" x=\"156.973625\" y=\"104.58\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 0.00 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 108.379219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_9\">\n <g>\n <use xlink:href=\"#m5755c5adc8\" x=\"156.973625\" y=\"83.79\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 0.25 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 87.589219) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_8\">\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#m5755c5adc8\" x=\"156.973625\" y=\"63\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 0.50 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 66.799219) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_9\">\n <g id=\"line2d_11\">\n <g>\n <use xlink:href=\"#m5755c5adc8\" x=\"156.973625\" y=\"42.21\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 0.75 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 46.009219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-37\" d=\"M 525 4666 \nL 3525 4666 \nL 3525 4397 \nL 1831 0 \nL 1172 0 \nL 2766 4134 \nL 525 4134 \nL 525 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-37\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_10\">\n <g id=\"line2d_12\">\n <g>\n <use xlink:href=\"#m5755c5adc8\" x=\"156.973625\" y=\"21.42\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_14\">\n <!-- 1.00 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 25.219219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"LineCollection_1\"/>\n <g id=\"patch_8\">\n <path d=\"M 152.815625 104.58 \nL 154.894625 104.58 \nL 156.973625 104.58 \nL 156.973625 21.42 \nL 154.894625 21.42 \nL 152.815625 21.42 \nL 152.815625 104.58 \nz\n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pfba67317e4\">\n <rect x=\"34.240625\" y=\"7.2\" width=\"111.6\" height=\"111.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 4
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:42.925242334Z",
|
||
"start_time": "2026-05-29T15:19:42.844425757Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"n_train = 50\n",
|
||
"x_train,_ = torch.sort(torch.rand(n_train)*5)"
|
||
],
|
||
"id": "a4070c75847fb887",
|
||
"outputs": [],
|
||
"execution_count": 5
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:42.978395734Z",
|
||
"start_time": "2026-05-29T15:19:42.926738710Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"def f(x):\n",
|
||
" return 2*torch.sin(x)+x**0.8"
|
||
],
|
||
"id": "2aca6952876d9cf5",
|
||
"outputs": [],
|
||
"execution_count": 6
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.056742866Z",
|
||
"start_time": "2026-05-29T15:19:42.982949395Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"y_train = f(x_train)+torch.normal(0.0,0.5,(n_train,))\n",
|
||
"x_test = torch.arange(0,5,0.1)\n",
|
||
"y_truth = f(x_test)\n",
|
||
"n_test = len(x_test)\n",
|
||
"n_test"
|
||
],
|
||
"id": "ea7b94585dcde934",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"50"
|
||
]
|
||
},
|
||
"execution_count": 7,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 7
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.117629637Z",
|
||
"start_time": "2026-05-29T15:19:43.058324467Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"def plot_kernel_reg(y_hat):\n",
|
||
" d2l.plot(x_test, [y_truth, y_hat], 'x', 'y', legend=['Truth', 'Pred'],\n",
|
||
" xlim=[0, 5], ylim=[-1, 5])\n",
|
||
" d2l.plt.plot(x_train, y_train, 'o', alpha=0.5);"
|
||
],
|
||
"id": "35c2403bbb5509cf",
|
||
"outputs": [],
|
||
"execution_count": 8
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.224202029Z",
|
||
"start_time": "2026-05-29T15:19:43.119223163Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"y_hat = torch.repeat_interleave(y_train.mean(),n_test)\n",
|
||
"plot_kernel_reg(y_hat)"
|
||
],
|
||
"id": "f27ecb9c68aed894",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 350x250 with 1 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"187.155469pt\" viewBox=\"0 0 248.301563 187.155469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:43.188981</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 187.155469 \nL 248.301563 187.155469 \nL 248.301563 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \nL 237.920313 10.999219 \nL 42.620312 10.999219 \nz\n\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path id=\"m987bebe234\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(39.439062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path d=\"M 81.680312 149.599219 \nL 81.680312 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"81.680312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.499062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path d=\"M 120.740313 149.599219 \nL 120.740313 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"120.740313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(117.559062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path d=\"M 159.800313 149.599219 \nL 159.800313 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"159.800313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(156.619063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path d=\"M 198.860313 149.599219 \nL 198.860313 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"198.860313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(195.679063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_6\">\n <g id=\"line2d_11\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_12\">\n <g>\n <use xlink:href=\"#m987bebe234\" x=\"237.920313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(234.739063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- x -->\n <g style=\"fill: #ffffff\" transform=\"translate(137.310937 177.875781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-78\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_13\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_14\">\n <defs>\n <path id=\"m76165e2f31\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- −1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 153.398437) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-2212\"/>\n <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_15\">\n <path d=\"M 42.620312 126.499219 \nL 237.920313 126.499219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"126.499219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 130.298437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_17\">\n <path d=\"M 42.620312 103.399219 \nL 237.920313 103.399219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"103.399219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 107.198437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_19\">\n <path d=\"M 42.620312 80.299219 \nL 237.920313 80.299219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_20\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"80.299219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 84.098437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_21\">\n <path d=\"M 42.620312 57.199219 \nL 237.920313 57.199219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_22\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"57.199219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 60.998437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_6\">\n <g id=\"line2d_23\">\n <path d=\"M 42.620312 34.099219 \nL 237.920313 34.099219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_24\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"34.099219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 37.898438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_25\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_26\">\n <g>\n <use xlink:href=\"#m76165e2f31\" x=\"42.620312\" y=\"10.999219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_14\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 14.798437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_15\">\n <!-- y -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 83.258594) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-79\"/>\n </g>\n </g>\n </g>\n <g id=\"line2d_27\">\n <path d=\"M 42.620312 126.499219 \nL 46.526313 118.225812 \nL 50.432313 110.946345 \nL 54.338313 104.029425 \nL 58.244313 97.4097 \nL 62.150312 91.082293 \nL 66.056313 85.061866 \nL 69.962312 79.370737 \nL 73.868313 74.033949 \nL 77.774314 69.076775 \nL 81.680312 64.523261 \nL 85.586313 60.395214 \nL 89.492314 56.711598 \nL 93.398311 53.487961 \nL 97.304312 50.736132 \nL 101.210313 48.46391 \nL 105.116313 46.674891 \nL 109.022314 45.368338 \nL 112.928315 44.539111 \nL 116.834312 44.177706 \nL 120.740313 44.270242 \nL 124.646309 44.798618 \nL 128.552314 45.740654 \nL 132.458311 47.070245 \nL 136.364316 48.757689 \nL 140.270312 50.76986 \nL 144.176318 53.070611 \nL 148.082314 55.621064 \nL 151.98832 58.380042 \nL 155.894316 61.304393 \nL 159.800313 64.349483 \nL 163.706318 67.469619 \nL 167.612314 70.618454 \nL 171.518311 73.749494 \nL 175.424316 76.816549 \nL 179.330312 79.774142 \nL 183.236318 82.578044 \nL 187.142314 85.185605 \nL 191.048311 87.556281 \nL 194.954316 89.651973 \nL 198.860313 91.437389 \nL 202.766309 92.880457 \nL 206.672305 93.952601 \nL 210.57832 94.629017 \nL 214.484316 94.888934 \nL 218.390312 94.715829 \nL 222.296309 94.097555 \nL 226.202305 93.026506 \nL 230.10832 91.499643 \nL 234.014316 89.518571 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_28\">\n <path d=\"M 42.620312 75.75554 \nL 46.526313 75.75554 \nL 50.432313 75.75554 \nL 54.338313 75.75554 \nL 58.244313 75.75554 \nL 62.150312 75.75554 \nL 66.056313 75.75554 \nL 69.962312 75.75554 \nL 73.868313 75.75554 \nL 77.774314 75.75554 \nL 81.680312 75.75554 \nL 85.586313 75.75554 \nL 89.492314 75.75554 \nL 93.398311 75.75554 \nL 97.304312 75.75554 \nL 101.210313 75.75554 \nL 105.116313 75.75554 \nL 109.022314 75.75554 \nL 112.928315 75.75554 \nL 116.834312 75.75554 \nL 120.740313 75.75554 \nL 124.646309 75.75554 \nL 128.552314 75.75554 \nL 132.458311 75.75554 \nL 136.364316 75.75554 \nL 140.270312 75.75554 \nL 144.176318 75.75554 \nL 148.082314 75.75554 \nL 151.98832 75.75554 \nL 155.894316 75.75554 \nL 159.800313 75.75554 \nL 163.706318 75.75554 \nL 167.612314 75.75554 \nL 171.518311 75.75554 \nL 175.424316 75.75554 \nL 179.330312 75.75554 \nL 183.236318 75.75554 \nL 187.142314 75.75554 \nL 191.048311 75.75554 \nL 194.954316 75.75554 \nL 198.860313 75.75554 \nL 202.766309 75.75554 \nL 206.672305 75.75554 \nL 210.57832 75.75554 \nL 214.484316 75.75554 \nL 218.390312 75.75554 \nL 222.296309 75.75554 \nL 226.202305 75.75554 \nL 230.10832 75.75554 \nL 234.014316 75.75554 \n\" clip-path=\"url(#pd870bf6001)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"line2d_29\">\n <defs>\n <path id=\"mbefe54bf1d\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #feffb3; stroke-opacity: 0.5\"/>\n </defs>\n <g clip-path=\"url(#pd870bf6001)\">\n <use xlink:href=\"#mbefe54bf1d\" x=\"42.657342\" y=\"131.660222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"44.675703\" y=\"139.896089\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"51.855287\" y=\"118.429289\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"54.159045\" y=\"115.579943\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"55.326313\" y=\"105.400959\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"56.406136\" y=\"80.646272\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"56.83766\" y=\"104.882394\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"58.709219\" y=\"111.776797\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"65.568564\" y=\"85.512184\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"69.374217\" y=\"88.669352\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"71.016162\" y=\"79.61144\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"73.907617\" y=\"76.012711\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"78.84565\" y=\"80.675858\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"80.596239\" y=\"61.336688\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"88.147235\" y=\"70.985422\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"98.85527\" y=\"34.961782\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"100.382736\" y=\"40.731445\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"105.461658\" y=\"31.018935\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"109.596131\" y=\"38.510393\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"113.923449\" y=\"48.746884\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"116.643575\" y=\"42.636143\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"118.092844\" y=\"35.130222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"135.776419\" y=\"40.64603\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"137.078837\" y=\"33.64439\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"139.889426\" y=\"44.932482\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"141.994257\" y=\"73.442056\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"146.06478\" y=\"54.749326\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"153.43892\" y=\"51.831986\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"158.648284\" y=\"80.610407\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"165.201852\" y=\"77.170315\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"170.382431\" y=\"58.974783\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"174.452506\" y=\"84.573287\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"174.833132\" y=\"91.050581\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"178.946297\" y=\"56.271491\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"181.982698\" y=\"68.464549\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"182.384082\" y=\"93.021015\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"182.537526\" y=\"76.335311\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"193.579195\" y=\"76.817551\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"204.920897\" y=\"97.381441\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"214.149062\" y=\"79.999232\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"215.84437\" y=\"100.845345\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"216.101529\" y=\"79.141615\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"222.443877\" y=\"87.218974\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"222.684701\" y=\"85.093691\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"228.080867\" y=\"78.91387\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"228.265034\" y=\"87.556254\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"230.126312\" y=\"86.51374\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"230.632882\" y=\"66.206134\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"233.755183\" y=\"77.956022\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mbefe54bf1d\" x=\"234.184309\" y=\"75.603727\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"legend_1\">\n <g id=\"patch_7\">\n <path d=\"M 173.58125 48.355469 \nL 230.920313 48.355469 \nQ 232.920313 48.355469 232.920313 46.355469 \nL 232.920313 17.999219 \nQ 232.920313 15.999219 230.920313 15.999219 \nL 173.58125 15.999219 \nQ 171.58125 15.999219 171.58125 17.999219 \nL 171.58125 46.355469 \nQ 171.58125 48.355469 173.58125 48.355469 \nz\n\" style=\"opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n </g>\n <g id=\"line2d_30\">\n <path d=\"M 175.58125 24.097656 \nL 185.58125 24.097656 \nL 195.58125 24.097656 \n\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"text_16\">\n <!-- Truth -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 27.597656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-54\" d=\"M -19 4666 \nL 3928 4666 \nL 3928 4134 \nL 2272 4134 \nL 2272 0 \nL 1638 0 \nL 1638 4134 \nL -19 4134 \nL -19 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-54\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n </g>\n </g>\n <g id=\"line2d_31\">\n <path d=\"M 175.58125 38.775781 \nL 185.58125 38.775781 \nL 195.58125 38.775781 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"text_17\">\n <!-- Pred -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 42.275781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \nL 1259 2394 \nL 2053 2394 \nQ 2494 2394 2734 2622 \nQ 2975 2850 2975 3272 \nQ 2975 3691 2734 3919 \nQ 2494 4147 2053 4147 \nL 1259 4147 \nz\nM 628 4666 \nL 2053 4666 \nQ 2838 4666 3239 4311 \nQ 3641 3956 3641 3272 \nQ 3641 2581 3239 2228 \nQ 2838 1875 2053 1875 \nL 1259 1875 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n </g>\n </g>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pd870bf6001\">\n <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"138.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 9
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.317103476Z",
|
||
"start_time": "2026-05-29T15:19:43.225907041Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"from torch import nn\n",
|
||
"X_repeat = x_test.repeat_interleave(n_train).reshape((-1, n_train))\n",
|
||
"attention_weights = nn.functional.softmax(-(X_repeat - x_train)**2 / 2, dim=1)\n",
|
||
"y_hat = torch.matmul(attention_weights,y_train)\n",
|
||
"x_train,X_repeat,attention_weights"
|
||
],
|
||
"id": "fa7579d7cd8bfcb7",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(tensor([9.4801e-04, 5.2621e-02, 2.3643e-01, 2.9541e-01, 3.2529e-01, 3.5294e-01,\n",
|
||
" 3.6399e-01, 4.1190e-01, 5.8751e-01, 6.8494e-01, 7.2698e-01, 8.0101e-01,\n",
|
||
" 9.2743e-01, 9.7225e-01, 1.1656e+00, 1.4397e+00, 1.4788e+00, 1.6088e+00,\n",
|
||
" 1.7147e+00, 1.8255e+00, 1.8951e+00, 1.9322e+00, 2.3849e+00, 2.4183e+00,\n",
|
||
" 2.4902e+00, 2.5441e+00, 2.6483e+00, 2.8371e+00, 2.9705e+00, 3.1383e+00,\n",
|
||
" 3.2709e+00, 3.3751e+00, 3.3849e+00, 3.4902e+00, 3.5679e+00, 3.5782e+00,\n",
|
||
" 3.5821e+00, 3.8648e+00, 4.1552e+00, 4.3914e+00, 4.4348e+00, 4.4414e+00,\n",
|
||
" 4.6038e+00, 4.6099e+00, 4.7481e+00, 4.7528e+00, 4.8005e+00, 4.8134e+00,\n",
|
||
" 4.8934e+00, 4.9044e+00]),\n",
|
||
" tensor([[0.0000, 0.0000, 0.0000, ..., 0.0000, 0.0000, 0.0000],\n",
|
||
" [0.1000, 0.1000, 0.1000, ..., 0.1000, 0.1000, 0.1000],\n",
|
||
" [0.2000, 0.2000, 0.2000, ..., 0.2000, 0.2000, 0.2000],\n",
|
||
" ...,\n",
|
||
" [4.7000, 4.7000, 4.7000, ..., 4.7000, 4.7000, 4.7000],\n",
|
||
" [4.8000, 4.8000, 4.8000, ..., 4.8000, 4.8000, 4.8000],\n",
|
||
" [4.9000, 4.9000, 4.9000, ..., 4.9000, 4.9000, 4.9000]]),\n",
|
||
" tensor([[6.8662e-02, 6.8567e-02, 6.6769e-02, ..., 6.3916e-07, 4.3363e-07,\n",
|
||
" 4.1091e-07],\n",
|
||
" [6.4257e-02, 6.4501e-02, 6.3975e-02, ..., 9.6787e-07, 6.6191e-07,\n",
|
||
" 6.2792e-07],\n",
|
||
" [5.9935e-02, 6.0473e-02, 6.1093e-02, ..., 1.4608e-06, 1.0070e-06,\n",
|
||
" 9.5634e-07],\n",
|
||
" ...,\n",
|
||
" [9.4878e-07, 1.2079e-06, 2.7906e-06, ..., 5.8779e-02, 5.8062e-02,\n",
|
||
" 5.7935e-02],\n",
|
||
" [6.1962e-07, 7.9294e-07, 1.8658e-06, ..., 6.2113e-02, 6.1848e-02,\n",
|
||
" 6.1781e-02],\n",
|
||
" [4.0301e-07, 5.1842e-07, 1.2425e-06, ..., 6.5370e-02, 6.5614e-02,\n",
|
||
" 6.5615e-02]]))"
|
||
]
|
||
},
|
||
"execution_count": 10,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 10
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.435846223Z",
|
||
"start_time": "2026-05-29T15:19:43.319732830Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": "plot_kernel_reg(y_hat)",
|
||
"id": "f76573b2eb74ba7",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 350x250 with 1 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"187.155469pt\" viewBox=\"0 0 248.301563 187.155469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:43.394543</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 187.155469 \nL 248.301563 187.155469 \nL 248.301563 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \nL 237.920313 10.999219 \nL 42.620312 10.999219 \nz\n\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path id=\"mca27f47254\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(39.439062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path d=\"M 81.680312 149.599219 \nL 81.680312 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"81.680312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.499062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path d=\"M 120.740313 149.599219 \nL 120.740313 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"120.740313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(117.559062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path d=\"M 159.800313 149.599219 \nL 159.800313 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"159.800313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(156.619063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path d=\"M 198.860313 149.599219 \nL 198.860313 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"198.860313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(195.679063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_6\">\n <g id=\"line2d_11\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_12\">\n <g>\n <use xlink:href=\"#mca27f47254\" x=\"237.920313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(234.739063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- x -->\n <g style=\"fill: #ffffff\" transform=\"translate(137.310937 177.875781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-78\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_13\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_14\">\n <defs>\n <path id=\"m41e37907de\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- −1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 153.398437) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-2212\"/>\n <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_15\">\n <path d=\"M 42.620312 126.499219 \nL 237.920313 126.499219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"126.499219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 130.298437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_17\">\n <path d=\"M 42.620312 103.399219 \nL 237.920313 103.399219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"103.399219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 107.198437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_19\">\n <path d=\"M 42.620312 80.299219 \nL 237.920313 80.299219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_20\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"80.299219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 84.098437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_21\">\n <path d=\"M 42.620312 57.199219 \nL 237.920313 57.199219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_22\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"57.199219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 60.998437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_6\">\n <g id=\"line2d_23\">\n <path d=\"M 42.620312 34.099219 \nL 237.920313 34.099219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_24\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"34.099219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 37.898438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_25\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_26\">\n <g>\n <use xlink:href=\"#m41e37907de\" x=\"42.620312\" y=\"10.999219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_14\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 14.798437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_15\">\n <!-- y -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 83.258594) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-79\"/>\n </g>\n </g>\n </g>\n <g id=\"line2d_27\">\n <path d=\"M 42.620312 126.499219 \nL 46.526313 118.225812 \nL 50.432313 110.946345 \nL 54.338313 104.029425 \nL 58.244313 97.4097 \nL 62.150312 91.082293 \nL 66.056313 85.061866 \nL 69.962312 79.370737 \nL 73.868313 74.033949 \nL 77.774314 69.076775 \nL 81.680312 64.523261 \nL 85.586313 60.395214 \nL 89.492314 56.711598 \nL 93.398311 53.487961 \nL 97.304312 50.736132 \nL 101.210313 48.46391 \nL 105.116313 46.674891 \nL 109.022314 45.368338 \nL 112.928315 44.539111 \nL 116.834312 44.177706 \nL 120.740313 44.270242 \nL 124.646309 44.798618 \nL 128.552314 45.740654 \nL 132.458311 47.070245 \nL 136.364316 48.757689 \nL 140.270312 50.76986 \nL 144.176318 53.070611 \nL 148.082314 55.621064 \nL 151.98832 58.380042 \nL 155.894316 61.304393 \nL 159.800313 64.349483 \nL 163.706318 67.469619 \nL 167.612314 70.618454 \nL 171.518311 73.749494 \nL 175.424316 76.816549 \nL 179.330312 79.774142 \nL 183.236318 82.578044 \nL 187.142314 85.185605 \nL 191.048311 87.556281 \nL 194.954316 89.651973 \nL 198.860313 91.437389 \nL 202.766309 92.880457 \nL 206.672305 93.952601 \nL 210.57832 94.629017 \nL 214.484316 94.888934 \nL 218.390312 94.715829 \nL 222.296309 94.097555 \nL 226.202305 93.026506 \nL 230.10832 91.499643 \nL 234.014316 89.518571 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_28\">\n <path d=\"M 42.620312 91.911585 \nL 46.526313 90.441176 \nL 50.432313 88.905308 \nL 54.338313 87.305116 \nL 58.244313 85.643193 \nL 62.150312 83.923907 \nL 66.056313 82.153683 \nL 69.962312 80.341312 \nL 73.868313 78.498199 \nL 77.774314 76.63858 \nL 81.680312 74.779556 \nL 85.586313 72.941097 \nL 89.492314 71.145761 \nL 93.398311 69.418217 \nL 97.304312 67.784613 \nL 101.210313 66.27164 \nL 105.116313 64.905396 \nL 109.022314 63.710187 \nL 112.928315 62.70725 \nL 116.834312 61.913568 \nL 120.740313 61.340847 \nL 124.646309 60.994823 \nL 128.552314 60.874959 \nL 132.458311 60.974479 \nL 136.364316 61.280804 \nL 140.270312 61.776438 \nL 144.176318 62.439917 \nL 148.082314 63.24696 \nL 151.98832 64.171708 \nL 155.894316 65.187836 \nL 159.800313 66.269492 \nL 163.706318 67.392184 \nL 167.612314 68.533326 \nL 171.518311 69.672744 \nL 175.424316 70.792875 \nL 179.330312 71.878926 \nL 183.236318 72.918869 \nL 187.142314 73.903285 \nL 191.048311 74.825268 \nL 194.954316 75.680192 \nL 198.860313 76.465436 \nL 202.766309 77.180141 \nL 206.672305 77.824911 \nL 210.57832 78.401565 \nL 214.484316 78.912901 \nL 218.390312 79.362365 \nL 222.296309 79.753941 \nL 226.202305 80.091912 \nL 230.10832 80.380691 \nL 234.014316 80.62471 \n\" clip-path=\"url(#pa9d008eb08)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"line2d_29\">\n <defs>\n <path id=\"m1a2194a0a5\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #feffb3; stroke-opacity: 0.5\"/>\n </defs>\n <g clip-path=\"url(#pa9d008eb08)\">\n <use xlink:href=\"#m1a2194a0a5\" x=\"42.657342\" y=\"131.660222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"44.675703\" y=\"139.896089\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"51.855287\" y=\"118.429289\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"54.159045\" y=\"115.579943\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"55.326313\" y=\"105.400959\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"56.406136\" y=\"80.646272\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"56.83766\" y=\"104.882394\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"58.709219\" y=\"111.776797\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"65.568564\" y=\"85.512184\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"69.374217\" y=\"88.669352\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"71.016162\" y=\"79.61144\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"73.907617\" y=\"76.012711\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"78.84565\" y=\"80.675858\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"80.596239\" y=\"61.336688\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"88.147235\" y=\"70.985422\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"98.85527\" y=\"34.961782\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"100.382736\" y=\"40.731445\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"105.461658\" y=\"31.018935\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"109.596131\" y=\"38.510393\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"113.923449\" y=\"48.746884\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"116.643575\" y=\"42.636143\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"118.092844\" y=\"35.130222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"135.776419\" y=\"40.64603\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"137.078837\" y=\"33.64439\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"139.889426\" y=\"44.932482\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"141.994257\" y=\"73.442056\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"146.06478\" y=\"54.749326\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"153.43892\" y=\"51.831986\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"158.648284\" y=\"80.610407\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"165.201852\" y=\"77.170315\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"170.382431\" y=\"58.974783\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"174.452506\" y=\"84.573287\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"174.833132\" y=\"91.050581\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"178.946297\" y=\"56.271491\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"181.982698\" y=\"68.464549\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"182.384082\" y=\"93.021015\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"182.537526\" y=\"76.335311\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"193.579195\" y=\"76.817551\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"204.920897\" y=\"97.381441\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"214.149062\" y=\"79.999232\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"215.84437\" y=\"100.845345\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"216.101529\" y=\"79.141615\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"222.443877\" y=\"87.218974\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"222.684701\" y=\"85.093691\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"228.080867\" y=\"78.91387\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"228.265034\" y=\"87.556254\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"230.126312\" y=\"86.51374\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"230.632882\" y=\"66.206134\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"233.755183\" y=\"77.956022\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#m1a2194a0a5\" x=\"234.184309\" y=\"75.603727\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"legend_1\">\n <g id=\"patch_7\">\n <path d=\"M 173.58125 48.355469 \nL 230.920313 48.355469 \nQ 232.920313 48.355469 232.920313 46.355469 \nL 232.920313 17.999219 \nQ 232.920313 15.999219 230.920313 15.999219 \nL 173.58125 15.999219 \nQ 171.58125 15.999219 171.58125 17.999219 \nL 171.58125 46.355469 \nQ 171.58125 48.355469 173.58125 48.355469 \nz\n\" style=\"opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n </g>\n <g id=\"line2d_30\">\n <path d=\"M 175.58125 24.097656 \nL 185.58125 24.097656 \nL 195.58125 24.097656 \n\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"text_16\">\n <!-- Truth -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 27.597656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-54\" d=\"M -19 4666 \nL 3928 4666 \nL 3928 4134 \nL 2272 4134 \nL 2272 0 \nL 1638 0 \nL 1638 4134 \nL -19 4134 \nL -19 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-54\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n </g>\n </g>\n <g id=\"line2d_31\">\n <path d=\"M 175.58125 38.775781 \nL 185.58125 38.775781 \nL 195.58125 38.775781 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"text_17\">\n <!-- Pred -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 42.275781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \nL 1259 2394 \nL 2053 2394 \nQ 2494 2394 2734 2622 \nQ 2975 2850 2975 3272 \nQ 2975 3691 2734 3919 \nQ 2494 4147 2053 4147 \nL 1259 4147 \nz\nM 628 4666 \nL 2053 4666 \nQ 2838 4666 3239 4311 \nQ 3641 3956 3641 3272 \nQ 3641 2581 3239 2228 \nQ 2838 1875 2053 1875 \nL 1259 1875 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n </g>\n </g>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pa9d008eb08\">\n <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"138.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 11
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.558539946Z",
|
||
"start_time": "2026-05-29T15:19:43.438360863Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"d2l.show_heatmaps(attention_weights.unsqueeze(0).unsqueeze(0),\n",
|
||
" xlabel='Sorted training inputs',\n",
|
||
" ylabel='Sorted testing inputs')"
|
||
],
|
||
"id": "1bbe3af9e8a0f412",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 250x250 with 2 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"199.80175pt\" height=\"159.039469pt\" viewBox=\"0 0 199.80175 159.039469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:43.512317</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 159.039469 \nL 199.80175 159.039469 \nL 199.80175 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 40.603125 121.483219 \nL 152.203125 121.483219 \nL 152.203125 9.883219 \nL 40.603125 9.883219 \nz\n\"/>\n </g>\n <g clip-path=\"url(#pbcbc2e6914)\">\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAJsAAACbCAYAAAB1YemMAAASmElEQVR4nO2dW3MbuRGFMRdeRFLy7v7/P5TKU35AHrYqVXlI1muLosTLDCcPSoyvIZzxUFJA2dXnCRpiZkQZxkF3n+6uht2XIfxkGAbxldR14rTPzx/O+XEIIfR9HB8e47Snhzj++u84x4w/x/EZ7/vyR7x3e485ybuB41/+9m3897/+I4638Tsd8Z34d/rnEd8B2Pbxfembz+LPeQ75D+r8dIfj/eGLzVEM7bV/getBUS3pEnPOff568tnQd/E6KXm/i+Onx/wYdDw8Yv4j5rx4d/x9+6fjt3HXx3ncUdoKjwrxh7s2v+/M6yp7fQxqB/OdzVEMvtgcxfDD0qi0OF9O5A/iOqDo8jxmjYI6j5E6h8NTvL4HFT5GKzXsMOb7dpfT6PnphMtxXlNFKiQp8kmbJr/vrGv9d66qPMW2gnl9Z3MUgy82RzH8sDQ6iinUqeacJ1ij58QB2kf6CqROjp9Ii3D20urk+0idYzTKX2N/yk6bge7MAQB0Vw+XUeLz7Xl65vvItL6zOYrBF5ujGH4eGn0LdUq6PIvrsD5DCMPpEMf7PF0G0iUt0N33afT8KOK1IYQBVudRxDdnxmrMU+pC0CWduumUWli5cziIabH6zuYoBl9sjmLwxeYohh/qzDbI89eLiWIs3Bo8vzEawPm4PnRwdYRgXRwm4J4/pw0TogPDY3xmv4tnQikiCyF0XfyMx7TFhGD6TEQDlosGz7RzmrbKfraY4x5sZ76zOYrBF5ujGH4oGrWYSKPSDSIoFdGAga4PuDdCQqMy4L7bxjkYT4kO9LuoTTuDRscECB0k3IbWmrwrglgum+z19Xom3zcTNMpnuevDcRX4YnMUw4en0ddlSonAutGq5Wl0OEX6MnRJiTfnhBDCIynyIT9+yEcNzrtIwYwG9Lv4Psq9X5weeA+s0aaJ9NXCo18Ly3S1inRJpr3daBqtF7wn3tRsFpjkNOq4AnyxOYrhQ9LoJOoco1El4R4UpeJeOmWZ7USLs4NlGoK1QB9ggWJM6hx2cX7/kLc0z6DOM3RqqVOX93A8m8V9hI7ZuslbkKRL0ujs13X8IaHgeo7lA4u3WUcarZxGHdeALzZHMXwYGp2WLSWctc8PwFjp0IRWDfMtXQq5Ny3TEELYoRbHA8aMgWJM6uwfkmf97/pjpNETdGrDSGyUH81Bo6tV/GduRDLy7NdV9nr72+bbOPUH10tYqtS2bdbZ676zOYrBF5ujGIrT6CS6nGKNvigdNYFGe0GpnE8HLeVGJmsqoT5aoJR8b+N1Om/psGViMf82pM6TkHunoLE4hwW6XM/jnHn+n3z2yzp7vf3tVr9wHp8bGsRWV6Bkp1HHNeCLzVEMRWh0cl2O/N18EMYJjU7JkGIysaJRVIsMHWiUqttj4tSlfGibd+R2qP5I5W2/j1Ynv0J3ir8Ty1+NgXFPOnLbTzdxjqDR9pc89YW7u/z1ECyN1ti31pGSXWLkuAp8sTmK4bpOXUmvE6gzrbdh1La0QE/ZsUla4bNIiZzDCpF7WKYhKbAMKVG/RaIxqJOxzuMxX5C57xnzxLtGjiQtHLnzm+hwbe8iRVYmGQW0+OlT/qHqegihktboBpMgb5JPcjjeGb7YHMXwf6PRyxW2E+pzKIsz/YzOWFChUeGiQqShWsqCOB/W6LBPnLpbyooQA6UFiljncR9/vx5JKuYrnEmj06zRGeKe7e0yjmlpzhDPpAVJqxOo7jSNhnl8h/EoGxp1a9RxBfhicxTDJBp9m1M26DxONWdKL4I+pdG885blrIwKl4WW6bzdfsW9pFHGRhOnrrFAQZ2QD7EqZNdd5rBVuZ4pFnDkNnfRkRtuEd+kBUlZkKDRcAsaTX+PmbBGb1xi5LgyfLE5isEXm6MY5Jntzec0+zQ+WL0wjo1WTZ3ZkrJVlHbznMaWjDyzCfm3yYg64sxGd0fi+qC7o9tCt0Z3BzRpqiA5weNRM7F/VHsTz1Atz2w8j/HMRpizWZ2/nmKOZGTes4SrpfYIguMK8MXmKIbLIwivoddLK3ZL14fQpoWkvBXokt2MTRaUoVG4Pu7v89dR2mo42Fof3X181hmlrk4HRgpQkwPRAeXVIHU2IrH4xT2osVHdIiuKNDrLuz4kXa7hNqmSvUk9a4HAv7s+HNeALzZHMbSvK0ml8IbogLI6DY2iiPIxCYaD8gbVbpGUSn0arU7KuvHM/hE1OQ626QYjBR27GUParahTWZosc8W6HWPBhGaDwDijBhtQpIggSLpcichCCKEyNIp7hJXqO5ujGHyxOYphojU6kVIlJasSVhMk33wkZdp00IaQWI6sBAnrEkF2Q6MIuPf3sGQRMD+DRs/HlEbjZ3Tenrq8Vm2KpcmgOis8pmWriOaTcOTeCmuUWAs92zKfvPziWU6jjo8EX2yOYrA0OsXhKue/+BBDUuSEqpB9PoF46JDQSyszBOvkJY0y1sksKMq8T/HeHg7aAZJtUwkyqb1hLFAUUeafh4Zfi/4Bc2Y7sesw4pz1Tb5Q8vOHLFUFR+4GtLj5Po1WN5vsdaNNS9Fg+YAuqzZf9Nl3Nkcx+GJzFEP7pg7EY1AxTVVjw8zp8vMZz3xKaJQSblqdlHnff8H9rCQJGoWDdoBT9nzAnJ4SKJto3IvKkG2Tp07KggjGOZsVrbsRry4dubRAV7hOijOyoDxdVsygSlFDCm7OAHknh+9sjmLwxeYohlbHM5XzdSqNKlpU1Am6pNUppENGLhSCpFFDnZQPSRqF8xaUeGKcM6HRztTliGOWsGKss0Hh4xpVIU1LntvooG1WLE1ladRYpyYemqfRqhF+/AUcwqTXJl+k+cU8Q6N5evWdzVEMvtgcxdBKilRJJ5MpVSlsJ/Rgp3yI0iFaoLQ4QzBUKKmT8iEkrQzHeO/hwMQUqGuF0jYES52kNdbemC/RiwCWZntL+gLtolaHKoicwjhyIRmqmIDS5B2u1WyRvR6Eg/b5JkWj+T3MdzZHMfhicxTDiFN3giwohXqWqfKYd9gOSj5kpEOgRFJlCIk1ythopN7hPl5nTufQQRZERy675LGEVb5YZAghhNkcVAiFLS1KKmqbW1F2ipblGI0aaxQ0eoP7F6RRYY0KelUO2ufPBKXTGuVl/SSH433hi81RDO2k8lTSwTvyZFXCqssXVDYlrKiiZSNZtu3Zpk5dPIuVIGGNmvxOyIKGU/yuHStBjtAlQaOsNRZopCY6aWlpMr/TUCLkQmY8GhuNiS2UDBlLU1CclQsxI0fMH/tdnEYd14YvNkcx+GJzFEOrNWWq6/Dl3YylW4NnOfaDootD6dTu9ZmN57T+K0pYmTNbnH+G6+Msyo4yMvCi5AXOaabUKDVpPKfdwS2hekPhesXq22Pls5ghRTm30rBNOZulX5YQkQJ1j+9sjmLwxeYohla3SxRdh1WAPQXvIXWynBWjA0qrRhpl1IBRghCsJg3UaSpBQqvWI9GY1btVSaoasu60PofRqpE6GSm4A60Z+TZrbICqWcJqxerbI/sD3R2UczeCRgnlElHXQ9CuD3Pd9WyOK8AXm6MYEhpl86QJXYcHresyujVVCZIUycwpWp2nfHHl873NrhpIi6TO+xiZOLLxBQPu+N61qb0Rn8/sqKax/0cXN9SqoWfUJ9H4gpYmNWi1CKqLloopjNXaioYY4TKvv7Q4x56ljiIjT3I43hW+2BzF0Kq6GpO6Dqf9owhmSKkiyqY3FILvW2WN5oPqIdhguilhxa7FkHxT2k0anUODxuwoVn9MadRo1dB/wATZFXXe/RLHhkZhjTKBeCwQr3Rr9QQalfQ88r5J1ih+Df0kh+N94YvNUQytsRop06Z1yPY8o20YIZ2mNUvq3MEZe0AWFWh0eGC/Arwbjtw+pVG2VYRW7XSkVg3UKRKLZ2vU4YAFyuqP9dxabiahmM5bUietS443EwonqwTiBBXn1flyVsrhKp/L+RNbUSrq9Z3NUQy+2BzF0ErnLbvZUf5D6kw74xFKGmRoFM9FJUgjH8IcFldmdlQINkOKican7vvUScxhWVawOln90RRUDtOct8a65HgtJEZw0FYTadTEQOnIVQ7bKRSpaHcMbo06rg1fbI5iaE0j2JMokMzaG8J6fb4JTmFDo6DFB5SzYkbUDjRK+dCRPQqiBXp8shRuyltNoE6lvDWd7VqobkVB5RBCqG+FBboRNErqXOVjo6b/AGk0hSpvpapCXhjPfJVTV8B3Nkcx+GJzFENrFLKkPiad0Bo1ScbaqWuol9QpKJKVIIdtpHBTOBnFlVmTI321ok7Khxj3rE2pKsQ2ocCt16DXRVJe6lLnLaizumEdj3xB5Uq1AHr+NA5pgRpH7pQ95VJ6vRy+szmKwReboxha0wiWNKpimExS6W13OpMAA+o11EmHLa1R9GCnfIgKXEqHul6rhBV1tg1lQnlKZWe7qkV8kWWr5gmtmQQW4bxV1LnMJ7OY+hyqDkcKWqC1iocKvCNdyqShd3uDw/Ed+GJzFENrOtjRwUuZz55OXVBfp2nUxFNJnawEeaSlyRgoyiSARk1x5REa5TZuexHkW/rUorNdmMFJegPH6tK22Knuvh/3NF3vaGmadj3MsKGDdmIPYqnIfT1FKkp8DXxncxSDLzZHMfhicxSDPbPRxcG6Gnt2F2aPqeTMRjf+IX9m65FAfEZG1HmHMxv7R53iOxg1SPVopu8Tz2bIimI5K2rSGCkwGjTh+qjmSQSB5zRGCqac01oRHTBB9Yl7AiMFl7o+CsB3Nkcx+GJzFENrJNvG6y/aJb6CRhkRMDQKtwYrQR4g+VZtGFOTnAxiekbBxcGOxNSkUbfGaICNIIASUxrd5PVppvYGNWnNBLeGCqqPwdDtZdT5ni4OBd/ZHMXgi81RDK2xOmmNfgW90rIkdY7Q6HCAnPtrDLJLSxPJxMcjuhaLmhyzuf1/Qk3aHJ+1N+wZhaqQK8q/EQCnBo10t0bAfG4jCKRRI+emBcqIgMqCIupX0OgE6ixBlwq+szmKwReboxha03X4mC9PNYBGWZqKicEhBFO58nxAJUgUVGYJq571OZARdQSl2sbN8QfW4QjBlrFqWZdjDRplTQ4mI89Baxs4aGmNsq9AKguf4ry9OIH4Ull3kI7ca1In4Tuboxh8sTmKoVVWZ/8FxZKfWIUSFNfbDCdLo/Ge/S7S8wEUSeuyB4126XP/C/YfmCVlq0x5q3W+azFbLxp9GnVrjG3SgqRTNnHqyoRiQ52iEuQUGp0aG32Dbq0EfGdzFIMvNkcxWBqF/Lv7HJOXSYkD+wek1ihA+dDTPlqmdNjSuiSl0gK1vQji/43ZwsYUa9blUNRJx6yiUcYzmzyNvkgaVgnFU6hTtveZGOcUluZHsUAJ39kcxeCLzVEMbf850iitztOfkUYZt2RWE6kvBEuLLFv19IRE4y6fTEyY7Kgmr8BtkrJV1RwtfViXYwW6ZOYUk45NFhWsUdCdqf6Y0qgqnGzGwkl7YYPYUdXtB6ROwnc2RzH4YnMUQ3v6F5y3iGc+3KOXgOhg14/QKOft9/lYJ0EGmLV5OqA1Wq+sY7VeRipsNoI6YY1WbBgLWqyWbMkDq3G2zM4PIZUPCepUdTjeXKrqY1Mn4Tuboxh8sTmKoT38EWtv0OF6v4XStqNyNt6cWpOm+iNotGMdDsznSq9r5ZyMY9MZb2PVsqbFD523pM41KJWSIZbAWigahYWbxjOnyIcqQZ2vKZys7nBr1OF4hi82RzG0f/4ZZUUn0OV2B0UtE1lwc14I9N95wuqkwLYGVcwYDzU+z3wiC5W2IYRQLfAzSyUYSqVTl6WxSKOIgdJqlM1ik8+mlEC4tNPdB6fHqfCdzVEMvtgcxeCLzVEM7Z9fUJMD56YH9KU6i/NXiiHkJ7ZMIOb6rvIaNlOalFEDlrlaw0URgnVfMMiuzmms2M0IgowAjJzZVKRAZUi9qZfUjwvf2RzF4IvNUQztZ0i76ek/DJRv528elVaBHm6wpNtqyM4xlSPZHANBedN6caVp1ATZVxNolBEABtVNXyjh3ghhhDqVi+NC18cIPnrUgPCdzVEMvtgcxdD+gbJXpFFapmpFprFzzmuwvc+qSDOGkgWbsHIkx+xmPEajki45ppS7hTauFn2ilKw7/dlQ5/v8X/6RqHIMvrM5isEXm6MY2t+RQHyGU5aOWLoweX2MRuf4cC0yiJSejbo1jo0UnEnGIYSKNGqoU9ThgG6tYi8CY1kGcT394hc6byfQ4s9CnYTvbI5i8MXmKIb2d9TxIG7hWJ0ztsm45QsajRcWsDp7m0/8DbydJa9Uq0ZTLZKO2xBsGSvTqZgWKKhT9iWYYFmmFDf22Xeu/4x0qeA7m6MYfLE5iuE/MnuUaG9klSUAAAAASUVORK5CYII=\" id=\"image9543c406d3\" transform=\"scale(1 -1) translate(0 -111.6)\" x=\"40.603125\" y=\"-9.883219\" width=\"111.6\" height=\"111.6\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path id=\"m1bc1ba6f1f\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m1bc1ba6f1f\" x=\"41.719125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(38.537875 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use xlink:href=\"#m1bc1ba6f1f\" x=\"86.359125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(79.996625 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_3\">\n <g>\n <use xlink:href=\"#m1bc1ba6f1f\" x=\"130.999125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 40 -->\n <g style=\"fill: #ffffff\" transform=\"translate(124.636625 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- Sorted training inputs -->\n <g style=\"fill: #ffffff\" transform=\"translate(41.889844 149.759781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \nL 3425 3897 \nQ 3066 4069 2747 4153 \nQ 2428 4238 2131 4238 \nQ 1616 4238 1336 4038 \nQ 1056 3838 1056 3469 \nQ 1056 3159 1242 3001 \nQ 1428 2844 1947 2747 \nL 2328 2669 \nQ 3034 2534 3370 2195 \nQ 3706 1856 3706 1288 \nQ 3706 609 3251 259 \nQ 2797 -91 1919 -91 \nQ 1588 -91 1214 -16 \nQ 841 59 441 206 \nL 441 856 \nQ 825 641 1194 531 \nQ 1563 422 1919 422 \nQ 2459 422 2753 634 \nQ 3047 847 3047 1241 \nQ 3047 1584 2836 1778 \nQ 2625 1972 2144 2069 \nL 1759 2144 \nQ 1053 2284 737 2584 \nQ 422 2884 422 3419 \nQ 422 4038 858 4394 \nQ 1294 4750 2059 4750 \nQ 2388 4750 2728 4690 \nQ 3069 4631 3425 4513 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \nQ 2906 2416 2648 2759 \nQ 2391 3103 1925 3103 \nQ 1463 3103 1205 2759 \nQ 947 2416 947 1791 \nQ 947 1169 1205 825 \nQ 1463 481 1925 481 \nQ 2391 481 2648 825 \nQ 2906 1169 2906 1791 \nz\nM 3481 434 \nQ 3481 -459 3084 -895 \nQ 2688 -1331 1869 -1331 \nQ 1566 -1331 1297 -1286 \nQ 1028 -1241 775 -1147 \nL 775 -588 \nQ 1028 -725 1275 -790 \nQ 1522 -856 1778 -856 \nQ 2344 -856 2625 -561 \nQ 2906 -266 2906 331 \nL 2906 616 \nQ 2728 306 2450 153 \nQ 2172 0 1784 0 \nQ 1141 0 747 490 \nQ 353 981 353 1791 \nQ 353 2603 747 3093 \nQ 1141 3584 1784 3584 \nQ 2172 3584 2450 3431 \nQ 2728 3278 2906 2969 \nL 2906 3500 \nL 3481 3500 \nL 3481 434 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-53\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"400.976562\"/>\n <use xlink:href=\"#DejaVuSans-61\" x=\"442.089844\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"503.369141\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"531.152344\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"594.53125\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"622.314453\"/>\n <use xlink:href=\"#DejaVuSans-67\" x=\"685.693359\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"749.169922\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"780.957031\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"808.740234\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"872.119141\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"935.595703\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"998.974609\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"1038.183594\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_4\">\n <defs>\n <path id=\"mb5f45e7341\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mb5f45e7341\" x=\"40.603125\" y=\"10.999219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(27.240625 14.798438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_5\">\n <g>\n <use xlink:href=\"#mb5f45e7341\" x=\"40.603125\" y=\"33.319219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 10 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 37.118438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#mb5f45e7341\" x=\"40.603125\" y=\"55.639219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 59.438438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_7\">\n <g>\n <use xlink:href=\"#mb5f45e7341\" x=\"40.603125\" y=\"77.959219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 30 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 81.758438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#mb5f45e7341\" x=\"40.603125\" y=\"100.279219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 40 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 104.078438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-34\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- Sorted testing inputs -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798438 118.160563) rotate(-90) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-53\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"400.976562\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"462.5\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"514.599609\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"553.808594\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"581.591797\"/>\n <use xlink:href=\"#DejaVuSans-67\" x=\"644.970703\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"708.447266\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"740.234375\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"768.017578\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"831.396484\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"894.873047\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"958.251953\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"997.460938\"/>\n </g>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 40.603125 121.483219 \nL 40.603125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 152.203125 121.483219 \nL 152.203125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 40.603125 121.483219 \nL 152.203125 121.483219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 40.603125 9.883219 \nL 152.203125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n <g id=\"axes_2\">\n <g id=\"patch_7\">\n <path d=\"M 159.178125 107.263219 \nL 163.336125 107.263219 \nL 163.336125 24.103219 \nL 159.178125 24.103219 \nz\n\"/>\n </g>\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAYAAABzCAYAAAC7I3M6AAAAv0lEQVR4nNWVQQrDQAwDXfD/v9pLT1l71Q/sBBQMpTmukMbWhuSlz1txeDK0T+d3wrYFmyFm9BTjZsFjVY/g6GgSyKFaLsOHt82gKPlT+QvaJUbVWNS/waldjqKXGh24oB9lO/RL+AOBGGoSFjLsqDm4mj6W/lSFDDcK4ZvGbXTQ36BJQAa0Hlk2nAWCF081xsBKWiQcjyNykwM6jCx0nM8jO2wH74GbQ5S/IMIXMbASnAodFwllR/mOy76Puam+t3oOUronbv0AAAAASUVORK5CYII=\" id=\"image3b2d35adf7\" transform=\"scale(1 -1) translate(0 -82.8)\" x=\"159.12\" y=\"-23.76\" width=\"4.32\" height=\"82.8\"/>\n <g id=\"matplotlib.axis_3\"/>\n <g id=\"matplotlib.axis_4\">\n <g id=\"ytick_6\">\n <g id=\"line2d_9\">\n <defs>\n <path id=\"m354c337467\" d=\"M 0 0 \nL 3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m354c337467\" x=\"163.336125\" y=\"83.040452\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 0.02 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 86.839671) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#m354c337467\" x=\"163.336125\" y=\"58.817198\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 0.04 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 62.616417) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-34\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_8\">\n <g id=\"line2d_11\">\n <g>\n <use xlink:href=\"#m354c337467\" x=\"163.336125\" y=\"34.593944\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 0.06 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 38.393162) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-36\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"LineCollection_1\"/>\n <g id=\"patch_8\">\n <path d=\"M 159.178125 107.263219 \nL 161.257125 107.263219 \nL 163.336125 107.263219 \nL 163.336125 24.103219 \nL 161.257125 24.103219 \nL 159.178125 24.103219 \nL 159.178125 107.263219 \nz\n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pbcbc2e6914\">\n <rect x=\"40.603125\" y=\"9.883219\" width=\"111.6\" height=\"111.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 12
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.610782245Z",
|
||
"start_time": "2026-05-29T15:19:43.560607937Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"class NWKernelRegression(nn.Module):\n",
|
||
" def __init__(self,**kwargs):\n",
|
||
" super().__init__(**kwargs)\n",
|
||
" self.w = nn.Parameter(torch.randn((1,),requires_grad=True))\n",
|
||
" def forward(self,queries,keys,values):\n",
|
||
" queries = queries.repeat_interleave(keys.shape[1]).reshape(-1,keys.shape[1])\n",
|
||
" self.attention_weights = nn.functional.softmax(\n",
|
||
" -((queries - keys) * self.w)**2 / 2, dim=1)\n",
|
||
" return torch.bmm(self.attention_weights.unsqueeze(1),values.unsqueeze(-1)).reshape(-1)"
|
||
],
|
||
"id": "aeb79a3bd64c826",
|
||
"outputs": [],
|
||
"execution_count": 13
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:43.661276280Z",
|
||
"start_time": "2026-05-29T15:19:43.611752619Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"# X_tile的形状:(n_train,n_train),每一行都包含着相同的训练输入\n",
|
||
"X_tile = x_train.repeat((n_train, 1))\n",
|
||
"# Y_tile的形状:(n_train,n_train),每一行都包含着相同的训练输出\n",
|
||
"Y_tile = y_train.repeat((n_train, 1))\n",
|
||
"# keys的形状:('n_train','n_train'-1)\n",
|
||
"keys = X_tile[(1 - torch.eye(n_train)).type(torch.bool)].reshape((n_train, -1))\n",
|
||
"# values的形状:('n_train','n_train'-1)\n",
|
||
"values = Y_tile[(1 - torch.eye(n_train)).type(torch.bool)].reshape((n_train, -1))"
|
||
],
|
||
"id": "7061ed7f139bc78e",
|
||
"outputs": [],
|
||
"execution_count": 14
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.080669795Z",
|
||
"start_time": "2026-05-29T15:19:43.662206275Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"net = NWKernelRegression()\n",
|
||
"loss = nn.MSELoss(reduction='none')\n",
|
||
"trainer = torch.optim.SGD(net.parameters(), lr=0.5)\n",
|
||
"animator = d2l.Animator(xlabel='epoch', ylabel='loss', xlim=[1, 5])\n",
|
||
"for epoch in range(5):\n",
|
||
" trainer.zero_grad()\n",
|
||
" l = loss(net(x_train, keys, values), y_train)\n",
|
||
" l.sum().backward()\n",
|
||
" trainer.step()\n",
|
||
" print(f'epoch {epoch + 1}, loss {float(l.sum()):.6f}')\n",
|
||
" animator.add(epoch + 1, float(l.sum()))"
|
||
],
|
||
"id": "3dca11d4e962d859",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 350x250 with 1 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"246.284375pt\" height=\"183.35625pt\" viewBox=\"0 0 246.284375 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:44.050719</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 183.35625 \nL 246.284375 183.35625 \nL 246.284375 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 40.603125 145.8 \nL 235.903125 145.8 \nL 235.903125 7.2 \nL 40.603125 7.2 \nz\n\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path d=\"M 40.603125 145.8 \nL 40.603125 7.2 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path id=\"m03460f72e1\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m03460f72e1\" x=\"40.603125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(37.421875 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path d=\"M 89.428125 145.8 \nL 89.428125 7.2 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#m03460f72e1\" x=\"89.428125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(86.246875 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path d=\"M 138.253125 145.8 \nL 138.253125 7.2 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#m03460f72e1\" x=\"138.253125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(135.071875 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path d=\"M 187.078125 145.8 \nL 187.078125 7.2 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#m03460f72e1\" x=\"187.078125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(183.896875 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path d=\"M 235.903125 145.8 \nL 235.903125 7.2 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#m03460f72e1\" x=\"235.903125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(232.721875 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- epoch -->\n <g style=\"fill: #ffffff\" transform=\"translate(123.025 174.076563) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-65\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_11\">\n <path d=\"M 40.603125 126.456369 \nL 235.903125 126.456369 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_12\">\n <defs>\n <path id=\"m8b192d28b9\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m8b192d28b9\" x=\"40.603125\" y=\"126.456369\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 16 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 130.255588) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-36\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_13\">\n <path d=\"M 40.603125 99.691836 \nL 235.903125 99.691836 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_14\">\n <g>\n <use xlink:href=\"#m8b192d28b9\" x=\"40.603125\" y=\"99.691836\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 18 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 103.491054) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-38\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_15\">\n <path d=\"M 40.603125 72.927302 \nL 235.903125 72.927302 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use xlink:href=\"#m8b192d28b9\" x=\"40.603125\" y=\"72.927302\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 76.726521) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_17\">\n <path d=\"M 40.603125 46.162769 \nL 235.903125 46.162769 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use xlink:href=\"#m8b192d28b9\" x=\"40.603125\" y=\"46.162769\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 22 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 49.961988) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_19\">\n <path d=\"M 40.603125 19.398236 \nL 235.903125 19.398236 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_20\">\n <g>\n <use xlink:href=\"#m8b192d28b9\" x=\"40.603125\" y=\"19.398236\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 24 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 23.197454) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-34\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- loss -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 86.157813) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-6c\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"27.783203\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"88.964844\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"141.064453\"/>\n </g>\n </g>\n </g>\n <g id=\"line2d_21\">\n <path d=\"M 40.603125 13.5 \nL 89.428125 137.396259 \nL 138.253125 138.09691 \nL 187.078125 138.798838 \nL 235.903125 139.5 \n\" clip-path=\"url(#p31ab99acb0)\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 40.603125 145.8 \nL 40.603125 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 235.903125 145.8 \nL 235.903125 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 40.603125 145.8 \nL 235.903125 145.8 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 40.603125 7.2 \nL 235.903125 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"p31ab99acb0\">\n <rect x=\"40.603125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 15
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.196985129Z",
|
||
"start_time": "2026-05-29T15:19:44.082458369Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"# keys的形状:(n_test,n_train),每一行包含着相同的训练输入(例如,相同的键)\n",
|
||
"keys = x_train.repeat((n_test, 1))\n",
|
||
"# value的形状:(n_test,n_train)\n",
|
||
"values = y_train.repeat((n_test, 1))\n",
|
||
"y_hat = net(x_test, keys, values).unsqueeze(1).detach()\n",
|
||
"plot_kernel_reg(y_hat)"
|
||
],
|
||
"id": "4ff00f0b4983b55e",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 350x250 with 1 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"187.155469pt\" viewBox=\"0 0 248.301563 187.155469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:44.158025</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 187.155469 \nL 248.301563 187.155469 \nL 248.301563 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \nL 237.920313 10.999219 \nL 42.620312 10.999219 \nz\n\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path id=\"m91fc095f56\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(39.439062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path d=\"M 81.680312 149.599219 \nL 81.680312 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"81.680312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.499062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path d=\"M 120.740313 149.599219 \nL 120.740313 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"120.740313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(117.559062 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path d=\"M 159.800313 149.599219 \nL 159.800313 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"159.800313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(156.619063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path d=\"M 198.860313 149.599219 \nL 198.860313 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"198.860313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(195.679063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_6\">\n <g id=\"line2d_11\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_12\">\n <g>\n <use xlink:href=\"#m91fc095f56\" x=\"237.920313\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(234.739063 164.197656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- x -->\n <g style=\"fill: #ffffff\" transform=\"translate(137.310937 177.875781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-78\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_13\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_14\">\n <defs>\n <path id=\"mb0cdd34b51\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"149.599219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- −1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 153.398437) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-2212\"/>\n <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_15\">\n <path d=\"M 42.620312 126.499219 \nL 237.920313 126.499219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"126.499219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 130.298437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_17\">\n <path d=\"M 42.620312 103.399219 \nL 237.920313 103.399219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"103.399219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 107.198437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_19\">\n <path d=\"M 42.620312 80.299219 \nL 237.920313 80.299219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_20\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"80.299219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 84.098437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_21\">\n <path d=\"M 42.620312 57.199219 \nL 237.920313 57.199219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_22\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"57.199219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 3 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 60.998437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-33\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_6\">\n <g id=\"line2d_23\">\n <path d=\"M 42.620312 34.099219 \nL 237.920313 34.099219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_24\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"34.099219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 37.898438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-34\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_25\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_26\">\n <g>\n <use xlink:href=\"#mb0cdd34b51\" x=\"42.620312\" y=\"10.999219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_14\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(29.257812 14.798437) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_15\">\n <!-- y -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 83.258594) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-79\"/>\n </g>\n </g>\n </g>\n <g id=\"line2d_27\">\n <path d=\"M 42.620312 126.499219 \nL 46.526313 118.225812 \nL 50.432313 110.946345 \nL 54.338313 104.029425 \nL 58.244313 97.4097 \nL 62.150312 91.082293 \nL 66.056313 85.061866 \nL 69.962312 79.370737 \nL 73.868313 74.033949 \nL 77.774314 69.076775 \nL 81.680312 64.523261 \nL 85.586313 60.395214 \nL 89.492314 56.711598 \nL 93.398311 53.487961 \nL 97.304312 50.736132 \nL 101.210313 48.46391 \nL 105.116313 46.674891 \nL 109.022314 45.368338 \nL 112.928315 44.539111 \nL 116.834312 44.177706 \nL 120.740313 44.270242 \nL 124.646309 44.798618 \nL 128.552314 45.740654 \nL 132.458311 47.070245 \nL 136.364316 48.757689 \nL 140.270312 50.76986 \nL 144.176318 53.070611 \nL 148.082314 55.621064 \nL 151.98832 58.380042 \nL 155.894316 61.304393 \nL 159.800313 64.349483 \nL 163.706318 67.469619 \nL 167.612314 70.618454 \nL 171.518311 73.749494 \nL 175.424316 76.816549 \nL 179.330312 79.774142 \nL 183.236318 82.578044 \nL 187.142314 85.185605 \nL 191.048311 87.556281 \nL 194.954316 89.651973 \nL 198.860313 91.437389 \nL 202.766309 92.880457 \nL 206.672305 93.952601 \nL 210.57832 94.629017 \nL 214.484316 94.888934 \nL 218.390312 94.715829 \nL 222.296309 94.097555 \nL 226.202305 93.026506 \nL 230.10832 91.499643 \nL 234.014316 89.518571 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_28\">\n <path d=\"M 42.620312 134.594811 \nL 46.526313 128.951736 \nL 50.432313 113.784377 \nL 54.338313 106.193717 \nL 58.244313 103.079934 \nL 62.150312 97.539786 \nL 66.056313 87.328713 \nL 69.962312 82.78043 \nL 73.868313 78.964076 \nL 77.774314 74.26501 \nL 81.680312 70.673914 \nL 85.586313 69.558354 \nL 89.492314 67.965374 \nL 93.398311 50.818023 \nL 97.304312 38.356619 \nL 101.210313 36.582983 \nL 105.116313 35.817764 \nL 109.022314 38.606928 \nL 112.928315 41.887601 \nL 116.834312 41.457682 \nL 120.740313 39.760567 \nL 124.646309 38.400745 \nL 128.552314 38.785298 \nL 132.458311 39.980436 \nL 136.364316 43.477629 \nL 140.270312 50.335387 \nL 144.176318 56.498548 \nL 148.082314 56.789727 \nL 151.98832 57.519665 \nL 155.894316 65.984645 \nL 159.800313 74.615356 \nL 163.706318 75.211821 \nL 167.612314 72.44456 \nL 171.518311 75.291894 \nL 175.424316 77.100194 \nL 179.330312 75.500109 \nL 183.236318 76.290833 \nL 187.142314 77.800491 \nL 191.048311 77.442494 \nL 194.954316 77.744166 \nL 198.860313 85.656037 \nL 202.766309 95.566777 \nL 206.672305 94.179635 \nL 210.57832 87.98772 \nL 214.484316 86.744827 \nL 218.390312 86.768457 \nL 222.296309 85.237417 \nL 226.202305 82.175374 \nL 230.10832 79.394474 \nL 234.014316 77.630327 \n\" clip-path=\"url(#pdea2f7e48f)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"line2d_29\">\n <defs>\n <path id=\"mfcc44eb9f7\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #feffb3; stroke-opacity: 0.5\"/>\n </defs>\n <g clip-path=\"url(#pdea2f7e48f)\">\n <use xlink:href=\"#mfcc44eb9f7\" x=\"42.657342\" y=\"131.660222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"44.675703\" y=\"139.896089\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"51.855287\" y=\"118.429289\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"54.159045\" y=\"115.579943\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"55.326313\" y=\"105.400959\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"56.406136\" y=\"80.646272\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"56.83766\" y=\"104.882394\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"58.709219\" y=\"111.776797\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"65.568564\" y=\"85.512184\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"69.374217\" y=\"88.669352\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"71.016162\" y=\"79.61144\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"73.907617\" y=\"76.012711\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"78.84565\" y=\"80.675858\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"80.596239\" y=\"61.336688\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"88.147235\" y=\"70.985422\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"98.85527\" y=\"34.961782\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"100.382736\" y=\"40.731445\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"105.461658\" y=\"31.018935\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"109.596131\" y=\"38.510393\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"113.923449\" y=\"48.746884\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"116.643575\" y=\"42.636143\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"118.092844\" y=\"35.130222\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"135.776419\" y=\"40.64603\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"137.078837\" y=\"33.64439\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"139.889426\" y=\"44.932482\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"141.994257\" y=\"73.442056\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"146.06478\" y=\"54.749326\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"153.43892\" y=\"51.831986\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"158.648284\" y=\"80.610407\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"165.201852\" y=\"77.170315\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"170.382431\" y=\"58.974783\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"174.452506\" y=\"84.573287\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"174.833132\" y=\"91.050581\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"178.946297\" y=\"56.271491\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"181.982698\" y=\"68.464549\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"182.384082\" y=\"93.021015\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"182.537526\" y=\"76.335311\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"193.579195\" y=\"76.817551\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"204.920897\" y=\"97.381441\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"214.149062\" y=\"79.999232\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"215.84437\" y=\"100.845345\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"216.101529\" y=\"79.141615\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"222.443877\" y=\"87.218974\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"222.684701\" y=\"85.093691\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"228.080867\" y=\"78.91387\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"228.265034\" y=\"87.556254\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"230.126312\" y=\"86.51374\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"230.632882\" y=\"66.206134\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"233.755183\" y=\"77.956022\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n <use xlink:href=\"#mfcc44eb9f7\" x=\"234.184309\" y=\"75.603727\" style=\"fill: #feffb3; fill-opacity: 0.5; stroke: #feffb3; stroke-opacity: 0.5\"/>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 42.620312 149.599219 \nL 42.620312 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 237.920313 149.599219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 42.620312 149.599219 \nL 237.920313 149.599219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 42.620312 10.999219 \nL 237.920313 10.999219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"legend_1\">\n <g id=\"patch_7\">\n <path d=\"M 173.58125 48.355469 \nL 230.920313 48.355469 \nQ 232.920313 48.355469 232.920313 46.355469 \nL 232.920313 17.999219 \nQ 232.920313 15.999219 230.920313 15.999219 \nL 173.58125 15.999219 \nQ 171.58125 15.999219 171.58125 17.999219 \nL 171.58125 46.355469 \nQ 171.58125 48.355469 173.58125 48.355469 \nz\n\" style=\"opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n </g>\n <g id=\"line2d_30\">\n <path d=\"M 175.58125 24.097656 \nL 185.58125 24.097656 \nL 195.58125 24.097656 \n\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"text_16\">\n <!-- Truth -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 27.597656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-54\" d=\"M -19 4666 \nL 3928 4666 \nL 3928 4134 \nL 2272 4134 \nL 2272 0 \nL 1638 0 \nL 1638 4134 \nL -19 4134 \nL -19 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-54\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n </g>\n </g>\n <g id=\"line2d_31\">\n <path d=\"M 175.58125 38.775781 \nL 185.58125 38.775781 \nL 195.58125 38.775781 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n </g>\n <g id=\"text_17\">\n <!-- Pred -->\n <g style=\"fill: #ffffff\" transform=\"translate(203.58125 42.275781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \nL 1259 2394 \nL 2053 2394 \nQ 2494 2394 2734 2622 \nQ 2975 2850 2975 3272 \nQ 2975 3691 2734 3919 \nQ 2494 4147 2053 4147 \nL 1259 4147 \nz\nM 628 4666 \nL 2053 4666 \nQ 2838 4666 3239 4311 \nQ 3641 3956 3641 3272 \nQ 3641 2581 3239 2228 \nQ 2838 1875 2053 1875 \nL 1259 1875 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n </g>\n </g>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pdea2f7e48f\">\n <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"138.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 16
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.303651198Z",
|
||
"start_time": "2026-05-29T15:19:44.199584310Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"d2l.show_heatmaps(net.attention_weights.unsqueeze(0).unsqueeze(0),\n",
|
||
"xlabel='Sorted training inputs',\n",
|
||
"ylabel='Sorted testing inputs')"
|
||
],
|
||
"id": "97a690478767c3c3",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 250x250 with 2 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"199.80175pt\" height=\"159.039469pt\" viewBox=\"0 0 199.80175 159.039469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:44.256961</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 159.039469 \nL 199.80175 159.039469 \nL 199.80175 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 40.603125 121.483219 \nL 152.203125 121.483219 \nL 152.203125 9.883219 \nL 40.603125 9.883219 \nz\n\"/>\n </g>\n <g clip-path=\"url(#p690a9a1c03)\">\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAJsAAACbCAYAAAB1YemMAAAHoElEQVR4nO3dW4hVZRTA8e/b54zOeBnFS17Q0Rg1tamUzFIJSiul3gShnnrutZ6i3oIeonwRsoeCgiACS+klCcUQbxiYjijZzbtONiNHnfvlfL3It9Y+OjY6c5b7nPP/Pa397X0Oe5jFWmffvu1DVyE4QAlBpcTNdr0ivV3hH1no65Hxtgt3/d5kTPYOGAGSDWbyD3sHkA1hoE8tSLsM/15S48X0Z1TrdF7qll+6SuJcLsZUNpgh2WCGNlpjUkeaul1eOy/jQ0My3tMp496nvstPmyVx3XhZMWWm2kjqGZUNZkg2mKGN1oDQr44ae7vVCjm6DK2HZFy1y+TZjXcdd8451zBZrVN1S7VUr79r5LsMjA7JBjO00RoQLvwm8bWLsmJoIIa+uUXG8yot9JFlCZ/khl13N1Q2mCHZYIZkgxl+s1WpMDQo8bH9sqJunMTqIrl/ZpOMq9MV9/u77F6obDBDssEMbbRKFU8djHEoXI+xf2q1bKQvno+fUPZ9orLBDMkGM56nq6rTngXLYrz+wM4Y++lzZCN9K7e+qF4mVDaYIdlghqPRKhJuyVHn3oLct7Zh7iLZSJ2k9aX3p5UZlQ1mSDaYoY1WkZtvbI7xB+/ItU6fy8a/mcoGMyQbzHBStwKEcI9/kVr31uSmGG/vOBNjXz+xLPt1v6hsMEOywUw2DlNwh1BU01N135BY3YF7e8MYbpnRGOOstE6NygYzJBvMcDSaIamjzi5pncUTP8t4t5rCyjnnBvpj6FvWxDhpWuayhsoGMyQbzHA0+pCFwX61oGaCbFdzcvSqKa9KqedA/bzHxnLXxhyVDWZINpihjT4EemoEV7h21/HQdk62mb0ghl5Pn+BcyVQJ2a4d2d47VBWSDWZINpjhN5sRfWE9dFyW+NQR2Ui97MLNa45hMm+JjN/xu8z2CanRoLLBDMkGM7RRKzfUKY49O2R81lyJG2TaqqRpqYzX32MeDuMHjUeDygYzJBvM0EbLSL8zaujLj2VFfX0Mcxtfl3H9MLFqnVm/MjBS1fFXoCKQbDBDGx1jYVDeB1XcLzM+9hw6EeOJW7fJB6bK24gr6aL6g6i+vwiZRbLBDG10jIWzrTG+9clnMZ78/tsx9momyKxMZ2WBygYzJBvM1E4NL6Mw0BfjoU8/ivGkFQtjnKx6Jca11Do1KhvMkGwwU5v1/AGk5uHQDxY754qt8vLYwgl5uHj6F3I06g3eepd1VDaYIdlghjZaItUug5798aYMX/4j9ZnBz7fHeNqH78bYNy0f+x2sYFQ2mCHZYIY2WkrdXev6JC7++auM/97qtPy652KcrNoY41o9eTscKhvMkGwwQ50vEdrOStxxVVZcOS/xTPWededcsvKFGPt8yZRWiKhsMEOywQzJBjP8ZisRDu6WhUTNo9EsVwP8gpIXWkyZWea9qg5UNpgh2WCGNlpi8NDhGOdXPhlj3Tp9SdvkSsHIUNlghmSDmZqt/6G/VxbUvWoD7bdinJ8zL8a+cbpsXydTXmHkqGwwQ7LBTE210dBViHFxz7cxvrX96xhP2fWjfEC1S444R4/KBjMkG8xUfW8IRXlFT7jeJvE1uVetYZHM/ujrJ9nsWA2issEMyQYzVdlGUw8ad8tJ2nDmWIx9XV2M82vXmOxXraOywQzJBjNV2UZdj1zrLB7fJ+NtlyRevjKGfvajFntV86hsMEOywUzFttEwNJgeULNBFg/8INudlDk6/MbNMU4Wtshnx3HLkAUqG8yQbDBTuW2043J6+cpfEh87GmO/4bUYJ0uelg/o24cq6D3rlYzKBjMkG8xUbhvd/U16uaM9xv7FTTFOnnhexsc1lH/HMCwqG8yQbDBDssFMRf1mC33dMR48fDS1LrdoYYyTx9fJCt4ZlRlUNpgh2WAm821U3+I9tO29GOdalqa28+tekoUJjTLO1YHMoLLBDMkGMz50FcL/b2Yr6DcV93TG8KvFq2P85t/HXIq6OuDzdQ7ZQ2WDGZINZjJzNBqK8tbicPE3iY8fjPGWDYtj7NURJyoDlQ1mSDaYMW+jqXk4grROPYlyce9OGb9wIYYNW7eXc9dQZlQ2mCHZYMb+aLS/R2J1wrZ45pcYp65nrl4r4zPnl3XXUF5UNpgh2WDGpI0G1TrD+dMSXz0nG12Vo07/8haJpz4icZIrzw7CBJUNZkg2mClbG9Unb1Ot8+QR2Ui3xRa5fcjPbVbbZObyLUaJygYzJBvMjKhHpa9nqli9quf2Sgl7u2Szn76LsV+yXOKmJRLPlwdYfH7cSHYLFYbKBjMkG8wM+8CLfptd6npmnzpBq1rlHevUEaiWrFwvC3pqBNU6edazOlHZYIZkgxmSDWaGP/XRK/eahZsdMt55Q8bV/WjOOeeK6kUYDfJGYj3VaOphYn6b1RQqG8yQbDCTaqOpB4XbzkqsWqe+eO7Hl8y+nZev840z1HbM/ggqGwyRbDCTD+qo03UWYhhOydNOboG6YN44XeJJU9PfllNdWR2NAs5R2WCIZIOZfHHfjrgQTrfG2L8qTzgl6l4zVzde4lzJDI/6JC1PQqEElQ1mSDaYyQ98v0sWZk+LcdK8Qm0lrdMn5CceDJkDMyQbzPwHmq/Dqg5shuQAAAAASUVORK5CYII=\" id=\"image4ae95fc219\" transform=\"scale(1 -1) translate(0 -111.6)\" x=\"40.603125\" y=\"-9.883219\" width=\"111.6\" height=\"111.6\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path id=\"mc4d4f61ded\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mc4d4f61ded\" x=\"41.719125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(38.537875 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use xlink:href=\"#mc4d4f61ded\" x=\"86.359125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(79.996625 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_3\">\n <g>\n <use xlink:href=\"#mc4d4f61ded\" x=\"130.999125\" y=\"121.483219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 40 -->\n <g style=\"fill: #ffffff\" transform=\"translate(124.636625 136.081656) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-34\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- Sorted training inputs -->\n <g style=\"fill: #ffffff\" transform=\"translate(41.889844 149.759781) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \nL 3425 3897 \nQ 3066 4069 2747 4153 \nQ 2428 4238 2131 4238 \nQ 1616 4238 1336 4038 \nQ 1056 3838 1056 3469 \nQ 1056 3159 1242 3001 \nQ 1428 2844 1947 2747 \nL 2328 2669 \nQ 3034 2534 3370 2195 \nQ 3706 1856 3706 1288 \nQ 3706 609 3251 259 \nQ 2797 -91 1919 -91 \nQ 1588 -91 1214 -16 \nQ 841 59 441 206 \nL 441 856 \nQ 825 641 1194 531 \nQ 1563 422 1919 422 \nQ 2459 422 2753 634 \nQ 3047 847 3047 1241 \nQ 3047 1584 2836 1778 \nQ 2625 1972 2144 2069 \nL 1759 2144 \nQ 1053 2284 737 2584 \nQ 422 2884 422 3419 \nQ 422 4038 858 4394 \nQ 1294 4750 2059 4750 \nQ 2388 4750 2728 4690 \nQ 3069 4631 3425 4513 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \nQ 2906 2416 2648 2759 \nQ 2391 3103 1925 3103 \nQ 1463 3103 1205 2759 \nQ 947 2416 947 1791 \nQ 947 1169 1205 825 \nQ 1463 481 1925 481 \nQ 2391 481 2648 825 \nQ 2906 1169 2906 1791 \nz\nM 3481 434 \nQ 3481 -459 3084 -895 \nQ 2688 -1331 1869 -1331 \nQ 1566 -1331 1297 -1286 \nQ 1028 -1241 775 -1147 \nL 775 -588 \nQ 1028 -725 1275 -790 \nQ 1522 -856 1778 -856 \nQ 2344 -856 2625 -561 \nQ 2906 -266 2906 331 \nL 2906 616 \nQ 2728 306 2450 153 \nQ 2172 0 1784 0 \nQ 1141 0 747 490 \nQ 353 981 353 1791 \nQ 353 2603 747 3093 \nQ 1141 3584 1784 3584 \nQ 2172 3584 2450 3431 \nQ 2728 3278 2906 2969 \nL 2906 3500 \nL 3481 3500 \nL 3481 434 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-53\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"400.976562\"/>\n <use xlink:href=\"#DejaVuSans-61\" x=\"442.089844\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"503.369141\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"531.152344\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"594.53125\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"622.314453\"/>\n <use xlink:href=\"#DejaVuSans-67\" x=\"685.693359\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"749.169922\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"780.957031\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"808.740234\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"872.119141\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"935.595703\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"998.974609\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"1038.183594\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_4\">\n <defs>\n <path id=\"mc789012e8a\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mc789012e8a\" x=\"40.603125\" y=\"10.999219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(27.240625 14.798438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_5\">\n <g>\n <use xlink:href=\"#mc789012e8a\" x=\"40.603125\" y=\"33.319219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- 10 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 37.118438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#mc789012e8a\" x=\"40.603125\" y=\"55.639219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 59.438438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_7\">\n <g>\n <use xlink:href=\"#mc789012e8a\" x=\"40.603125\" y=\"77.959219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 30 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 81.758438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-33\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#mc789012e8a\" x=\"40.603125\" y=\"100.279219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 40 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 104.078438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-34\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- Sorted testing inputs -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798438 118.160563) rotate(-90) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-53\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"400.976562\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"462.5\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"514.599609\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"553.808594\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"581.591797\"/>\n <use xlink:href=\"#DejaVuSans-67\" x=\"644.970703\"/>\n <use xlink:href=\"#DejaVuSans-20\" x=\"708.447266\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"740.234375\"/>\n <use xlink:href=\"#DejaVuSans-6e\" x=\"768.017578\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"831.396484\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"894.873047\"/>\n <use xlink:href=\"#DejaVuSans-74\" x=\"958.251953\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"997.460938\"/>\n </g>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 40.603125 121.483219 \nL 40.603125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 152.203125 121.483219 \nL 152.203125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 40.603125 121.483219 \nL 152.203125 121.483219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 40.603125 9.883219 \nL 152.203125 9.883219 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n <g id=\"axes_2\">\n <g id=\"patch_7\">\n <path d=\"M 159.178125 107.263219 \nL 163.336125 107.263219 \nL 163.336125 24.103219 \nL 159.178125 24.103219 \nz\n\"/>\n </g>\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAYAAABzCAYAAAC7I3M6AAAAv0lEQVR4nNWVQQrDQAwDXfD/v9pLT1l71Q/sBBQMpTmukMbWhuSlz1txeDK0T+d3wrYFmyFm9BTjZsFjVY/g6GgSyKFaLsOHt82gKPlT+QvaJUbVWNS/waldjqKXGh24oB9lO/RL+AOBGGoSFjLsqDm4mj6W/lSFDDcK4ZvGbXTQ36BJQAa0Hlk2nAWCF081xsBKWiQcjyNykwM6jCx0nM8jO2wH74GbQ5S/IMIXMbASnAodFwllR/mOy76Puam+t3oOUronbv0AAAAASUVORK5CYII=\" id=\"image458426cd14\" transform=\"scale(1 -1) translate(0 -82.8)\" x=\"159.12\" y=\"-23.76\" width=\"4.32\" height=\"82.8\"/>\n <g id=\"matplotlib.axis_3\"/>\n <g id=\"matplotlib.axis_4\">\n <g id=\"ytick_6\">\n <g id=\"line2d_9\">\n <defs>\n <path id=\"mbf2d14ad8b\" d=\"M 0 0 \nL 3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mbf2d14ad8b\" x=\"163.336125\" y=\"107.263219\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- 0.00 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 111.062437) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_7\">\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#mbf2d14ad8b\" x=\"163.336125\" y=\"85.117441\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_12\">\n <!-- 0.25 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 88.91666) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_8\">\n <g id=\"line2d_11\">\n <g>\n <use xlink:href=\"#mbf2d14ad8b\" x=\"163.336125\" y=\"62.971664\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_13\">\n <!-- 0.50 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 66.770883) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_9\">\n <g id=\"line2d_12\">\n <g>\n <use xlink:href=\"#mbf2d14ad8b\" x=\"163.336125\" y=\"40.825886\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_14\">\n <!-- 0.75 -->\n <g style=\"fill: #ffffff\" transform=\"translate(170.336125 44.625105) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-37\" d=\"M 525 4666 \nL 3525 4666 \nL 3525 4397 \nL 1831 0 \nL 1172 0 \nL 2766 4134 \nL 525 4134 \nL 525 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-37\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"LineCollection_1\"/>\n <g id=\"patch_8\">\n <path d=\"M 159.178125 107.263219 \nL 161.257125 107.263219 \nL 163.336125 107.263219 \nL 163.336125 24.103219 \nL 161.257125 24.103219 \nL 159.178125 24.103219 \nL 159.178125 107.263219 \nz\n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"p690a9a1c03\">\n <rect x=\"40.603125\" y=\"9.883219\" width=\"111.6\" height=\"111.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 17
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.358514818Z",
|
||
"start_time": "2026-05-29T15:19:44.306386112Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"def masked_softmax(X,valid_lens):\n",
|
||
" # X:3D valid_len 1D or 2D\n",
|
||
" if valid_lens is None:\n",
|
||
" return nn.functional.softmax(X,dim=-1)\n",
|
||
" else:\n",
|
||
" shape = X.shape\n",
|
||
" if valid_lens.dim()==1:\n",
|
||
" valid_lens = torch.repeat_interleave(valid_lens,shape[1])\n",
|
||
" else:\n",
|
||
" valid_lens = valid_lens.reshape(-1)\n",
|
||
" #print(valid_lens)\n",
|
||
" X = d2l.sequence_mask(X.reshape(-1,shape[-1]),valid_lens,value=-1e6)\n",
|
||
" return nn.functional.softmax(X.reshape(shape),dim=-1)"
|
||
],
|
||
"id": "8d03d0c7f735b755",
|
||
"outputs": [],
|
||
"execution_count": 18
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.420710191Z",
|
||
"start_time": "2026-05-29T15:19:44.359351187Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": "masked_softmax(torch.rand(2,2,4),torch.tensor([2,3]))",
|
||
"id": "27f8c24ec572b267",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"tensor([[[0.6937, 0.3063, 0.0000, 0.0000],\n",
|
||
" [0.6165, 0.3835, 0.0000, 0.0000]],\n",
|
||
"\n",
|
||
" [[0.3526, 0.3291, 0.3183, 0.0000],\n",
|
||
" [0.2735, 0.2359, 0.4906, 0.0000]]])"
|
||
]
|
||
},
|
||
"execution_count": 19,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 19
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.470391356Z",
|
||
"start_time": "2026-05-29T15:19:44.422576814Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"class AdditiveAttention(nn.Module):\n",
|
||
" def __init__(self,key_size,query_size,num_hiddens,dropout,**kwargs):\n",
|
||
" super(AdditiveAttention,self).__init__(**kwargs)\n",
|
||
" self.W_k = nn.Linear(key_size,num_hiddens,bias=False)\n",
|
||
" self.W_q = nn.Linear(query_size,num_hiddens,bias=False)\n",
|
||
" self.w_v = nn.Linear(num_hiddens,1,bias=False)\n",
|
||
" self.dropout=nn.Dropout(dropout)\n",
|
||
" def forward(self,queries,keys,value,valid_lens):\n",
|
||
" queries,keys=self.W_q(queries),self.W_k(keys)\n",
|
||
" # queries (batch_size,n_q,1,num_hidden)\n",
|
||
" # key (batch_size,1,n_k,num_hiddens)\n",
|
||
" features = queries.unsqueeze(2) + keys.unsqueeze(1)\n",
|
||
" #features (batch_size,n_q,n_k,num_hidden)\n",
|
||
" features = torch.tanh(features)\n",
|
||
" scores = self.w_v(features).squeeze(-1)\n",
|
||
" #print(f\"Inside AdditiveAttention: value.shape = {value.shape}\") # 检查此处形状\n",
|
||
" self.attention_weights = masked_softmax(scores, valid_lens)\n",
|
||
"\n",
|
||
" return torch.bmm(self.dropout(self.attention_weights), value)"
|
||
],
|
||
"id": "c7e5254395b14b1",
|
||
"outputs": [],
|
||
"execution_count": 20
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.536311739Z",
|
||
"start_time": "2026-05-29T15:19:44.471725853Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"queries,keys = torch.normal(0,1,(2,1,20)) , torch.ones((2,10,2))\n",
|
||
"values = torch.arange(40,dtype=torch.float32).reshape(1,10,4).repeat(2,1,1)\n",
|
||
"valid_lens = torch.tensor([2, 6])\n",
|
||
"attention = AdditiveAttention(key_size=2, query_size=20, num_hiddens=8,\n",
|
||
" dropout=0.1)\n",
|
||
"attention.eval()\n",
|
||
"attention(queries,keys,values,valid_lens)"
|
||
],
|
||
"id": "77e325a032e70d98",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"tensor([[[ 2.0000, 3.0000, 4.0000, 5.0000]],\n",
|
||
"\n",
|
||
" [[10.0000, 11.0000, 12.0000, 13.0000]]], grad_fn=<BmmBackward0>)"
|
||
]
|
||
},
|
||
"execution_count": 21,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 21
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.618227172Z",
|
||
"start_time": "2026-05-29T15:19:44.538570102Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),\n",
|
||
" xlabel='Keys', ylabel='Queries')"
|
||
],
|
||
"id": "93ceedfd6e03982f",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 250x250 with 2 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"187.07675pt\" height=\"103.438906pt\" viewBox=\"0 0 187.07675 103.438906\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:44.586919</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M -0 103.438906 \nL 187.07675 103.438906 \nL 187.07675 0 \nL -0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 34.240625 59.94 \nL 145.840625 59.94 \nL 145.840625 37.62 \nL 34.240625 37.62 \nz\n\"/>\n </g>\n <g clip-path=\"url(#pf12a9f2efa)\">\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAJsAAAAfCAYAAADwQL9CAAAAjUlEQVR4nO3aMRHCAAxA0Zau1YcFxmqoCzbMYYGNO+riZ+A9A8nwL1PW7+v8LaS2+zG9wojb9AL8D7GRERsZsZERGxmxkREbGbGRERsZsZERGxmxkREbGbGRERuZ9bHsY/9sz897ajQDXDYyYiMjNjJiIyM2MmIjIzYyYiMjNjJiIyM2MmIjIzYyYiNzAasBCAMqMzMRAAAAAElFTkSuQmCC\" id=\"image2928a5698f\" transform=\"scale(1 -1) translate(0 -22.32)\" x=\"34.240625\" y=\"-37.62\" width=\"111.6\" height=\"22.32\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path id=\"m8574d70971\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m8574d70971\" x=\"39.820625\" y=\"59.94\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(36.639375 74.538438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use xlink:href=\"#m8574d70971\" x=\"95.620625\" y=\"59.94\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(92.439375 74.538438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- Keys -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.371094 88.216563) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \nL 1259 4666 \nL 1259 2694 \nL 3353 4666 \nL 4166 4666 \nL 1850 2491 \nL 4331 0 \nL 3500 0 \nL 1259 2247 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-4b\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_3\">\n <defs>\n <path id=\"mceb7e9ef54\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mceb7e9ef54\" x=\"34.240625\" y=\"43.2\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 46.999219) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#mceb7e9ef54\" x=\"34.240625\" y=\"54.36\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 58.159219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- Queries -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 68.087031) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \nQ 1834 4238 1429 3725 \nQ 1025 3213 1025 2328 \nQ 1025 1447 1429 934 \nQ 1834 422 2522 422 \nQ 3209 422 3611 934 \nQ 4013 1447 4013 2328 \nQ 4013 3213 3611 3725 \nQ 3209 4238 2522 4238 \nz\nM 3406 84 \nL 4238 -825 \nL 3475 -825 \nL 2784 -78 \nQ 2681 -84 2626 -87 \nQ 2572 -91 2522 -91 \nQ 1538 -91 948 567 \nQ 359 1225 359 2328 \nQ 359 3434 948 4092 \nQ 1538 4750 2522 4750 \nQ 3503 4750 4090 4092 \nQ 4678 3434 4678 2328 \nQ 4678 1516 4351 937 \nQ 4025 359 3406 84 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-51\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 34.240625 59.94 \nL 34.240625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 145.840625 59.94 \nL 145.840625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 34.240625 59.94 \nL 145.840625 59.94 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 34.240625 37.62 \nL 145.840625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n <g id=\"axes_2\">\n <g id=\"patch_7\">\n <path d=\"M 152.815625 90.36 \nL 156.973625 90.36 \nL 156.973625 7.2 \nL 152.815625 7.2 \nz\n\"/>\n </g>\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAYAAAB0CAYAAACmJkOCAAAAyElEQVR4nM2WSwrEMAxDXcj9zzqbblp/egG/gEII02WEJMt2Qq+6f2XNN6yyO7dhGQQQo1qLFY9ij30AB5Rz6B7uIqNQKkiKAUwuAyRV8e6SmjTxgAcy5An+qTkD+vrQNVgw15sI5qWXi909kLwCpTCgDPgB83dfuXpVFDAD3vakR18H3KEqWJKJVCBAyTEgSukBw2WP9thsJP0zOAEoFcjoz22EUQ5kyFVhwH5BZx4MkBQ2Ee7mhAEjX2E88sxRCluyYg4MquoD0XoQUGMmzEcAAAAASUVORK5CYII=\" id=\"image235d8845b8\" transform=\"scale(1 -1) translate(0 -83.52)\" x=\"152.64\" y=\"-6.48\" width=\"4.32\" height=\"83.52\"/>\n <g id=\"matplotlib.axis_3\"/>\n <g id=\"matplotlib.axis_4\">\n <g id=\"ytick_3\">\n <g id=\"line2d_5\">\n <defs>\n <path id=\"mbf94a7a396\" d=\"M 0 0 \nL 3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#mbf94a7a396\" x=\"156.973625\" y=\"90.36\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 0.0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 94.159219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#mbf94a7a396\" x=\"156.973625\" y=\"57.096\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 0.2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 60.895219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_7\">\n <g>\n <use xlink:href=\"#mbf94a7a396\" x=\"156.973625\" y=\"23.832\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0.4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 27.631219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"LineCollection_1\"/>\n <g id=\"patch_8\">\n <path d=\"M 152.815625 90.36 \nL 154.894625 90.36 \nL 156.973625 90.36 \nL 156.973625 7.2 \nL 154.894625 7.2 \nL 152.815625 7.2 \nL 152.815625 90.36 \nz\n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pf12a9f2efa\">\n <rect x=\"34.240625\" y=\"37.62\" width=\"111.6\" height=\"22.32\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 22
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.668038302Z",
|
||
"start_time": "2026-05-29T15:19:44.620075434Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"import math\n",
|
||
"class DotProductAttention(nn.Module):\n",
|
||
" \"\"\"缩放点积注意力\"\"\"\n",
|
||
" def __init__(self, dropout, **kwargs):\n",
|
||
" super(DotProductAttention, self).__init__(**kwargs)\n",
|
||
" self.dropout = nn.Dropout(dropout)\n",
|
||
"# queries的形状:(batch_size,查询的个数,d)\n",
|
||
"# keys的形状:(batch_size,“键-值”对的个数,d)\n",
|
||
"# values的形状:(batch_size,“键-值”对的个数,值的维度)\n",
|
||
"# valid_lens的形状:(batch_size,)或者(batch_size,查询的个数)\n",
|
||
" def forward(self, queries, keys, values, valid_lens=None):\n",
|
||
" d = queries.shape[-1]\n",
|
||
" # 设置transpose_b=True为了交换keys的最后两个维度\n",
|
||
" scores = torch.bmm(queries, keys.transpose(1,2)) / math.sqrt(d)\n",
|
||
" self.attention_weights = masked_softmax(scores, valid_lens)\n",
|
||
"\n",
|
||
" return torch.bmm(self.dropout(self.attention_weights), values)"
|
||
],
|
||
"id": "8453c76623a5b435",
|
||
"outputs": [],
|
||
"execution_count": 23
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.754268677Z",
|
||
"start_time": "2026-05-29T15:19:44.668929892Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"queries = torch.normal(0, 1, (2, 1, 2))\n",
|
||
"attention = DotProductAttention(dropout=0.5)\n",
|
||
"attention.eval()\n",
|
||
"attention(queries, keys, values, valid_lens)"
|
||
],
|
||
"id": "8af6b28944977a62",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"tensor([[[ 2.0000, 3.0000, 4.0000, 5.0000]],\n",
|
||
"\n",
|
||
" [[10.0000, 11.0000, 12.0000, 13.0000]]])"
|
||
]
|
||
},
|
||
"execution_count": 24,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 24
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.822905172Z",
|
||
"start_time": "2026-05-29T15:19:44.756082157Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),\n",
|
||
"xlabel='Keys', ylabel='Queries')"
|
||
],
|
||
"id": "28f7e16771076e33",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 250x250 with 2 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"187.07675pt\" height=\"103.438906pt\" viewBox=\"0 0 187.07675 103.438906\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:19:44.802392</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M -0 103.438906 \nL 187.07675 103.438906 \nL 187.07675 0 \nL -0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 34.240625 59.94 \nL 145.840625 59.94 \nL 145.840625 37.62 \nL 34.240625 37.62 \nz\n\"/>\n </g>\n <g clip-path=\"url(#pae18bb7a98)\">\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAJsAAAAfCAYAAADwQL9CAAAAjUlEQVR4nO3aMRHCAAxA0Zau1YcFxmqoCzbMYYGNO+riZ+A9A8nwL1PW7+v8LaS2+zG9wojb9AL8D7GRERsZsZERGxmxkREbGbGRERsZsZERGxmxkREbGbGRERuZ9bHsY/9sz897ajQDXDYyYiMjNjJiIyM2MmIjIzYyYiMjNjJiIyM2MmIjIzYyYiNzAasBCAMqMzMRAAAAAElFTkSuQmCC\" id=\"image443cc5516b\" transform=\"scale(1 -1) translate(0 -22.32)\" x=\"34.240625\" y=\"-37.62\" width=\"111.6\" height=\"22.32\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path id=\"me0fc03e250\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#me0fc03e250\" x=\"39.820625\" y=\"59.94\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(36.639375 74.538438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_2\">\n <g>\n <use xlink:href=\"#me0fc03e250\" x=\"95.620625\" y=\"59.94\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 5 -->\n <g style=\"fill: #ffffff\" transform=\"translate(92.439375 74.538438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n </g>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- Keys -->\n <g style=\"fill: #ffffff\" transform=\"translate(78.371094 88.216563) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \nL 1259 4666 \nL 1259 2694 \nL 3353 4666 \nL 4166 4666 \nL 1850 2491 \nL 4331 0 \nL 3500 0 \nL 1259 2247 \nL 1259 0 \nL 628 0 \nL 628 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \nQ 1816 -950 1584 -1140 \nQ 1353 -1331 966 -1331 \nL 506 -1331 \nL 506 -850 \nL 844 -850 \nQ 1081 -850 1212 -737 \nQ 1344 -625 1503 -206 \nL 1606 56 \nL 191 3500 \nL 800 3500 \nL 1894 763 \nL 2988 3500 \nL 3597 3500 \nL 2059 -325 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-4b\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_3\">\n <defs>\n <path id=\"m550d085c03\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m550d085c03\" x=\"34.240625\" y=\"43.2\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 46.999219) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#m550d085c03\" x=\"34.240625\" y=\"54.36\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 1 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 58.159219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n </g>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- Queries -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 68.087031) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \nQ 1834 4238 1429 3725 \nQ 1025 3213 1025 2328 \nQ 1025 1447 1429 934 \nQ 1834 422 2522 422 \nQ 3209 422 3611 934 \nQ 4013 1447 4013 2328 \nQ 4013 3213 3611 3725 \nQ 3209 4238 2522 4238 \nz\nM 3406 84 \nL 4238 -825 \nL 3475 -825 \nL 2784 -78 \nQ 2681 -84 2626 -87 \nQ 2572 -91 2522 -91 \nQ 1538 -91 948 567 \nQ 359 1225 359 2328 \nQ 359 3434 948 4092 \nQ 1538 4750 2522 4750 \nQ 3503 4750 4090 4092 \nQ 4678 3434 4678 2328 \nQ 4678 1516 4351 937 \nQ 4025 359 3406 84 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-75\" d=\"M 544 1381 \nL 544 3500 \nL 1119 3500 \nL 1119 1403 \nQ 1119 906 1312 657 \nQ 1506 409 1894 409 \nQ 2359 409 2629 706 \nQ 2900 1003 2900 1516 \nL 2900 3500 \nL 3475 3500 \nL 3475 0 \nL 2900 0 \nL 2900 538 \nQ 2691 219 2414 64 \nQ 2138 -91 1772 -91 \nQ 1169 -91 856 284 \nQ 544 659 544 1381 \nz\nM 1991 3584 \nL 1991 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-51\"/>\n <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 34.240625 59.94 \nL 34.240625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 145.840625 59.94 \nL 145.840625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 34.240625 59.94 \nL 145.840625 59.94 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 34.240625 37.62 \nL 145.840625 37.62 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n <g id=\"axes_2\">\n <g id=\"patch_7\">\n <path d=\"M 152.815625 90.36 \nL 156.973625 90.36 \nL 156.973625 7.2 \nL 152.815625 7.2 \nz\n\"/>\n </g>\n <image xlink:href=\"data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAYAAAB0CAYAAACmJkOCAAAAyElEQVR4nM2WSwrEMAxDXcj9zzqbblp/egG/gEII02WEJMt2Qq+6f2XNN6yyO7dhGQQQo1qLFY9ij30AB5Rz6B7uIqNQKkiKAUwuAyRV8e6SmjTxgAcy5An+qTkD+vrQNVgw15sI5qWXi909kLwCpTCgDPgB83dfuXpVFDAD3vakR18H3KEqWJKJVCBAyTEgSukBw2WP9thsJP0zOAEoFcjoz22EUQ5kyFVhwH5BZx4MkBQ2Ee7mhAEjX2E88sxRCluyYg4MquoD0XoQUGMmzEcAAAAASUVORK5CYII=\" id=\"image4e18b80789\" transform=\"scale(1 -1) translate(0 -83.52)\" x=\"152.64\" y=\"-6.48\" width=\"4.32\" height=\"83.52\"/>\n <g id=\"matplotlib.axis_3\"/>\n <g id=\"matplotlib.axis_4\">\n <g id=\"ytick_3\">\n <g id=\"line2d_5\">\n <defs>\n <path id=\"maa9dfdf4b6\" d=\"M 0 0 \nL 3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#maa9dfdf4b6\" x=\"156.973625\" y=\"90.36\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 0.0 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 94.159219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#maa9dfdf4b6\" x=\"156.973625\" y=\"57.096\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 0.2 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 60.895219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_5\">\n <g id=\"line2d_7\">\n <g>\n <use xlink:href=\"#maa9dfdf4b6\" x=\"156.973625\" y=\"23.832\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0.4 -->\n <g style=\"fill: #ffffff\" transform=\"translate(163.973625 27.631219) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n </g>\n </g>\n </g>\n </g>\n <g id=\"LineCollection_1\"/>\n <g id=\"patch_8\">\n <path d=\"M 152.815625 90.36 \nL 154.894625 90.36 \nL 156.973625 90.36 \nL 156.973625 7.2 \nL 154.894625 7.2 \nL 152.815625 7.2 \nL 152.815625 90.36 \nz\n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"pae18bb7a98\">\n <rect x=\"34.240625\" y=\"37.62\" width=\"111.6\" height=\"22.32\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 25
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.874393721Z",
|
||
"start_time": "2026-05-29T15:19:44.824430337Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"class AttentionDecoder(d2l.Decoder):\n",
|
||
" def __init__(self,**kwargs):\n",
|
||
" super(AttentionDecoder, self).__init__(**kwargs)\n",
|
||
" @property\n",
|
||
" def attention_weight(self):\n",
|
||
" raise NotImplementedError"
|
||
],
|
||
"id": "33507bd2e1917a29",
|
||
"outputs": [],
|
||
"execution_count": 26
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.926627628Z",
|
||
"start_time": "2026-05-29T15:19:44.875567483Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"class Seq2SeqAttentionDecoder(AttentionDecoder):\n",
|
||
" def __init__(self,vocab_size,embed_size,num_hiddens,num_layers,dropout=0,**kwargs):\n",
|
||
" super(Seq2SeqAttentionDecoder, self).__init__(**kwargs)\n",
|
||
" self.attention = AdditiveAttention(\n",
|
||
" num_hiddens, num_hiddens, num_hiddens,dropout)\n",
|
||
" self.embedding = nn.Embedding(vocab_size, embed_size)\n",
|
||
" self.rnn = nn.GRU(\n",
|
||
" embed_size + num_hiddens, num_hiddens, num_layers,\n",
|
||
" dropout=dropout)\n",
|
||
" self.dense = nn.Linear(num_hiddens, vocab_size)\n",
|
||
" def init_state(self, enc_outputs, enc_valid_lens, *args):\n",
|
||
"# outputs的形状为(batch_size,num_steps,num_hiddens).\n",
|
||
"# hidden_state的形状为(num_layers,batch_size,num_hiddens)\n",
|
||
" outputs, hidden_state = enc_outputs\n",
|
||
" #print(f\"Encoder outputs shape before permute: {outputs.shape}\") # 应为 (num_steps, batch_size, num_hiddens) 或 (batch_size, num_steps, num_hiddens)\n",
|
||
" enc_outputs_permuted = outputs.permute(1, 0, 2)\n",
|
||
" #print(f\"After permute: {enc_outputs_permuted.shape}\") # 期望 (batch_size, num_steps, num_hiddens)\n",
|
||
" return (enc_outputs_permuted, hidden_state, enc_valid_lens)\n",
|
||
" def forward(self, X, state):\n",
|
||
" # enc_outputs的形状为(batch_size,num_steps,num_hiddens).\n",
|
||
" # hidden_state的形状为(num_layers,batch_size,\n",
|
||
" # num_hiddens)\n",
|
||
" enc_outputs, hidden_state, enc_valid_lens = state\n",
|
||
" # 输出X的形状为(num_steps,batch_size,embed_size)\n",
|
||
" X = self.embedding(X).permute(1, 0, 2)\n",
|
||
" outputs, self._attention_weights = [], []\n",
|
||
" for x in X:\n",
|
||
" # query的形状为(batch_size,1,num_hiddens)\n",
|
||
" query = torch.unsqueeze(hidden_state[-1], dim=1)\n",
|
||
" # context的形状为(batch_size,1,num_hiddens)\n",
|
||
" #print(f\"values shape before attention: {enc_outputs.shape}\") # 应为 (4, 7, 16)\n",
|
||
" context = self.attention(\n",
|
||
" query, enc_outputs, enc_outputs, enc_valid_lens)\n",
|
||
" # 在特征维度上连结\n",
|
||
" x = torch.cat((context, torch.unsqueeze(x, dim=1)), dim=-1)\n",
|
||
" # 将x变形为(1,batch_size,embed_size+num_hiddens)\n",
|
||
" out, hidden_state = self.rnn(x.permute(1, 0, 2), hidden_state)\n",
|
||
" outputs.append(out)\n",
|
||
" self._attention_weights.append(self.attention.attention_weights)\n",
|
||
" # 全连接层变换后,outputs的形状为\n",
|
||
" # (num_steps,batch_size,vocab_size)\n",
|
||
" outputs = self.dense(torch.cat(outputs, dim=0))\n",
|
||
" return outputs.permute(1, 0, 2), [enc_outputs, hidden_state,\n",
|
||
" enc_valid_lens]\n",
|
||
" @property\n",
|
||
" def attention_weights(self):\n",
|
||
" return self._attention_weights"
|
||
],
|
||
"id": "a8a497c9041910a1",
|
||
"outputs": [],
|
||
"execution_count": 27
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:44.996664037Z",
|
||
"start_time": "2026-05-29T15:19:44.927689328Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"encoder = d2l.Seq2SeqEncoder(vocab_size=10, embed_size=8, num_hiddens=16,\n",
|
||
"num_layers=2)\n",
|
||
"encoder.eval()\n",
|
||
"decoder = Seq2SeqAttentionDecoder(vocab_size=10, embed_size=8, num_hiddens=16,\n",
|
||
"num_layers=2)\n",
|
||
"decoder.eval()\n",
|
||
"X = torch.zeros((4, 7), dtype=torch.long) # (batch_size,num_steps)\n",
|
||
"state = decoder.init_state(encoder(X), None)\n",
|
||
"output, state = decoder(X, state)\n",
|
||
"output.shape, len(state), state[0].shape, len(state[1]), state[1][0].shape"
|
||
],
|
||
"id": "b2a6bc735743bd0f",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(torch.Size([4, 7, 10]), 3, torch.Size([4, 7, 16]), 2, torch.Size([4, 16]))"
|
||
]
|
||
},
|
||
"execution_count": 28,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 28
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:19:45.047118759Z",
|
||
"start_time": "2026-05-29T15:19:44.998053092Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": "",
|
||
"id": "4c7bf86095f15c98",
|
||
"outputs": [],
|
||
"execution_count": 28
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:20:14.678359202Z",
|
||
"start_time": "2026-05-29T15:19:45.048442204Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"embed_size, num_hiddens, num_layers, dropout = 32, 32, 2, 0.1\n",
|
||
"batch_size, num_steps = 64, 10\n",
|
||
"lr, num_epochs, device = 0.005, 250, d2l.try_gpu()\n",
|
||
"train_iter, src_vocab, tgt_vocab = d2l.load_data_nmt(batch_size, num_steps)\n",
|
||
"encoder = d2l.Seq2SeqEncoder(\n",
|
||
"len(src_vocab), embed_size, num_hiddens, num_layers, dropout)\n",
|
||
"decoder = Seq2SeqAttentionDecoder(\n",
|
||
"len(tgt_vocab), embed_size, num_hiddens, num_layers, dropout)\n",
|
||
"net = d2l.EncoderDecoder(encoder, decoder)\n",
|
||
"d2l.train_seq2seq(net, train_iter, lr, num_epochs, tgt_vocab, device)"
|
||
],
|
||
"id": "5f5cedf74b97bd12",
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"loss 0.019, 17862.0 tokens/sec on cuda:0\n"
|
||
]
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<Figure size 350x250 with 1 Axes>"
|
||
],
|
||
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"262.1875pt\" height=\"183.35625pt\" viewBox=\"0 0 262.1875 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2026-05-29T23:20:14.649299</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 183.35625 \nL 262.1875 183.35625 \nL 262.1875 0 \nL 0 0 \nz\n\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 50.14375 145.8 \nL 245.44375 145.8 \nL 245.44375 7.2 \nL 50.14375 7.2 \nz\n\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path d=\"M 82.69375 145.8 \nL 82.69375 7.2 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path id=\"me6d087a839\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#me6d087a839\" x=\"82.69375\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 50 -->\n <g style=\"fill: #ffffff\" transform=\"translate(76.33125 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-35\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path d=\"M 123.38125 145.8 \nL 123.38125 7.2 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use xlink:href=\"#me6d087a839\" x=\"123.38125\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 100 -->\n <g style=\"fill: #ffffff\" transform=\"translate(113.8375 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path d=\"M 164.06875 145.8 \nL 164.06875 7.2 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_6\">\n <g>\n <use xlink:href=\"#me6d087a839\" x=\"164.06875\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_3\">\n <!-- 150 -->\n <g style=\"fill: #ffffff\" transform=\"translate(154.525 160.398438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-31\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_4\">\n <g id=\"line2d_7\">\n <path d=\"M 204.75625 145.8 \nL 204.75625 7.2 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_8\">\n <g>\n <use xlink:href=\"#me6d087a839\" x=\"204.75625\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_4\">\n <!-- 200 -->\n <g style=\"fill: #ffffff\" transform=\"translate(195.2125 160.398438) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_5\">\n <g id=\"line2d_9\">\n <path d=\"M 245.44375 145.8 \nL 245.44375 7.2 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_10\">\n <g>\n <use xlink:href=\"#me6d087a839\" x=\"245.44375\" y=\"145.8\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_5\">\n <!-- 250 -->\n <g style=\"fill: #ffffff\" transform=\"translate(235.9 160.398438) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-32\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n </g>\n </g>\n </g>\n <g id=\"text_6\">\n <!-- epoch -->\n <g style=\"fill: #ffffff\" transform=\"translate(132.565625 174.076563) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-65\"/>\n <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\n </g>\n </g>\n </g>\n <g id=\"matplotlib.axis_2\">\n <g id=\"ytick_1\">\n <g id=\"line2d_11\">\n <path d=\"M 50.14375 117.894917 \nL 245.44375 117.894917 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_12\">\n <defs>\n <path id=\"m32ef1fbfc5\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #ffffff; stroke-width: 0.8\"/>\n </defs>\n <g>\n <use xlink:href=\"#m32ef1fbfc5\" x=\"50.14375\" y=\"117.894917\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_7\">\n <!-- 0.05 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 121.694136) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_2\">\n <g id=\"line2d_13\">\n <path d=\"M 50.14375 83.153473 \nL 245.44375 83.153473 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_14\">\n <g>\n <use xlink:href=\"#m32ef1fbfc5\" x=\"50.14375\" y=\"83.153473\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_8\">\n <!-- 0.10 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 86.952691) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_3\">\n <g id=\"line2d_15\">\n <path d=\"M 50.14375 48.412029 \nL 245.44375 48.412029 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_16\">\n <g>\n <use xlink:href=\"#m32ef1fbfc5\" x=\"50.14375\" y=\"48.412029\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_9\">\n <!-- 0.15 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 52.211247) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"ytick_4\">\n <g id=\"line2d_17\">\n <path d=\"M 50.14375 13.670584 \nL 245.44375 13.670584 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linecap: square\"/>\n </g>\n <g id=\"line2d_18\">\n <g>\n <use xlink:href=\"#m32ef1fbfc5\" x=\"50.14375\" y=\"13.670584\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.8\"/>\n </g>\n </g>\n <g id=\"text_10\">\n <!-- 0.20 -->\n <g style=\"fill: #ffffff\" transform=\"translate(20.878125 17.469803) scale(0.1 -0.1)\">\n <use xlink:href=\"#DejaVuSans-30\"/>\n <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n </g>\n </g>\n </g>\n <g id=\"text_11\">\n <!-- loss -->\n <g style=\"fill: #ffffff\" transform=\"translate(14.798437 86.157813) rotate(-90) scale(0.1 -0.1)\">\n <defs>\n <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-6c\"/>\n <use xlink:href=\"#DejaVuSans-6f\" x=\"27.783203\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"88.964844\"/>\n <use xlink:href=\"#DejaVuSans-73\" x=\"141.064453\"/>\n </g>\n </g>\n </g>\n <g id=\"line2d_19\">\n <path d=\"M 50.14375 13.5 \nL 58.28125 62.377216 \nL 66.41875 88.244089 \nL 74.55625 104.555407 \nL 82.69375 115.035219 \nL 90.83125 122.178078 \nL 98.96875 127.027916 \nL 107.10625 129.868108 \nL 115.24375 132.553244 \nL 123.38125 134.41552 \nL 131.51875 135.282212 \nL 139.65625 136.651996 \nL 147.79375 136.918477 \nL 155.93125 137.435732 \nL 164.06875 137.483335 \nL 172.20625 138.061004 \nL 180.34375 138.44064 \nL 188.48125 138.351583 \nL 196.61875 138.597139 \nL 204.75625 138.687442 \nL 212.89375 139.31802 \nL 221.03125 139.187124 \nL 229.16875 139.5 \nL 237.30625 139.126328 \nL 245.44375 139.340138 \n\" clip-path=\"url(#p67feb63f08)\" style=\"fill: none; stroke: #8dd3c7; stroke-width: 1.5; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_3\">\n <path d=\"M 50.14375 145.8 \nL 50.14375 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_4\">\n <path d=\"M 245.44375 145.8 \nL 245.44375 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_5\">\n <path d=\"M 50.14375 145.8 \nL 245.44375 145.8 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n <g id=\"patch_6\">\n <path d=\"M 50.14375 7.2 \nL 245.44375 7.2 \n\" style=\"fill: none; stroke: #ffffff; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n </g>\n </g>\n </g>\n <defs>\n <clipPath id=\"p67feb63f08\">\n <rect x=\"50.14375\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n </clipPath>\n </defs>\n</svg>\n"
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data",
|
||
"jetTransient": {
|
||
"display_id": null
|
||
}
|
||
}
|
||
],
|
||
"execution_count": 29
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:20:14.794039857Z",
|
||
"start_time": "2026-05-29T15:20:14.727727180Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"engs = ['go .', \"i lost .\", 'he\\'s calm .', 'i\\'m home .']\n",
|
||
"fras = ['va !', 'j\\'ai perdu .', 'il est calme .', 'je suis chez moi .']\n",
|
||
"for eng, fra in zip(engs, fras):\n",
|
||
" translation, dec_attention_weight_seq = d2l.predict_seq2seq(\n",
|
||
" net, eng, src_vocab, tgt_vocab, num_steps, device, True)\n",
|
||
" print(f'{eng} => {translation}, ',\n",
|
||
" f'bleu {d2l.bleu(translation, fra, k=2):.3f}')"
|
||
],
|
||
"id": "ddaed8bd284ee01b",
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"go . => va !, bleu 1.000\n",
|
||
"i lost . => j'ai perdu ., bleu 1.000\n",
|
||
"he's calm . => il est <unk> ., bleu 0.658\n",
|
||
"i'm home . => je suis chez moi ., bleu 1.000\n"
|
||
]
|
||
}
|
||
],
|
||
"execution_count": 30
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:20:38.342057516Z",
|
||
"start_time": "2026-05-29T15:20:38.288567783Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"class MultiHeadAttention(nn.Module):\n",
|
||
" def __init__(self, key_size, query_size, value_size, num_hiddens,\n",
|
||
" num_heads, dropout, bias=False, **kwargs):\n",
|
||
" super(MultiHeadAttention, self).__init__(**kwargs)\n",
|
||
" self.num_heads = num_heads\n",
|
||
" self.attention = d2l.DotProductAttention(dropout)\n",
|
||
" self.W_q = nn.Linear(query_size, num_hiddens, bias=bias)\n",
|
||
" self.W_k = nn.Linear(key_size, num_hiddens, bias=bias)\n",
|
||
" self.W_v = nn.Linear(value_size, num_hiddens, bias=bias)\n",
|
||
" self.W_o = nn.Linear(num_hiddens, num_hiddens, bias=bias)\n",
|
||
" def forward(self, queries, keys, values, valid_lens):\n",
|
||
" # 1. 线性投影 + 变换形状以分割多头\n",
|
||
" queries = transpose_qkv(self.W_q(queries), self.num_heads)\n",
|
||
" keys = transpose_qkv(self.W_k(keys), self.num_heads)\n",
|
||
" values = transpose_qkv(self.W_v(values), self.num_heads)\n",
|
||
"\n",
|
||
" # 2. 处理有效长度掩码(valid_lens)以适配多头\n",
|
||
" if valid_lens is not None:\n",
|
||
" valid_lens = torch.repeat_interleave(valid_lens, repeats=self.num_heads, dim=0)\n",
|
||
"\n",
|
||
" # 3. 计算注意力(每个头独立计算)\n",
|
||
" output = self.attention(queries, keys, values, valid_lens)\n",
|
||
"\n",
|
||
" # 4. 合并多头,并通过输出线性层\n",
|
||
" output_concat = transpose_output(output, self.num_heads)\n",
|
||
" return self.W_o(output_concat)\n",
|
||
"def transpose_qkv(X, num_heads):\n",
|
||
" \"\"\"为了多注意力头的并行计算而变换形状\"\"\"\n",
|
||
" # 输入X的形状:(batch_size,查询或者“键-值”对的个数,num_hiddens)\n",
|
||
" # 输出X的形状:(batch_size,查询或者“键-值”对的个数,num_heads,\n",
|
||
" # num_hiddens/num_heads)\n",
|
||
" X = X.reshape(X.shape[0], X.shape[1], num_heads, -1)\n",
|
||
" # 输出X的形状:(batch_size,num_heads,查询或者“键-值”对的个数,\n",
|
||
" # num_hiddens/num_heads)\n",
|
||
" X = X.permute(0, 2, 1, 3)\n",
|
||
" # 最终输出的形状:(batch_size*num_heads,查询或者“键-值”对的个数,\n",
|
||
" # num_hiddens/num_heads)\n",
|
||
" return X.reshape(-1, X.shape[2], X.shape[3])\n",
|
||
"\n",
|
||
"def transpose_output(X, num_heads):\n",
|
||
" \"\"\"逆转transpose_qkv函数的操作\"\"\"\n",
|
||
" X = X.reshape(-1, num_heads, X.shape[1], X.shape[2])\n",
|
||
" X = X.permute(0, 2, 1, 3)\n",
|
||
" return X.reshape(X.shape[0], X.shape[1], -1)\n"
|
||
],
|
||
"id": "13d19f8b5048c74d",
|
||
"outputs": [],
|
||
"execution_count": 32
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:20:39.251763154Z",
|
||
"start_time": "2026-05-29T15:20:39.201715213Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"num_hiddens, num_heads = 100, 5\n",
|
||
"attention = MultiHeadAttention(num_hiddens, num_hiddens, num_hiddens,\n",
|
||
"num_hiddens, num_heads, 0.5)\n",
|
||
"attention.eval()"
|
||
],
|
||
"id": "b25c661a511d7763",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"MultiHeadAttention(\n",
|
||
" (attention): DotProductAttention(\n",
|
||
" (dropout): Dropout(p=0.5, inplace=False)\n",
|
||
" )\n",
|
||
" (W_q): Linear(in_features=100, out_features=100, bias=False)\n",
|
||
" (W_k): Linear(in_features=100, out_features=100, bias=False)\n",
|
||
" (W_v): Linear(in_features=100, out_features=100, bias=False)\n",
|
||
" (W_o): Linear(in_features=100, out_features=100, bias=False)\n",
|
||
")"
|
||
]
|
||
},
|
||
"execution_count": 33,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 33
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-05-29T15:20:40.455647106Z",
|
||
"start_time": "2026-05-29T15:20:40.307682855Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"batch_size, num_queries = 2, 4\n",
|
||
"num_kvpairs, valid_lens = 6, torch.tensor([3, 2])\n",
|
||
"X = torch.ones((batch_size, num_queries, num_hiddens))\n",
|
||
"Y = torch.ones((batch_size, num_kvpairs, num_hiddens))\n",
|
||
"attention(X, Y, Y, valid_lens).shape"
|
||
],
|
||
"id": "49877c929741ec94",
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"torch.Size([2, 4, 100])"
|
||
]
|
||
},
|
||
"execution_count": 34,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"execution_count": 34
|
||
},
|
||
{
|
||
"metadata": {},
|
||
"cell_type": "code",
|
||
"outputs": [],
|
||
"execution_count": null,
|
||
"source": "",
|
||
"id": "b8a10576c7789750"
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 2
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython2",
|
||
"version": "2.7.6"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|