{"id":195,"date":"2026-10-11T18:41:00","date_gmt":"2026-10-11T10:41:00","guid":{"rendered":"https:\/\/99website.top\/blog\/?p=195"},"modified":"2026-10-11T18:41:00","modified_gmt":"2026-10-11T10:41:00","slug":"attention-is-all-you-need-3%ef%bc%9a%e7%a5%9e%e5%a5%87%e5%8f%88%e9%87%8d%e8%a6%81%e7%9a%84mlp%e5%88%9d%e5%a7%8b%e5%8c%96","status":"publish","type":"post","link":"https:\/\/99website.top\/blog\/?p=195","title":{"rendered":"Attention Is All You Need &#8211; #3\uff1a\u795e\u5947\u53c8\u91cd\u8981\u7684MLP\u521d\u59cb\u5316"},"content":{"rendered":"\n<h1>Attention Is All You Need #3: \u795e\u5947\u53c8\u91cd\u8981\u7684\u521d\u59cb\u5316<\/h1>\n<p>\u6b22\u8fce\u56de\u6765~\u4eca\u5929\u4f5c\u4e1a\u90fd\u5199\u5b8c\u5566~\u6765\u5b66\u4e00\u4e2a\u5c0f\u65f6\uff0c\u4e0d\u8bba\u6700\u5f00\u59cb\u768499mlp\u8fd8\u662f\u4e0a\u7bc7\u535a\u5ba2\u6240\u4fee\u6539\u7684\u77e9\u9635\u7248\uff0c\u90fd\u6709\u8bad\u7ec3\u5931\u8d25\u7684\u95ee\u9898\uff0cGPT \u63d0\u51fa\uff0c\u6743\u91cd\u521d\u59cb\u5316\u53ef\u80fd\u662f\u91cd\u8981\u539f\u56e0\u4e4b\u4e00\uff0c\u8fd9\u7bc7\u535a\u5ba2\u6211\u4eec\u5c31\u6765\u7814\u7a76\u5b83\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u968f\u673a\u521d\u59cb\u5316\u6743\u91cd\u7684\u6570\u503c\uff0c\u6709\u4ec0\u4e48\u95ee\u9898\u5462\uff1f<\/p>\n<h2>\u968f\u673a\u521d\u59cb\u5316\u5230\u5e95\u6709\u4ec0\u4e48\u95ee\u9898\uff1f<\/h2>\n<p>\u6765\u770b\u521d\u59cb\u5316\u6743\u91cd<span class=\"katex math inline\">W<\/span>\u77e9\u9635\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">self.W = np.random.randn(neuron_num, weights_num)\n<\/code><\/pre>\n<p>GPT\u8bf4<code>np.random.randn<\/code>\u751f\u6210\u7684\u662f\u670d\u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570\uff1a<\/p>\n<div class=\"katex math multi-line\">\nW_{ij}\\sim \\mathcal N(0,1)\n<\/div>\n<p>\u5929\u554a\u8fd9\u4e2a<span class=\"katex math inline\">\\mathcal N(0,1)<\/span>\u662f\u5565\u554a\u545c\u545c\uff0c\u5feb\u6765\u67e5\u67e5<\/p>\n<p>\u5b83\u7684\u610f\u601d\u662f\uff1a\u968f\u673a\u53d8\u91cf <span class=\"katex math inline\">X<\/span> \u670d\u4ece\u5747\u503c\u4e3a 0\u3001\u65b9\u5dee\u4e3a 1 \u7684\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<p>\u54b1\u4eec\u62c6\u5f00\u770b\uff1a<\/p>\n<ul>\n<li><span class=\"katex math inline\">\\mathcal N<\/span>\uff1aNormal Distribution\uff0c\u6b63\u6001\u5206\u5e03\u3002<\/li>\n<li><span class=\"katex math inline\">0<\/span>\uff1a\u5e73\u5747\u503c <span class=\"katex math inline\">\\mu=0<\/span>\uff0c\u968f\u673a\u6570\u4e3b\u8981\u96c6\u4e2d\u5728 0 \u9644\u8fd1\u3002<\/li>\n<li><span class=\"katex math inline\">1<\/span>\uff1a\u65b9\u5dee <span class=\"katex math inline\">\\sigma^2=1<\/span>\uff0c\u56e0\u6b64\u6807\u51c6\u5dee <span class=\"katex math inline\">\\sigma=1<\/span>\u3002<\/li>\n<li><span class=\"katex math inline\">\\sim<\/span>\uff1a\u8868\u793a\u300c\u670d\u4ece\u67d0\u79cd\u5206\u5e03\u300d\u3002<\/li>\n<\/ul>\n<p>\u6b63\u6001\u5206\u5e03\u53c8\u662f\u5565\uff1f<\/p>\n<blockquote>\n<p>\u6b63\u6001\u5206\u5e03\u662f\u4e00\u79cd\u8fde\u7eed\u6982\u7387\u5206\u5e03\uff0c\u5176\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\u5448\u5bf9\u79f0\u7684\u949f\u5f62\u66f2\u7ebf\uff0c\u5e7f\u6cdb\u7528\u4e8e\u63cf\u8ff0\u81ea\u7136\u548c\u793e\u4f1a\u73b0\u8c61\u7684\u6570\u636e\u5206\u5e03\u3002<\/p>\n<\/blockquote>\n<p>\u4eba\u8bdd\u8bb2\uff0c<strong>\u6b63\u6001\u5206\u5e03\uff0c\u5c31\u662f\u4e00\u79cd\u300c\u4e2d\u95f4\u51fa\u73b0\u5f97\u591a\uff0c\u4e24\u8fb9\u51fa\u73b0\u5f97\u5c11\uff0c\u800c\u4e14\u5de6\u53f3\u5bf9\u79f0\u300d\u7684\u968f\u673a\u6570\u5206\u5e03\u89c4\u5f8b\u3002<\/strong><\/p>\n<h2>\u4e3e\u4e2a\u4f8b\u5b50 \ud83c\udf1f<\/h2>\n<p>\u5047\u8bbe\u6211\u4eec\u6d4b\u91cf\u5f88\u591a\u4eba\u7684\u8eab\u9ad8\uff1a<\/p>\n<ul>\n<li>\u8eab\u9ad8 170cm \u5de6\u53f3\u7684\u4eba\u6bd4\u8f83\u591a\u3002<\/li>\n<li>\u8eab\u9ad8 160cm\u3001180cm \u7684\u4eba\u76f8\u5bf9\u5c11\u4e00\u4e9b\u3002<\/li>\n<li>\u8eab\u9ad8 140cm\u3001200cm \u7684\u4eba\u5c31\u66f4\u5c11\u4e86\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u8fd9\u4e9b\u8eab\u9ad8\u8fd1\u4f3c\u670d\u4ece\u6b63\u6001\u5206\u5e03\uff0c\u753b\u51fa\u6765\u5c31\u662f\u4e00\u6761\u50cf\u5c0f\u5c71\u4e00\u6837\u7684\u66f2\u7ebf\uff01<\/p>\n<p><img alt=\"desmos-graph\" src=\"https:\/\/99website.top\/blog\/wp-content\/themes\/Kizumi\/assets\/images\/loading.gif\" data-src=\"https:\/\/99website.top\/blog\/wp-content\/uploads\/2026\/10\/99blog-be9cbcaaa7c6ffc5fe62.svg\" class=\"lazy\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u6761\u66f2\u7ebf\u53eb\u505a\u6b63\u6001\u5206\u5e03\u66f2\u7ebf\uff0c\u53c8\u53eb\u300c\u949f\u5f62\u66f2\u7ebf\u300d\u3002<\/p>\n<p><strong>\u6807\u51c6\u6b63\u6001\u5206\u5e03<\/strong>\u51fd\u6570\u89e3\u6790\u5f0f\uff1a<\/p>\n<div class=\"katex math multi-line\">\nf(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-x^2\/2}\n<\/div>\n<p>\u554a\uff0c\u770b\u8d77\u6765\u597d\u590d\u6742\uff0c\u4e0d\u8fc7\u8fd9\u4e2a\u5f0f\u5b50\u73b0\u5728\u53ef\u4ee5\u5148\u4e0d\u7406\u89e3~\u53ea\u8981\u77e5\u9053<\/p>\n<div class=\"katex math multi-line\">\nX\\sim\\mathcal N(0,1)\n<\/div>\n<p>\u8868\u793a\u4ece\u300c\u5747\u503c 0\u3001\u65b9\u5dee 1\u300d\u7684\u6b63\u6001\u5206\u5e03\u4e2d\u968f\u673a\u53d6\u6570\u3002\u5c31\u53ef\u4ee5\u5566<\/p>\n<p>\u95ee\u9898\u662f\uff0c\u5047\u8bbe\u5c06\u6765\u6709\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u795e\u7ecf\u7f51\u7edc\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">Layer(100, 100)\n<\/code><\/pre>\n<p>\u6bcf\u4e00\u4e2a\u795e\u7ecf\u5143\u90fd\u6709100\u4e2a\u8f93\u5165\uff01\u6211\u561e\u4e2a\u53bb<\/p>\n<p>\u6309\u7167\u4e4b\u524d\u7684\u7b14\u8bb0\uff0c\u4e00\u4e2a\u795e\u7ecf\u5143\u5728\u7ecf\u8fc7\u6fc0\u6d3b\u51fd\u6570\u4e4b\u524d\u8ba1\u7b97\uff1a<\/p>\n<div class=\"katex math multi-line\">\nz=w_1x_1+w_2x_2+\\cdots+w_{100}x_{100}+b\n<\/div>\n<p>\u5047\u8bbe\u8fd9100\u4e2a\u8f93\u5165\u90fd\u5177\u6709\u5e73\u5747\u65700\uff0c\u65b9\u5dee1\uff0c\u5e76\u4e14\u76f8\u4e92\u72ec\u7acb\uff0c\u6743\u91cd\u4e5f\u72ec\u7acb\u968f\u673a\u521d\u59cb\u5316<\/p>\n<p>\u6839\u636e\u65b9\u5dee\u7684\u6027\u8d28\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(A+B)=\\operatorname{Var}(A)+\\operatorname{Var}(B)\n<\/div>\n<p>\u5f53\u5404\u9879\u76f8\u4e92\u72ec\u7acb\u65f6\u6210\u7acb\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u5c31\u80fd\u7b97\u51fa\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z)\n=100\\operatorname{Var}(w_ix_i)\n<\/div>\n<p>Var\u53c8\u662f\u5565\uff01\uff1f<\/p>\n<p>\u554a\uff0c\u539f\u6765Var\u5c31\u662f\u65b9\u5dee\u7684\u6982\u7387\u8bba\u5199\u6cd5\uff0c\u5176\u5b9e\u548c\u9ad8\u4e2d\u6570\u5b66\u91cc\u7684\u65b9\u5dee\u5dee\u4e0d\u591a\uff0c\u4f46\u662f\u4e0d\u5b8c\u5168\u4e00\u6837<\/p>\n<p>\u9ad8\u4e2d\u6570\u5b66\u7684\u65b9\u5dee\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{s^2=\\frac{1}{n}\\sum_{i=1}^{n}(x_i-\\bar{x})^2}\n<\/div>\n<p>\u6982\u7387\u8bba\u65b9\u5dee\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(X)=E[(X-E[X])^2]}\n<\/div>\n<p>\u6982\u7387\u8bba\u65b9\u5dee\u8fd9\u4e2a\u516c\u5f0f\u672c\u8d28\u4e0a\u5c31\u662f\u9ad8\u4e2d\u7684\u65b9\u5dee\u516c\u5f0f\uff0c\u53ea\u4e0d\u8fc7\u628a<strong>\u7b97\u6570\u5e73\u5747<\/strong>\u63a8\u5e7f\u6210\u4e86<strong>\u6309\u7167\u6982\u7387\u6c42\u5e73\u5747<\/strong><\/p>\n<h4><span class=\"katex math inline\">E[X]<\/span>\u662f\u5565\uff1f<\/h4>\n<p><span class=\"katex math inline\">E<\/span> \u662f\u82f1\u6587 Expectation\uff08\u671f\u671b\uff09\u7684\u7f29\u5199<\/p>\n<div class=\"katex math multi-line\">\nE[X]\n<\/div>\n<p>\u610f\u601d\u662f\uff1a<strong>\u968f\u673a\u53d8\u91cf<span class=\"katex math inline\">X<\/span>\u7684\u671f\u671b\u503c<\/strong>\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\u5c31\u597d\u61c2\u591a\u5566<\/p>\n<p>\u5047\u8bbe\u4e00\u4e2a\u968f\u673a\u53d8\u91cf <span class=\"katex math inline\">X<\/span>\uff0c\u53ea\u6709\u4e09\u79cd\u53ef\u80fd\u7684\u7ed3\u679c\uff1a<\/p>\n<div class=\"table-responsive\"><table class=\"table\">\n<thead>\n<tr>\n<th><span class=\"katex math inline\">X<\/span> \u7684\u503c<\/th>\n<th>\u51fa\u73b0\u6982\u7387<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>25%<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>50%<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>25%<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u90a3\u4e48\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\nE[X] &amp;= 1\\times0.25+2\\times0.5+3\\times0.25\\\\\n&amp;= 0.25+1+0.75\\\\\n&amp;= \\boxed{2}\n\\end{aligned}\n<\/div>\n<p>\u6240\u4ee5\u671f\u671b\u5176\u5b9e\u5c31\u662f\u4e00\u79cd<strong>\u52a0\u6743\u5e73\u5747\u6570<\/strong><\/p>\n<p>\u800c\u9ad8\u4e2d\u7684\u666e\u901a\u5e73\u5747\u6570\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\bar x=\\frac{x_1+x_2+\\cdots+x_n}{n}\n<\/div>\n<p>\u5176\u5b9e\u5c31\u662f\u76f8\u5f53\u4e8e\u6bcf\u4e2a\u6570\u636e\u7684\u6743\u91cd\u90fd\u662f<span class=\"katex math inline\">\\frac1n<\/span><\/p>\n<h4>X-E[X]<\/h4>\n<p>\u524d\u9762\u5df2\u7ecf\u6709\u4e86\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[X] = 2\n<\/div>\n<p>\u6240\u4ee5<\/p>\n<div class=\"katex math multi-line\">\nX-E[X] = X &#8211; 2\n<\/div>\n<p>\u5b83\u8868\u793a\u968f\u673a\u53d8\u91cf <span class=\"katex math inline\">X<\/span> \u504f\u79fb\u5e73\u5747\u503c\u591a\u5c11<\/p>\n<div class=\"table-responsive\"><table class=\"table\">\n<thead>\n<tr>\n<th><span class=\"katex math inline\">X<\/span><\/th>\n<th><span class=\"katex math inline\">X-E[X]<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>-1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u8bf6\uff1f\u8fd9\u4e2a\u597d\u50cf\u5c31\u662f\u9ad8\u4e2d\u65b9\u5dee\u91cc\u9762\u7684<\/p>\n<div class=\"katex math multi-line\">\nx_i-\\bar x\n<\/div>\n<p><strong>\u4e00\u6a21\u4e00\u6837\u7684\u601d\u60f3\uff01<\/strong><\/p>\n<p>\u4e4b\u540e\u8ddf\u9ad8\u4e2d\u65b9\u5dee\u4e00\u6837\uff0c\u5e73\u65b9<\/p>\n<div class=\"katex math multi-line\">\n(X-E[X])^2\n<\/div>\n<p>\u5f97\u5230\u4e86<\/p>\n<div class=\"table-responsive\"><table class=\"table\">\n<thead>\n<tr>\n<th><span class=\"katex math inline\">X<\/span><\/th>\n<th>\u504f\u5dee<\/th>\n<th>\u504f\u5dee\u5e73\u65b9<\/th>\n<th>\u51fa\u73b0\u6982\u7387<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>-1<\/td>\n<td>1<\/td>\n<td>25%<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>50%<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>25%<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u8fd9\u6837\uff0c\u8ddd\u79bb\u5e73\u5747\u503c\u8d8a\u8fdc\uff0c\u5e73\u65b9\u504f\u5dee\u5c31\u8d8a\u5927\u3002<\/p>\n<p><strong>\u6700\u5173\u952e\u7684\u4e00\u6b65\uff01\u4e3a\u4ec0\u4e48\u5916\u9762\u8fd8\u6709\u4e2aE?<\/strong><\/p>\n<div class=\"katex math multi-line\">\n\\underbrace{E}_{\\text{\u53d6\u671f\u671b}}\\left[\n\\underbrace{(X-E[X])^2}_{\\text{\u504f\u5dee\u5e73\u65b9}}\n\\right]\n<\/div>\n<p>\u91cc\u9762\u7684 <span class=\"katex math inline\">E[X]<\/span> \u662f\u5148\u6c42 <span class=\"katex math inline\">X<\/span> \u7684\u5e73\u5747\u503c\u3002<\/p>\n<p>\u5916\u9762\u7684 <span class=\"katex math inline\">E[\\ ]<\/span> <strong>\u5219\u662f\u5bf9\u504f\u5dee\u5e73\u65b9\u518d\u6c42\u4e00\u6b21\u52a0\u6743\u5e73\u5747\u503c\u3002<\/strong><\/p>\n<p>\u4e5f\u5c31\u8ddf\u9ad8\u4e2d\u65b9\u5dee\u6700\u540e\u9664\u4ee5n\u7684\u4f5c\u7528\u76f8\u540c\uff0c\u53ea\u4e0d\u8fc7\u9ad8\u4e2d\u65b9\u5dee\u7684\u6743\u91cd\u90fd\u662f<span class=\"katex math inline\">\\frac1n<\/span><\/p>\n<p><strong>\u4f8b\u9898\uff01<\/strong><\/p>\n<p>\u5982\u679c\u76d2\u5b50\u91cc\u6709 10 \u4e2a\u7403\uff0c\u5176\u4e2d 7 \u4e2a\u5199\u7740\u6570\u5b57 1\uff0c3 \u4e2a\u5199\u7740\u6570\u5b57 5\uff0c\u6bcf\u4e2a\u7403\u88ab\u62bd\u4e2d\u7684\u53ef\u80fd\u6027\u76f8\u540c\u3002<\/p>\n<p>\u90a3\u4e48\uff1a<\/p>\n<div class=\"katex math multi-line\">\nP(X=1)=? \n<\/div>\n<div class=\"katex math multi-line\">\nP(X=5)=?\n<\/div>\n<div class=\"katex math multi-line\">\nE[X]=? \n<\/div>\n<p>\u7b97\u7b97\u770b\uff1a<\/p>\n<div class=\"katex math multi-line\">\nP(X=1) = \\frac7{10}\n<\/div>\n<div class=\"katex math multi-line\">\nP(X=5) = \\frac3{10}\n<\/div>\n<div class=\"katex math multi-line\">\nE[X] = \\frac{7}{10}\\times1+\\frac{3}{10}\\times5 = \\frac{22}{10}\n<\/div>\n<p>\u597d\u8036\uff01\u5c31\u662f\u8fd9\u6837\uff01<\/p>\n<p>\u90a3\u4e48\u8fd9\u4e2a\u4f8b\u5b50\u7684\u65b9\u5dee\u5c31\u662f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\n\\operatorname{Var}(X)\n&amp;=E[(X-E[X])^2]\\\\\n&amp;=E[(X-2.2)^2]\\\\\n&amp;=0.7(1-2.2)^2+0.3(5-2.2)^2\\\\\n&amp;=0.7\\times1.44+0.3\\times7.84\\\\\n&amp;=\\boxed{3.36}\n\\end{aligned}\n<\/div>\n<p>\u8fd9\u5c31\u662f\u6982\u7387\u65b9\u5dee\u548c\u7b97\u6570\u65b9\u5dee\u7684\u533a\u522b\u5566~<\/p>\n<p>\u518d\u6765\u8bf4\u8bf4\u65b9\u5dee\u7684\u52a0\u6cd5\u6027\u8d28\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(A+B)=\\operatorname{Var}(A)+\\operatorname{Var}(B)}\n<\/div>\n<p>\u5982\u4f55\u63a8\u5bfc\u8fd9\u4e2a\u5f0f\u5b50\u5462\uff1f<\/p>\n<p>\u54b1\u4eec\u5047\u8bbe<\/p>\n<div class=\"katex math multi-line\">\nE[A]=\\mu_A,\\qquad E[B]=\\mu_B\n<\/div>\n<p>\u5176\u4e2d<span class=\"katex math inline\">A<\/span>\uff0c<span class=\"katex math inline\">B<\/span>\u662f\u968f\u673a\u53d8\u91cf<\/p>\n<p>\u6839\u636e\u65b9\u5dee\u5b9a\u4e49\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(A+B)\n=E[((A+B)-E[A+B])^2]\n<\/div>\n<p>\u56e0\u4e3a\u671f\u671b\u5177\u6709\u7ebf\u6027\u6027\u8d28\uff1a<\/p>\n<p>\u6240\u4ee5\u6709\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[A+B]=E[A]+E[B]=\\mu_A+\\mu_B\n<\/div>\n<p>\u4ee3\u5165\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned} \\operatorname{Var}(A+B) &amp;=E[(A+B-\\mu_A-\\mu_B)^2]\\\\ &amp;=E[((A-\\mu_A)+(B-\\mu_B))^2] \\end{aligned}\n<\/div>\n<p>\u5c55\u5f00\u5e73\u65b9\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned} &amp;=E[(A-\\mu_A)^2]\\\\ &amp;\\quad+2E[(A-\\mu_A)(B-\\mu_B)]\\\\ &amp;\\quad+E[(B-\\mu_B)^2] \\end{aligned}\n<\/div>\n<p>\u91cd\u70b9\u6765\u4e86\uff01<\/p>\n<div class=\"katex math multi-line\">\nE[A-\\mu_A]=E[A]-E[\\mu_A]\\\\\nE[B-\\mu_B]=E[B]-E[\\mu_B]\n<\/div>\n<p>\u53c8\u56e0\u4e3a<strong>\u5e38\u6570\u7684\u671f\u671b\u503c\u7b49\u4e8e\u5b83\u672c\u8eab\uff01<\/strong><\/p>\n<p>\u6240\u4ee5<\/p>\n<div class=\"katex math multi-line\">\nE[A-\\mu_A]=E[A]-E[\\mu_A]=E[A]-\\mu_A = 0\\\\\nE[B-\\mu_B]=E[B]-E[\\mu_B]=E[B]-\\mu_B = 0\n<\/div>\n<p>\u56e0\u4e3a <span class=\"katex math inline\">A<\/span>\u3001<span class=\"katex math inline\">B<\/span> \u76f8\u4e92\u72ec\u7acb\uff1a<\/p>\n<p>\u5219\u6709\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned} &amp;E[(A-\\mu_A)(B-\\mu_B)]\\\\ &amp;=E[A-\\mu_A]\\cdot E[B-\\mu_B]\\\\ &amp;=0\\times0=0 \\end{aligned}\n<\/div>\n<p>\u6240\u4ee5\u6700\u540e\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned} &amp;=E[(A-\\mu_A)^2]\\\\ &amp;\\quad+0\\\\ &amp;\\quad+E[(B-\\mu_B)^2] \\end{aligned}\n<\/div>\n<p>\u5373\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(A+B) = \\operatorname{Var}(A) + \\operatorname{Var}(B)\n<\/div>\n<hr>\n<p>\u7ee7\u7eed\u56de\u5230\u521a\u624d\u7684\u516c\u5f0f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z)\n=100\\operatorname{Var}(w_ix_i)\n<\/div>\n<p>\u56e0\u4e3a <span class=\"katex math inline\">w_i,x_i<\/span> \u72ec\u7acb\u3001\u5747\u503c\u5747\u4e3a 0\u3001\u65b9\u5dee\u5747\u4e3a 1\uff0c\u6240\u4ee5 <\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(w_ix_i)=E[w_i^2]E[x_i^2]=1\n<\/div>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z) = 100\n<\/div>\n<p>\u4e5f\u5c31\u662f\u8bf4\u6807\u51c6\u5dee\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\sigma_z=\\sqrt{100}=10\n<\/div>\n<p><strong>\u54c7\uff01\u6bcf\u4e2a\u6743\u91cd\u7684\u6807\u51c6\u5dee\u53ea\u6709 1\uff0c\u4f46\u662f\u52a0\u8d77\u6765\u4e4b\u540e\uff0cz \u7684\u6807\u51c6\u5dee\u5c45\u7136\u53d8\u6210 10 \u4e86\uff01<\/strong><\/p>\n<p>\u8fd9\u5c31\u53ef\u80fd\u5bfc\u81f4\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u524d\u5411\u4f20\u64ad\u65f6\uff0c\u6570\u503c\u7684\u5c3a\u5ea6\u968f\u7740\u7f51\u7edc\u5c42\u6570\u53d1\u751f\u660e\u663e\u53d8\u5316\u3002<\/li>\n<li>\u53cd\u5411\u4f20\u64ad\u65f6\uff0c\u68af\u5ea6\u53ef\u80fd\u8d8a\u6765\u8d8a\u5927\u6216\u8d8a\u6765\u8d8a\u5c0f\u3002<\/li>\n<\/ul>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u5bfc\u81f4\u8fd9\u4e24\u4e2a\u95ee\u9898\u5462\uff1f<\/p>\n<p>\u54b1\u4eec\u8981\u6293\u4f4f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u4e8b\u5b9e\uff1a<\/p>\n<p><strong>\u7b2c\u4e00\u5c42\u653e\u5927\u7684\u6570\u503c\uff0c\u4e0d\u4f1a\u51ed\u7a7a\u6d88\u5931\uff0c\u800c\u662f\u4f1a\u7ee7\u7eed\u8fdb\u5165\u7b2c\u4e8c\u5c42\u3002<\/strong><\/p>\n<p>\u5148\u8003\u8651\u4e00\u4e2a\u6ca1\u6709\u6fc0\u6d3b\u51fd\u6570\u7684\u7b80\u5316\u7f51\u7edc\uff0c\u6bcf\u4e2a\u795e\u7ecf\u5143\u90fd\u6709 100 \u4e2a\u8f93\u5165\uff0c\u6743\u91cd\u72ec\u7acb\u3001\u5747\u503c\u4e3a 0\u3001\u65b9\u5dee\u4e3a 1\u3002<\/p>\n<div class=\"table-responsive\"><table class=\"table\">\n<thead>\n<tr>\n<th>\u5c42\u6570<\/th>\n<th>\u6fc0\u6d3b\u524d\u8f93\u51fa\u65b9\u5dee<\/th>\n<th>\u6807\u51c6\u5dee<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7b2c\u4e00\u5c42<\/td>\n<td>100<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c\u4e8c\u5c42<\/td>\n<td>10,000<\/td>\n<td>100<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c\u4e09\u5c42<\/td>\n<td>1,000,000<\/td>\n<td>1,000<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\u5462\uff1f<\/p>\n<p>\u56e0\u4e3a\u7b2c\u4e00\u5c42<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z_1)=100\\times1=100\n<\/div>\n<p>\u7b2c\u4e8c\u5c42\u63a5\u6536\u7684\u662f\u7b2c\u4e00\u5c42\u7684\u8f93\u51fa <span class=\"katex math inline\">z_1<\/span>\u3002\u7531\u4e8e\u7b2c\u4e00\u5c42\u8f93\u51fa\u7684\u65b9\u5dee\u5df2\u7ecf\u53d8\u6210 100\uff0c\u56e0\u6b64\u7b2c\u4e8c\u5c42\u7684\u8f93\u5165\u65b9\u5dee\u4e5f\u662f 100\u3002<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z_2)=100\\times100=10000\n<\/div>\n<p>\u7b2c\u4e09\u5c42\u7ee7\u7eed\u4e58\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z_3)=100\\times10000=1000000\n<\/div>\n<p>\u8fd9\u4e2a\u6570\u5b57\u589e\u957f\u7684\u901f\u5ea6\u7b80\u76f4\u5c31\u662f\u7206\u70b8\u5f0f\u589e\u957f<\/p>\n<p>\u800c\u4e14<strong>\u7f51\u7edc\u8d8a\u6df1\uff0c\u6570\u503c\u5c3a\u5ea6\u5c31\u53ef\u80fd\u589e\u957f\u5f97\u8d8a\u5938\u5f20\u3002<\/strong><\/p>\n<p>\u5f53\u7136\uff0c\u8fd9\u4e2a\u8868\u662f\u6ca1\u6709\u6fc0\u6d3b\u51fd\u6570\u7684\u7b80\u5316\u63a8\u5bfc\u3002\u73b0\u6709\u7684 ReLU \u7f51\u7edc\u5e76\u4e0d\u4f1a\u4e25\u683c\u6309\u7167\u8fd9\u4e2a\u8868\u589e\u957f\uff0c\u4f46\u5728\u8fd9\u4e9b\u968f\u673a\u521d\u59cb\u5316\u5047\u8bbe\u4e0b\uff0c\u4fe1\u53f7\u7684\u5e73\u65b9\u5747\u503c\u4ecd\u53ef\u80fd\u6bcf\u5c42\u7ea6\u653e\u5927 50 \u500d\u3002<\/p>\n<p>\u5f53\u6570\u503c\u8d8a\u6765\u8d8a\u5927\u65f6\uff0c\u8bad\u7ec3\u4e2d\u7684\u6fc0\u6d3b\u503c\u3001\u635f\u5931\u503c\u4ee5\u53ca\u67d0\u4e9b\u8ba1\u7b97\u7ed3\u679c\u5c31\u53ef\u80fd\u53d8\u5f97\u975e\u5e38\u5927\uff0c\u9020\u6210\u6570\u503c\u4e0d\u7a33\u5b9a\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u68af\u5ea6\u4e5f\u4f1a\u8d8a\u6765\u8d8a\u5927\u6216\u8005\u8d8a\u6765\u8d8a\u5c0f\u5462\uff1f<\/p>\n<p>\u5148\u8003\u8651\u6700\u7b80\u5355\u7684\u4e00\u4e2a\u795e\u7ecf\u5143\u4e14\u5ffd\u7565\u6fc0\u6d3b\u51fd\u6570\uff1a<\/p>\n<div class=\"katex math multi-line\">\nz=wx\n<\/div>\n<p>\u5047\u8bbe\u635f\u5931\u51fd\u6570\u662f <span class=\"katex math inline\">L<\/span>\u3002<\/p>\n<p>\u6839\u636e\u94fe\u5f0f\u6cd5\u5219\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial z}\\cdot w}\n<\/div>\n<p>\u53d1\u73b0\u4e86\u5417\uff1f<\/p>\n<p><strong>\u68af\u5ea6\u53cd\u5411\u4f20\u9012\u7684\u65f6\u5019\uff0c\u4f1a\u5411\u4e0a\u4e58\u4ee5\u6743\u91cd\uff01<\/strong><\/p>\n<p>\u5047\u5982\u8fde\u7eed\u4e09\u5c42\u7684\u6743\u91cd\u90fd\u662f2\uff0c\u90a3\u4e48\u53cd\u5411\u4f20\u64ad\u7684\u68af\u5ea6\u5230\u6700\u540e\u5c31\u662f8<\/p>\n<p>\u5047\u5982\u90fd\u662f0.5\uff0c\u90a3\u68af\u5ea6\u4f20\u5230\u6700\u540e\u5c31\u662f0.125<\/p>\n<p>\u6240\u4ee5\u5373\u4f7f\u6709\u6fc0\u6d3b\u51fd\u6570\uff0c\u53cd\u5411\u4f20\u64ad\u4e5f\u4f1a\u8fdb\u884c\u53cd\u590d\u4e58\u6cd5\u8fd0\u7b97\uff0c\u68af\u5ea6\u7684\u5c3a\u5ea6\u5c31\u6709\u53ef\u80fd\u53d1\u751f\u5267\u70c8\u53d8\u5316\uff0c\u5c24\u5176\u662f Sigmoid\uff0c\u5982\u679c\u8f93\u5165\u7279\u522b\u5927\u6216\u8005\u7279\u522b\u5c0f\uff0c\u5c31\u5f88\u5bb9\u6613\u8fdb\u5165\u5bfc\u6570\u63a5\u8fd1\u96f6\u7684\u9971\u548c\u533a\u57df\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u6bcf\u4e2a\u795e\u7ecf\u5143\u63a5\u6536\u7684\u8f93\u5165\u6570\u91cf\uff0c\u5408\u7406\u63a7\u5236\u521d\u59cb\u6743\u91cd\u7684\u5927\u5c0f\uff0c\u4ece\u800c\u964d\u4f4e\u524d\u5411\u4fe1\u53f7\u548c\u53cd\u5411\u68af\u5ea6\u8fc7\u5ea6\u653e\u5927\u6216\u7f29\u5c0f\u7684\u98ce\u9669\u3002<\/p>\n<h4>fan_in\u3001fan_out<\/h4>\n<p><code>fan_in<\/code> \u5c31\u662f\u4e00\u4e2a\u795e\u7ecf\u5143\u63a5\u6536\u7684\u8f93\u5165\u8fde\u63a5\u6570\u91cf\u3002<\/p>\n<p><code>fan_out<\/code>\u5c31\u662f\u4e00\u4e2a\u8fd9\u4e00\u5c42\u6709\u591a\u5c11\u8f93\u51fa\u795e\u7ecf\u5143<\/p>\n<p>GPT\u7684\u5c0f\u6d4b\u8bd5~<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u4f7f\u7528 Leaky ReLU\uff0c\u4e0b\u9762\u6709\u4e24\u4e2a\u795e\u7ecf\u7f51\u7edc\u5c42\uff1a<\/p>\n<p>A \u5c42<\/p>\n<p><strong>100 \u00d7 2<\/strong><\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">Layer(100, 2)\n<\/code><\/pre>\n<p>B \u5c42<\/p>\n<p><strong>2 \u00d7 100<\/strong><\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">Layer(2, 100)\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u907f\u514d\u524d\u5411\u4f20\u64ad\u6570\u503c\u8fc7\u5927\uff0c\u4f60\u89c9\u5f97\u54ea\u4e00\u5c42\u5e94\u8be5\u521d\u59cb\u5316\u5f97\u66f4\u5c0f\uff1f<\/p>\n<ul>\n<li>\n<p>A \u5c42\uff0c\u56e0\u4e3a\u5b83\u6709 100 \u4e2a\u795e\u7ecf\u5143<\/p>\n<\/li>\n<li>\n<p>B \u5c42\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u795e\u7ecf\u5143\u6709 100 \u4e2a\u8f93\u5165<\/p>\n<\/li>\n<li>\n<p>\u4e00\u6837\u5927\uff0c\u56e0\u4e3a\u6743\u91cd\u77e9\u9635\u7684\u5143\u7d20\u603b\u6570\u76f8\u540c<\/p>\n<\/li>\n<\/ul>\n<p>\u9009B\uff01<\/p>\n<p>B \u5c42\u9700\u8981\u66f4\u5c0f\u7684\u6743\u91cd\uff0c\u662f\u56e0\u4e3a\u6bcf\u4e2a\u795e\u7ecf\u5143\u8981\u628a 100 \u4e2a\u52a0\u6743\u8f93\u5165\u76f8\u52a0\uff0c\u5bb9\u6613\u8ba9\u8f93\u51fa\u6570\u503c\u7684\u5c3a\u5ea6\u53d8\u5927\u3002<\/p>\n<hr>\n<p>\u90a3\u4e48\u5408\u9002\u7684\u521d\u59cb\u5316\u65b9\u6cd5\u5230\u5e95\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\u5462\uff1f<\/p>\n<p>\u7531\u4e8e\u591a\u4e2a\u8f93\u5165\u5728\u4e0e\u6743\u91cd\u76f8\u4e58\u5e76\u6c42\u548c\u4e4b\u540e\uff0c\u6bcf\u4e00\u5c42\u8f93\u51fa\u6570\u503c\u7684\u5c3a\u5ea6\u53ef\u80fd\u4f1a\u7206\u70b8\u5f0f\u589e\u957f\u6216\u8870\u51cf\uff0c\u6240\u4ee5\u54b1\u4eec<strong>\u9700\u8981\u4e00\u79cd\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u8ba9\u795e\u7ecf\u7f51\u7edc\u6bcf\u7ecf\u8fc7\u4e00\u5c42\uff0c\u8f93\u51fa\u7684\u6570\u503c\u5c3a\u5ea6\u90fd\u5c3d\u91cf\u4fdd\u6301\u7a33\u5b9a\u3002<\/strong><\/p>\n<p>\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p>\u4e4b\u524d\u54b1\u4eec\u63a8\u5bfc\u8fc7\uff1a<\/p>\n<div class=\"katex math multi-line\">\nz=w_1x_1+w_2x_2+\\cdots+w_nx_n\n<\/div>\n<p>\u5f53\u8f93\u5165\u5747\u503c\u4e3a 0\u3001\u65b9\u5dee\u4e3a 1\uff0c\u5404\u9879\u72ec\u7acb\uff0c\u6743\u91cd\u4e5f\u72ec\u7acb\u4e14\u5747\u503c\u4e3a 0 \u65f6\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(z)=n\\operatorname{Var}(w)}\n<\/div>\n<p>\u73b0\u5728\u54b1\u4eec\u5e0c\u671b\u8fd9\u4e00\u5c42\u8f93\u51fa\u7684\u65b9\u5dee\u4e5f\u7b49\u4e8e1<\/p>\n<p>\u6240\u4ee5\u53ef\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\nn\\operatorname{Var}(w) = 1\n<\/div>\n<p>\u4e5f\u5c31\u662f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\n\\operatorname{Var}(w) = \\frac 1n}\n<\/div>\n<p>\u54c7\uff01\u8fd9\u6837\u4e00\u6765\uff0c\u65e0\u8bba\u6709\u591a\u5c11\u4e2a\u8f93\u5165\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u6743\u91cd\u65b9\u5dee\uff0c\u907f\u514d\u8fd9\u4e00\u5c42\u628a\u8f93\u5165\u7684\u65b9\u5dee\u653e\u5927\uff01<\/p>\n<p>\u4f46\u662f\u6709\u4e2a\u95ee\u9898&#8230;&#8230;<\/p>\n<h3>He \u521d\u59cb\u5316<\/h3>\n<p>ReLU\u628a\u6240\u6709\u7684\u8d1f\u6570\u90fd\u53d8\u6210\u4e860\uff01<\/p>\n<p>\u54b1\u4eec\u73b0\u5728\u7684\u521d\u59cb\u5316\u4ee3\u7801\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">self.W = np.random.randn(neuron_num, weights_num)\n<\/code><\/pre>\n<p>\u751f\u6210\u670d\u4ece\u5747\u503c\u4e3a0\uff0c\u65b9\u5dee\u4e3a1\u7684\u6b63\u6001\u5206\u5e03<\/p>\n<p>\u4e5f\u5c31\u662f\u4ee50\u4e3a\u5e73\u5747\u6570\uff0c\u5de6\u53f3\u5bf9\u79f0\uff0c\u8d8a\u9760\u8fd1 0\uff0c\u6982\u7387\u5bc6\u5ea6\u8d8a\u9ad8\uff0c\u79bb 0 \u8d8a\u8fdc\uff0c\u51fa\u73b0\u7684\u53ef\u80fd\u6027\u901a\u5e38\u8d8a\u5c0f\u3002<\/p>\n<p>\u6839\u636e\u6b63\u6001\u5206\u5e03\u7684\u6027\u8d28\uff0c<strong>\u72ec\u7acb\u6b63\u6001\u968f\u673a\u53d8\u91cf\u4e58\u4ee5\u5e38\u6570\u540e\u518d\u76f8\u52a0\uff0c\u4ecd\u7136\u670d\u4ece\u6b63\u6001\u5206\u5e03\u3002<\/strong><\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u521d\u59cb\u5316\u7684\u6743\u91cd\u5747\u503c\u4e3a 0\uff0c\u5047\u8bbe\u8f93\u5165\u503c\u56fa\u5b9a\u3001\u6743\u91cd\u76f8\u4e92\u72ec\u7acb\u4e14\u504f\u7f6e\u4e3a 0\uff0c\u90a3\u4e48\u52a0\u6743\u6c42\u548c\u540e\u7684 <span class=\"katex math inline\">z<\/span> \u4ecd\u7136\u670d\u4ece\u5747\u503c\u4e3a 0 \u7684\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<p>\u56e0\u6b64\uff0c<span class=\"katex math inline\">z<\/span> \u7684\u6982\u7387\u5206\u5e03\u5173\u4e8e 0 \u5bf9\u79f0\u3002<\/p>\n<p>\u5047\u8bbe\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[z]=0\n<\/div>\n<p>\u90a3\u4e48\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(z)=E[z^2]\n<\/div>\n<p>\u56e0\u4e3a <span class=\"katex math inline\">z<\/span> \u7684\u5206\u5e03\u5173\u4e8e 0 \u5bf9\u79f0\uff0c\u6b63\u6570\u548c\u8d1f\u6570\u5bf9 <span class=\"katex math inline\">E[z^2]<\/span> \u7684\u8d21\u732e\u76f8\u7b49\u3002<\/p>\n<p>\u800c\u7ecf\u8fc7 ReLU \u540e\uff0c\u8d1f\u6570\u90e8\u5206\u7684\u5e73\u65b9\u5168\u90e8\u53d8\u6210 0\u3002<\/p>\n<p>\u6240\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{E[\\operatorname{ReLU}(z)^2]=\\frac12E[z^2]}\n<\/div>\n<p><strong>\u8fd9\u91cc\u51cf\u534a\u7684\u662f\u5e73\u65b9\u7684\u671f\u671b\uff0c\u4e0d\u662f\u4e25\u683c\u610f\u4e49\u4e0a\u7684\u65b9\u5dee<\/strong><\/p>\n<p>\u56e0\u4e3a\u7ecf\u8fc7 ReLU \u540e\uff0c\u8f93\u51fa\u7684\u5e73\u5747\u503c\u901a\u5e38\u4e0d\u518d\u662f 0\u3002<\/p>\n<p>\u73b0\u5728\u54b1\u4eec\u628a\u4e24\u90e8\u5206\u5408\u8d77\u6765\uff01<\/p>\n<p>\u8fd9\u6b21\u6211\u4eec\u7814\u7a76\u7684\u662f\u6574\u4e2a\u7f51\u7edc\u4e2d\u8fde\u7eed\u7684\u4e24\u5c42\uff0c\u800c\u4e0d\u53ea\u662f\u7b2c\u4e00\u4e2a\u795e\u7ecf\u5143\u3002<\/p>\n<p>\u8bbe\u4e0a\u4e00\u5c42\u6fc0\u6d3b\u503c\u4e3a <span class=\"katex math inline\">a_i<\/span>\uff0c\u4e0b\u4e00\u5c42\u7684\u7ebf\u6027\u8ba1\u7b97\u4e3a\uff1a<\/p>\n<div class=\"katex math multi-line\">\nz=\\sum_{i=1}^{n}w_ia_i\n<\/div>\n<p>\u5047\u8bbe\u6743\u91cd\u72ec\u7acb\u3001\u5747\u503c\u4e3a 0\uff0c\u4e14\u4e0e\u8f93\u5165\u72ec\u7acb\u3002\u4e3a\u4e86\u7b80\u5316\u63a8\u5bfc\uff0c\u504f\u7f6e\u8bbe\u4e3a 0\u3002<\/p>\n<p>\u6240\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\nE[z^2]=E[(w_1a_1+\\cdots+w_na_n)^2]\\\\\n\\end{aligned}\n<\/div>\n<p>\u5047\u5982n=2<\/p>\n<div class=\"katex math multi-line\">\nE[z^2]=E[(w_1a_1+w_2a_2)^2]\n<\/div>\n<p>\u5229\u7528\u5b8c\u5168\u5e73\u65b9\u516c\u5f0f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\nE[z^2]\n=E[&amp;w_1^2a_1^2\\\\\n&amp;+2w_1a_1w_2a_2\\\\\n&amp;+w_2^2a_2^2]\n\\end{aligned}\n<\/div>\n<p>\u6839\u636e\u671f\u671b\u7684\u6027\u8d28\uff0c\u5f53\u4e24\u4e2a\u968f\u673a\u53d8\u91cf\u76f8\u4e92\u72ec\u7acb\u65f6\uff0c\u671f\u671b\u53ef\u4ee5\u62c6\u5f00\u76f8\u52a0\u3002<\/p>\n<div class=\"katex math multi-line\">\nE[A+B]=E[A]+E[B]\n<\/div>\n<p>\u5f97\u5230\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\nE[z^2]\n=&amp;E[w_1^2a_1^2]\\\\\n&amp;+2E[w_1a_1w_2a_2]\\\\\n&amp;+E[w_2^2a_2^2]\n\\end{aligned}\n<\/div>\n<p>\u56e0\u4e3a\u54b1\u4eec\u521d\u59cb\u5316\u6743\u91cd\u7684\u6b63\u6001\u5206\u5e03\u5747\u503c\u662f0<\/p>\n<p>\u6240\u4ee5\u5404\u4e2a\u6743\u91cd\u7684\u671f\u671b\u4e5f\u662f0<\/p>\n<p>\u6839\u636e\u671f\u671b\u7684\u6027\u8d28\uff0c\u5f53\u4e24\u4e2a\u968f\u673a\u53d8\u91cf\u76f8\u4e92\u72ec\u7acb\u65f6\uff0c\u5b83\u4eec\u4e58\u79ef\u7684\u671f\u671b\u7b49\u4e8e\u5404\u81ea\u671f\u671b\u7684\u4e58\u79ef\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[AB]=E[A]E[B]\n<\/div>\n<p>\u56e0\u4e3a\u54b1\u4eec\u5047\u8bbe\u5404\u4e2a\u6743\u91cd\u76f8\u4e92\u72ec\u7acb\uff0c\u5e76\u4e14\u4e0e\u8f93\u5165\u503c\u76f8\u4e92\u72ec\u7acb\uff1a<\/p>\n<p>\u6240\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[w_1]=E[w_2]=0\n<\/div>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\n&amp;E[w_1a_1w_2a_2]\\\\\n&amp;=E[w_1w_2]\\cdot E[a_1a_2]\\\\\n&amp;=E[w_1]E[w_2]\\cdot E[a_1a_2]\\\\\n&amp;=0\\times0\\times E[a_1a_2]\\\\\n&amp;=\\boxed{0}\n\\end{aligned}\n<\/div>\n<p>\u6240\u4ee5\u6700\u540e\u7684\u5f0f\u5b50\u5c31\u7b49\u4e8e<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{E[z^2]=E[w_1^2a_1^2]+E[w_2^2a_2^2]}\n<\/div>\n<p>\u56de\u5230n\u4e2a\u6743\u91cd\u4e0e\u8f93\u5165\uff0c\u516c\u5f0f\u5c31\u662f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{E[z^2]=\\sum_{i=1}^{n}E[w_i^2a_i^2]}\n<\/div>\n<p>\u4e58\u6cd5\u6027\u8d28\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{E[w_i^2a_i^2]=E[w_i^2]E[a_i^2]}\n<\/div>\n<p>\u6240\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{E[z^2]=\\sum_{i=1}^{n}E[w_i^2]E[a_i^2]}\n<\/div>\n<p>\u7531\u4e8e\u6743\u91cd\u5747\u503c\u4e3a0\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[w_i^2]=\\operatorname{Var}(w_i)\n<\/div>\n<p>\u5982\u679c\u5404\u8f93\u5165\u6fc0\u6d3b\u503c\u7684\u5e73\u65b9\u671f\u671b\u76f8\u540c\uff0c\u4e3a\u4e86\u65b9\u4fbf\u4e66\u5199\uff0c\u6211\u4eec\u7528 <span class=\"katex math inline\">q<\/span> \u8868\u793a\u5b83\u4eec\u5171\u540c\u7684\u5e73\u65b9\u671f\u671b\uff0c\u4e5f\u5c31\u662f<span class=\"katex math inline\">q=E[a_i^2]<\/span>\uff0c\u90a3\u4e48\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\begin{aligned}\nE[z^2]\n&amp;=\\sum_{i=1}^{n}\\operatorname{Var}(w_i)E[a_i^2]\\\\\n\\\\\n&amp;=(\\operatorname{Var}(w_1)+\\operatorname{Var}(w_2)+\\cdots+\\operatorname{Var}(w_n))q\\\\\n\\\\\n&amp;=\\boxed{n\\operatorname{Var}(w)q}\n\\end{aligned}\n<\/div>\n<p>\u8fd9\u5c31\u662f\u54b1\u4eec\u7684\u8fd9\u4e2a\u516c\u5f0f\u5566~<\/p>\n<div class=\"katex math multi-line\">\nE[z^2]=n\\operatorname{Var}(w)q\n<\/div>\n<ul>\n<li>\n<p><span class=\"katex math inline\">n<\/span>\uff1a\u8f93\u5165\u6570\u91cf\uff0c\u5373 <code>fan_in<\/code>\u3002<\/p>\n<\/li>\n<li>\n<p><span class=\"katex math inline\">\\operatorname{Var}(w)<\/span>\uff1a\u6743\u91cd\u7684\u65b9\u5dee\u3002<\/p>\n<\/li>\n<li>\n<p><span class=\"katex math inline\">q=E[a_i^2]<\/span>\uff1a\u4e0a\u4e00\u5c42\u6fc0\u6d3b\u503c\u5e73\u65b9\u7684\u671f\u671b\u3002<\/p>\n<\/li>\n<li>\n<p><span class=\"katex math inline\">E[z^2]<\/span>\uff1a\u5f53\u524d\u795e\u7ecf\u5143\u6fc0\u6d3b\u524d\u8f93\u51fa\u5e73\u65b9\u7684\u671f\u671b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u518d\u7ecf\u8fc7ReLU<\/p>\n<div class=\"katex math multi-line\">\nE[\\operatorname{ReLU}(z)^2]=\\frac12 n\\operatorname{Var}(w)q\n<\/div>\n<p>\u73b0\u5728\u5c31\u6709\u4e86\u524d\u4e00\u5c42\u6fc0\u6d3b\u8f93\u51fa\u548c\u540e\u4e00\u5c42\u6fc0\u6d3b\u8f93\u51fa\u7684\u5173\u7cfb\u65b9\u7a0b\u5566<\/p>\n<p>\u54b1\u4eec\u7684\u76ee\u6807\u662f\u8ba9\u4e24\u5c42\u6fc0\u6d3b\u503c\u7684\u5e73\u65b9\u5747\u503c\u5c3d\u91cf\u4fdd\u6301\u4e0d\u53d8\uff0c\u6240\u4ee5\u4ee4\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[\\operatorname{ReLU}(z)^2]=q\n<\/div>\n<p>\u6240\u4ee5<\/p>\n<div class=\"katex math multi-line\">\n\\frac12 n\\operatorname{Var}(w_i)=1\n<\/div>\n<p>\u6700\u540e\u5bf9\u4e8e<span class=\"katex math inline\">w_i<\/span>\u7684\u6982\u7387\u8bba\u65b9\u5dee\u5c31\u662f<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(w)=\\frac2n}\n<\/div>\n<p>\u63a8\u51fa\u6765\u5566\uff01\u8fd9\u5c31\u662f<strong>He\u521d\u59cb\u5316<\/strong>\u7684\u6838\u5fc3\u63a8\u5bfc\uff01<\/p>\n<p>\u53ea\u9700\u8981\u8ba9\u6743\u91cd\u521d\u59cb\u5316\u6570\u503c\u5728\u968f\u673a\u7684\u65f6\u5019\u4fdd\u6301\u65b9\u5dee\u4e3a<span class=\"katex math inline\">\\frac2n<\/span>\u5c31\u53ef\u4ee5\u5566<\/p>\n<p>\u4ee3\u7801\u4e2d\uff0c\u54b1\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy<\/code>\u7684\u6307\u5b9a\u6b63\u6001\u5206\u5e03\u5747\u503c\u4e0e\u6807\u51c6\u5dee\u51fd\u6570\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">np.random.normal(loc, scale, size)\n<\/code><\/pre>\n<div class=\"table-responsive\"><table class=\"table\">\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u610f\u601d<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>loc<\/code><\/td>\n<td>\u5747\u503c <span class=\"katex math inline\">\\mu<\/span><\/td>\n<\/tr>\n<tr>\n<td><code>scale<\/code><\/td>\n<td>\u6807\u51c6\u5dee <span class=\"katex math inline\">\\sigma<\/span><\/td>\n<\/tr>\n<tr>\n<td><code>size<\/code><\/td>\n<td>\u751f\u6210\u6570\u7ec4\u7684\u5f62\u72b6<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">np.random.normal(0, 2, (3, 4))\n<\/code><\/pre>\n<p>\u8868\u793a\u751f\u6210\u4e00\u4e2a 3\u00d74 \u7684\u77e9\u9635\uff0c\u6bcf\u4e2a\u5143\u7d20\u72ec\u7acb\u5730\u4ece\u4e0b\u9762\u7684\u6b63\u6001\u5206\u5e03\u4e2d\u62bd\u53d6\uff1a<\/p>\n<div class=\"katex math multi-line\">\nW_{ij}\\sim\\mathcal N(0,4)\n<\/div>\n<p>\u6ce8\u610f\u8fd9\u91cc\u4f20\u5165\u7684\u662f\u6807\u51c6\u5dee\uff01\u4e5f\u5c31\u662f\u65b9\u5dee\u5f00\u6839\u53f7<\/p>\n<p>\u6240\u4ee5\u54b1\u4eec\u539f\u6765\u7684\u521d\u59cb\u5316\u6539\u6210\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">self.W = np.random.normal(0,math.sqrt(2\/weights_num), (neuron_num, weights_num))\n<\/code><\/pre>\n<p>\u8fde\u7eed\u8bad\u7ec3\u4e94\u6b21\u7684\u7ed3\u679c\uff01\uff01<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-powershell\">[[0.05000393]]\n[[0.98421973]]\n[[0.98381852]]\n[[0.05004344]]\n\n[[0.0732803]]\n[[0.98319848]]\n[[0.98253261]]\n[[0.03048717]]\n\n[[0.02912275]]\n[[0.99501697]]\n[[0.99452799]]\n[[0.0291227]]\n\n[[0.0064221]]\n[[0.99681663]]\n[[0.99108292]]\n[[0.0064221]]\n\n[[0.03073486]]\n[[0.99494596]]\n[[0.99540396]]\n[[0.03073544]]\n<\/code><\/pre>\n<p>\u5168\u6210\u529f\u4e86\uff01\u6709\u70b9\u4e1c\u897f\uff01\uff01<\/p>\n<p>\u505a\u4e2a\u5c0f\u5b9e\u9a8c\u5427\uff0c\u6211\u7528\u539f\u6765\u7684\u65b9\u5dee\u4e3a1\u5747\u503c\u4e3a0\u7684\u6b63\u6001\u5206\u5e03\u968f\u673a\u8bad\u7ec3100\u6b21\u770b\u6548\u679c\uff0c\u518d\u7528He\u521d\u59cb\u5316\u8bad\u7ec3100\u6b21\uff0c\u6765\u770b\u770b\u6210\u529f\u7387\uff0c\u4e00\u6b21\u6210\u529f\u662f\u6307\u56db\u4e2a XOR \u6837\u672c\u5728\u9608\u503c 0.5 \u4e0b\u662f\u5426\u5168\u90e8\u5206\u7c7b\u6b63\u786e\u3002<\/p>\n<p>\u6fc0\u52a8\u4eba\u5fc3\u7684\u7ed3\u679c\uff01\uff01<\/p>\n<div class=\"blog-mermaid mermaid\"><code class=\"mermaid-source\">xychart-beta\n    title &quot;\u4ee4\u4eba\u4f24\u5fc3\u7684\u5931\u8d25\u7ed3\u679c&quot;\n    x-axis [&quot;\u9ed8\u8ba40\u5747\u503c1\u65b9\u5dee\u6b63\u6001\u5206\u5e03&quot;,&quot;\u6709\u95ee\u9898\u7684He\u521d\u59cb\u5316&quot;]\n    y-axis &quot;\u8bad\u7ec3\u6210\u529f\u7387 (%)&quot; 0 --&gt; 100\n    bar [46,45]\n<\/code><\/div>\n<p>\u4e0d\u3002\u3002\u3002\u8fd9\u4e0d\u53ef\u80fd\uff01\uff01\uff01\uff01<\/p>\n<p>*\u6655\u5012<\/p>\n<p>\u554a\u597d\u5427\u5176\u5b9e\u662f\u53ef\u80fd\u7684\uff0cGPT\u6307\u51fa\u4e86\u4e24\u70b9\uff0c\u7b2c\u4e00\uff0c99mlp\u7684\u9690\u85cf\u5c42\u7528\u7684\u662fLeaky ReLU\u554a\uff01\uff01\uff01<\/p>\n<p>\u8fd9\u91cc\u7528<span class=\"katex math inline\">\\alpha<\/span>\u8868\u793aLeakyReLU\u8d1f\u6570\u90e8\u5206\u7684\u659c\u7387<\/p>\n<p>\u6240\u4ee5\u4e4b\u524d\u63a8\u5bfc\u7684\u6fc0\u6d3b\u8f93\u51fa\u5e73\u65b9\u7684\u671f\u671b\u5c31\u662f<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\n\\begin{aligned}\nE[\\operatorname{LeakyReLU}(z)^2]&amp;=\\frac{1}{2}E[z^2]+\\frac{\\alpha^2}2 E[z^2]\\\\\n&amp;=\\frac{1+\\alpha^2}2E[z^2]\n\\end{aligned}\n}\n<\/div>\n<p>\u5e26\u5165\u524d\u9762\u7b97\u51fa\u7684<span class=\"katex math inline\">E[z^2]<\/span><\/p>\n<div class=\"katex math multi-line\">\n\\frac{1+\\alpha^2}2E[z^2]=\\frac{1+\\alpha^2}2 n\\operatorname{Var}(w)q\n<\/div>\n<p>\u73b0\u5728\u8ba9\u4e0a\u4e00\u5c42\u6fc0\u6d3b\u8f93\u51fa\u5e73\u65b9\u671f\u671b\u7b49\u4e8e\u4e0b\u4e00\u5c42\u6fc0\u6d3b\u8f93\u51fa\u5e73\u65b9\u671f\u671b\uff0c\u7ea6\u6389<\/p>\n<div class=\"katex math multi-line\">\n\\frac{1+\\alpha^2}2 n\\operatorname{Var}(w)=1\n<\/div>\n<p>LeakyReLU\u516c\u5f0f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(w) = \\frac{2}{(1+\\alpha^2)fan_{in}}\n<\/div>\n<hr>\n<p>\u4f46\u662f99mlp\u4e2dLeakyReLU\u7684<span class=\"katex math inline\">\\alpha<\/span>\u503c\u8bbe\u7f6e\u7684\u662f0.01\u554a\uff0c\u7ecf\u8fc7\u5e73\u65b9\u540e\u5f71\u54cd\u5df2\u7ecf\u5fae\u4e4e\u5176\u5fae\u4e86\uff0c\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u4e86\u5462\uff1f<\/p>\n<p>\u6211\u7a81\u7136\u6ce8\u610f\u5230\uff0cHe\u521d\u59cb\u5316\u53ea\u662f\u7ed9ReLU\u53ca\u7c7bReLU\u51c6\u5907\u7684\uff0c\u4f46\u662f\u8f93\u51fa\u5c42\u4f7f\u7528\u4e86Sigmoid\uff0cSigmoid\u4e0d\u9002\u5408\u7528He\u6765\u521d\u59cb\u5316<\/p>\n<p>\u5bf9\u4e8eSigmoid\u6fc0\u6d3b\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>Xavier<\/strong>\u521d\u59cb\u5316<\/p>\n<h3>Xavier\u521d\u59cb\u5316<\/h3>\n<p>He\u521d\u59cb\u5316\u91cd\u70b9\u8003\u8651<strong>\u600e\u6837\u8ba9\u524d\u5411\u4f20\u64ad\u65f6\u7684\u4fe1\u53f7\u5e73\u65b9\u5747\u503c\u5c3d\u91cf\u4fdd\u6301\u7a33\u5b9a\u3002<\/strong><\/p>\n<p>\u800cXavier \u521d\u59cb\u5316\u7684\u601d\u8def\u662f\uff1a<strong>\u65e2\u7136\u8981\u4fdd\u6301\u524d\u5411\u4f20\u64ad\u7a33\u5b9a\uff0c\u90a3\u4e3a\u4ec0\u4e48\u4e0d\u540c\u65f6\u8003\u8651\u53cd\u5411\u4f20\u64ad\u7684\u68af\u5ea6\u5462\uff1f<\/strong><\/p>\n<h4>\u5148\u63a8\u5bfc\u524d\u5411\u4f20\u64ad\u9700\u8981\u4ec0\u4e48<\/h4>\n<p>\u4e3a\u4e86\u7b80\u5316\u6570\u5b66\uff0c\u54b1\u4eec\u6682\u65f6\u7814\u7a76\u4e0d\u5e26\u6fc0\u6d3b\u51fd\u6570\u7684\u7ebf\u6027\u5c42\uff0c\u5047\u8bbe\u6743\u91cd\u72ec\u7acb\u3001\u5747\u503c\u4e3a 0\uff0c\u8f93\u5165\u7684\u5e73\u65b9\u5747\u503c\u76f8\u540c\uff0c\u5e76\u4e14\u6743\u91cd\u4e0e\u8f93\u5165\u72ec\u7acb\u3002<\/p>\n<p>\u6839\u636e\u4e4b\u524d\u7684\u63a8\u5bfc\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[z^2]={fan}_{in}\\operatorname{Var}(w)E[a^2]\n<\/div>\n<p>\u54b1\u4eec\u5e0c\u671b\u524d\u5411\u4f20\u64ad\u7684\u5e73\u65b9\u5747\u503c\u4fdd\u6301\u4e0d\u53d8\uff1a<\/p>\n<div class=\"katex math multi-line\">\nE[z^2]=E[a^2]\n<\/div>\n<p>\u4e8e\u662f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n{fan}_{in}\\operatorname{Var}(w)=1\n<\/div>\n<p>\u6240\u4ee5\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(w)=\\frac1{fan_{in}}}\n<\/div>\n<p>\u8fd9\u5c31\u662f\u524d\u5411\u4f20\u64ad\u5e0c\u671b\u5f97\u5230\u7684\u6743\u91cd\u65b9\u5dee\uff01<\/p>\n<p>\u90a3<strong>\u53cd\u5411\u4f20\u64ad<\/strong>\u5462\uff1f<\/p>\n<p>\u73b0\u5728\u5047\u8bbe\u67d0\u5c42\u6709 3 \u4e2a\u8f93\u51fa\u795e\u7ecf\u5143\uff0c\u67d0\u4e2a\u8f93\u5165\u795e\u7ecf\u5143\u4e0e\u5b83\u4eec\u5168\u90e8\u76f8\u8fde\u3002<\/p>\n<p>\u53cd\u5411\u4f20\u64ad\u65f6\uff0c\u8fd9\u4e2a\u8f93\u5165\u5bf9\u5e94\u7684\u68af\u5ea6\u5c31\u4f1a\u6536\u5230\u6765\u81ea 3 \u4e2a\u8f93\u51fa\u65b9\u5411\u7684\u8d21\u732e\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\delta_{\\text{in}}\n=w_1\\delta_1+w_2\\delta_2+w_3\\delta_3\n<\/div>\n<p>\u8bf6\uff1f\u8fd9\u4e2a\u8ddf<\/p>\n<div class=\"katex math multi-line\">\nE[z^2]\n=\\sum_{i=1}^{n}\\operatorname{Var}(w_i)E[a_i^2]\n<\/div>\n<p>\u957f\u5f97\u597d\u50cf\uff01\u4f46\u662f\u56e0\u4e3a\u662f\u53cd\u5411\u4f20\u64ad\uff0c\u6240\u4ee5<\/p>\n<div class=\"katex math multi-line\">\nE[\\delta_{in}^2]\n=\\sum_{i=1}^{n}\\operatorname{Var}(w_i)E[\\delta_{out}^2]\n<\/div>\n<p>\u4e5f\u5c31\u662f<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\nE[\\delta_{\\text{in}}^2]\n=fan_{out}\\operatorname{Var}(w)E[\\delta_{\\text{out}}^2]\n}\n<\/div>\n<p>\u7136\u540e\u54b1\u4eec\u5e0c\u671b\u540e\u4e00\u5c42\u7684\u68af\u5ea6\u5230\u4e86\u524d\u4e00\u5c42\u5e73\u65b9\u5747\u503c\u4fdd\u6301\u4e0d\u53d8<\/p>\n<p>\u6240\u4ee5<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(w)=\\frac1{fan_{out}}}\n<\/div>\n<p>\u5636\u3002\u3002\u3002\u3002\u3002\u8bf6\u4f46\u662f\u8fd9\u4e0d\u592a\u597d\uff0c\u5982\u679cfan_in\u548cfan_out\u4e0d\u4e00\u6837\u7684\u8bdd\uff0c\u6743\u91cd\u65b9\u5dee\u6ca1\u6cd5\u6c42\u4e86\uff01<\/p>\n<p>\u6240\u4ee5Xavier \u521d\u59cb\u5316\u91c7\u53d6\u4e86\u4e00\u79cd\u6298\u4e2d\u65b9\u6848<\/p>\n<p>\u628a\u4e24\u4e2a\u8fde\u63a5\u6570\u53d6\u7b97\u672f\u5e73\u5747\uff1a<\/p>\n<div class=\"katex math multi-line\">\nn_{\\text{avg}}=\\frac{fan_{in}+fan_{out}}2\n<\/div>\n<p>\u7136\u540e\u6309\u7167\u524d\u9762\u63a8\u5bfc\u7684\u601d\u8def\uff0c\u8ba9\uff1a<\/p>\n<div class=\"katex math multi-line\">\nn_{\\text{avg}}\\operatorname{Var}(w)=1\n<\/div>\n<p>\u4e8e\u662f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(w)=\\frac{2}{fan_{in}+fan_{out}}}\n<\/div>\n<p>\u8fd9\u5c31\u662f <strong>Xavier \u6b63\u6001\u521d\u59cb\u5316<\/strong> \u7684\u7ecf\u5178\u516c\u5f0f\uff01<\/p>\n<p>GPT\u8bf4\u8fd8\u6709\u4e00\u4e2a\u503c\u5f97\u5199\u5230\u7b14\u8bb0\u91cc\u7684\u4e1c\u897f\uff01<\/p>\n<h3>Xavier Uniform &#8211; \u5747\u5300\u5206\u5e03\u521d\u59cb\u5316<\/h3>\n<p>Xavier Uniform \u4e0d\u4f7f\u7528\u6b63\u6001\u5206\u5e03\uff0c\u800c\u662f\u4f7f\u7528\u5747\u5300\u5206\u5e03\uff01<\/p>\n<p>Xavier Uniform\u5e0c\u671b\u6743\u91cd\u670d\u4ece\uff1a<\/p>\n<div class=\"katex math multi-line\">\nW\\sim U(-a,a)\n<\/div>\n<p>\u5176\u4e2d <span class=\"katex math inline\">U<\/span> \u8868\u793a\u5747\u5300\u5206\u5e03\u3002<\/p>\n<p>\u5bf9\u4e8e\u8fd9\u79cd\u5206\u5e03\uff0c\u6709\u4e00\u4e2a\u65b9\u5dee\u516c\u5f0f\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{\\operatorname{Var}(W)=\\frac{a^2}{3}}\n<\/div>\n<p>\u800c\u6211\u4eec\u4e4b\u524d\u63a8\u5bfc\u7684 Xavier \u521d\u59cb\u5316\u8981\u6c42\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\operatorname{Var}(W)=\\frac{2}{fan_{in}+fan_{out}}\n<\/div>\n<p>\u6240\u4ee5\u8ba9\u4e24\u4e2a\u65b9\u5dee\u76f8\u7b49\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\frac{a^2}{3}=\\frac{2}{fan_{in}+fan_{out}}\n<\/div>\n<p>\u5316\u7b80\u5f97\uff1a<\/p>\n<div class=\"katex math multi-line\">\n\\boxed{a=\\sqrt{\\frac{6}{fan_{in}+fan_{out}}}}\n<\/div>\n<p>\u4e8e\u662f Xavier Uniform \u5c31\u53ef\u4ee5\u8fd9\u6837\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">a = math.sqrt(6 \/ (weights_num + neuron_num))\n\nself.W = np.random.uniform(\n    -a,\n    a,\n    (neuron_num, weights_num)\n)\n<\/code><\/pre>\n<hr>\n<p>\u6765\u6539\u4ee3\u7801\uff01\uff01\uff01<\/p>\n<p>\u9996\u5148\u7ed9\u521d\u59cb\u5316\u6539\u6210LeakyReLU\u7684He\u521d\u59cb\u5316\u548cXavier\u521d\u59cb\u5316<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">def __init__(self, neuron_num, weights_num, activation=&quot;relu&quot;):\n    # \u521d\u59cb\u5316\u795e\u7ecf\u5143\u77e9\u9635\uff0crandom.randn\u662f\u751f\u6210\u884cx\u5217\u7684\u77e9\u9635\uff0c\u91cc\u9762\u7684\u6570\u503c\u968f\u673a\n    # \u56e0\u4e3a\u6bcf\u4e2a\u8f93\u5165\u8981\u548c\u6bcf\u4e2a\u6743\u91cd\u70b9\u4e58\uff0c\u53c8\u56e0\u4e3a\u77e9\u9635\u4e58\u6cd5\u662f\u884c\u70b9\u4e58\u5217\uff0c\u6240\u4ee5\u6bcf\u4e2a\u795e\u7ecf\u5143\u7684\u6bcf\u4e2a\u6743\u91cd\u5b58\u5728\u77e9\u9635\u7684\u884c\u4e2d\n    # \u7136\u540e\u6bcf\u884c\u91cc\u7684\u6bcf\u4e2a\u6743\u91cd\u5c31\u53ef\u4ee5\u548c\u8f93\u5165\uff08\u770b\u505a\u591a\u884c1\u5217\u7684\u77e9\u9635\uff09\u70b9\u4e58\u5566~\n    # self.W = np.random.randn(neuron_num, weights_num)\n    # self.W = np.random.normal(0,math.sqrt(2\/weights_num), (neuron_num, weights_num))\n\n    if activation == &quot;sigmoid&quot;: # \u4f7f\u7528Xavier\u521d\u59cb\u5316\u6743\u91cd\n        self.W = np.random.normal(0, math.sqrt(2\/(weights_num+neuron_num)), (neuron_num, weights_num))\n    else: #\u4f7f\u7528LeakyReLU\u7684He\u521d\u59cb\u5316\n        self.W = np.random.normal(0, math.sqrt(2\/((1+0.01*0.01)*weights_num)), (neuron_num, weights_num))\n\n    # \u521b\u5efa\u4e00\u4e2aneuron_num\u884c\uff0c1\u5217\u7684\u77e9\u9635\uff0c\u4e5f\u5c31\u662f\u54b1\u4eec\u7684\u504f\u7f6e\u77e9\u9635\uff01\n    # \u504f\u7f6e\u77e9\u9635\u90fd\u586b\u51450\u5c31\u597d\uff0c\u504f\u7f6e\u521d\u59cb\u503c\u8bbe\u7f6e\u4e3a0\u66f4\u9ad8\u6548\n    self.b = np.zeros((neuron_num,1)) \n    self.activation = activation #\u6fc0\u6d3b\u51fd\u6570\u53ef\u4ee5\u8bbe\u5b9a\u6a21\u5f0f\u4e86\n<\/code><\/pre>\n<p>\u6765\u770b100\u6b21\u8f93\u51fa\u5b9e\u9a8c\u7ed3\u679c\uff1a<\/p>\n<div class=\"blog-mermaid mermaid\"><code class=\"mermaid-source\">xychart-beta\n    title &quot;\u4ee4\u4eba\u66f4\u4f24\u5fc3\u7684\u5931\u8d25\u7ed3\u679c&quot;\n    x-axis [&quot;\u9ed8\u8ba40\u5747\u503c1\u65b9\u5dee\u6b63\u6001\u5206\u5e03&quot;,&quot;\u6709\u95ee\u9898\u7684He\u521d\u59cb\u5316&quot;,&quot;\u4f7f\u7528\u4e86LeakyReLU\u548cXavier\u521d\u59cb\u5316\u540e&quot;]\n    y-axis &quot;\u8bad\u7ec3\u6210\u529f\u7387 (%)&quot; 0 --&gt; 100\n    bar [46,45,44]\n<\/code><\/div>\n<p>\u6ca1\u6709\u89c2\u5bdf\u5230\u660e\u663e\u5dee\u5f02\u751a\u81f3\u5f80\u4e0b\u8dcc\u4e86\uff01\uff1f<\/p>\n<p>*\u7761\u7740\u4e86<\/p>\n<p>GPT\u63d0\u51fa\u5c06\u8bad\u7ec3\u6837\u672c\u7684\u987a\u5e8f\u6253\u4e71<\/p>\n<p>\u53ef\u4ee5\u7528<code>numpy<\/code>\u7684<code>random.permutation()<\/code>\u6765\u505a\u5230\u8fd9\u4e00\u6548\u679c<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">np.random.permutation(len(train_data))\n<\/code><\/pre>\n<p>\u56e0\u4e3a<code>train_data<\/code>\u6709\u56db\u4e2a\u5bf9\u8c61\uff0c\u6240\u4ee5\u6700\u7ec8\u4f20\u7ed9\u8be5\u51fd\u6570\u7684\u503c\u4e3a<code>4<\/code><\/p>\n<p><code>numpy<\/code>\u4f1a\u751f\u6210\u4e00\u4e2a\u7531<code>0\u30011\u30012\u30013<\/code>\u7ec4\u6210\u7684\u968f\u673a\u6392\u5217<\/p>\n<p>\u4e0d\u4f1a\u91cd\u590d\uff0c\u4e5f\u4e0d\u4f1a\u9057\u6f0f<\/p>\n<p>\u6240\u4ee5\u653e\u5230for\u5faa\u73af\u5f53\u4e2d\uff0c\u987a\u5e8f\u5c31\u88ab\u6253\u4e71\u5566~<\/p>\n<p>\u6765\u8bd5\u8bd5\u770b<\/p>\n<pre class=\"prettyprint linenums\"><code class=\"language-python\">for epoch in range(20000):\n    for simple in np.random.permutation(len(train_data)):\n        y = train_data[simple][2]\n        haty = network.forward([train_data[simple][0],train_data[simple][1]])\n        # \u56e0\u4e3aforward\u6700\u540e\u8fd4\u56de\u7684\u662f\u6bcf\u4e2a\u795e\u7ecf\u5143\u7684\u8f93\u51fa\uff0c\u7136\u540e\u6700\u540e\u4e00\u5c42\u5c31\u4e00\u4e2a\u795e\u7ecf\u5143\uff0c\u6240\u4ee5\u7528[0]\n        dL_dhaty = 2*(haty[0] - y)\n        network.backward(dL_dhaty,0.01)\n<\/code><\/pre>\n<p>\u6765\u770b\u7ed3\u679c\u5427~<\/p>\n<div class=\"blog-mermaid mermaid\"><code class=\"mermaid-source\">xychart-beta\n    title &quot;\u4ee4\u4eba\u5f00\u5fc3\u7684\u5b9e\u9a8c\u7ed3\u679c&quot;\n    x-axis [&quot;\u9ed8\u8ba40\u5747\u503c1\u65b9\u5dee\u6b63\u6001\u5206\u5e03&quot;,&quot;\u6709\u95ee\u9898\u7684He\u521d\u59cb\u5316&quot;,&quot;\u6362\u7528\u521d\u59cb\u5316&quot;,&quot;\u6253\u4e71\u987a\u5e8f\u540e&quot;]\n    y-axis &quot;\u8bad\u7ec3\u6210\u529f\u7387 (%)&quot; 0 --&gt; 100\n    bar [46,45,44,55]\n<\/code><\/div>\n<p>\u597d\u8036\uff01\uff01\uff01\u7ec8\u4e8e\u6da8\u5566\uff01\uff01\uff01<\/p>\n<p>\u539f\u672c\u4ee5\u4e3a\uff0c\u7ecf\u8fc7\u4e00\u4e0b\u5348\u7684\u6570\u5b66\u63a8\u5bfc\uff0c\u4f7f\u7528 He \u548c Xavier \u521d\u59cb\u5316\u540e\uff0c99MLP \u7684\u8bad\u7ec3\u6210\u529f\u7387\u4f1a\u663e\u8457\u63d0\u9ad8\u3002<\/p>\n<p>\u7136\u800c\u5b9e\u9a8c\u7ed3\u679c\u5374\u51fa\u4e4e\u610f\u6599\uff1a46%\u300145%\u300144%\u2026\u2026\u6210\u529f\u7387\u4e0d\u4ec5\u6ca1\u6709\u63d0\u9ad8\uff0c\u53cd\u800c\u7565\u6709\u4e0b\u964d\u3002<\/p>\n<p>\u76f4\u5230\u6211\u5c1d\u8bd5\u968f\u673a\u6253\u4e71\u8bad\u7ec3\u6570\u636e\u7684\u987a\u5e8f\uff0c\u6210\u529f\u7387\u624d\u5728\u8fd9\u7ec4\u5b9e\u9a8c\u4e2d\u63d0\u9ad8\u5230\u4e86 55%\u3002<\/p>\n<p>\u770b\u6765\uff0c\u6743\u91cd\u521d\u59cb\u5316\u53ea\u662f\u5f71\u54cd\u795e\u7ecf\u7f51\u7edc\u8bad\u7ec3\u7684\u56e0\u7d20\u4e4b\u4e00\u3002\u65e2\u7136\u8bad\u7ec3\u987a\u5e8f\u80fd\u591f\u5f71\u54cd\u6700\u7ec8\u7ed3\u679c\uff0c\u90a3\u4e48 Loss \u5462\uff1f<\/p>\n<p>\u4e0b\u4e00\u7bc7\uff0c\u6211\u4eec\u5c31\u6765\u7814\u7a76\u5b83\u3002<\/p>\n<p>\u7ee7\u7eed\u52a0\u6cb9\uff01\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Attention Is All You Need #3: \u795e\u5947\u53c8\u91cd\u8981\u7684\u521d\u59cb\u5316 \u6b22\u8fce\u56de\u6765~\u4eca\u5929\u4f5c\u4e1a\u90fd\u5199\u5b8c\u5566~\u6765\u5b66\u4e00\u4e2a\u5c0f\u65f6\uff0c\u4e0d\u8bba\u6700\u5f00\u59cb\u768499mlp\u8fd8\u662f\u4e0a\u7bc7\u535a\u5ba2\u6240\u4fee\u6539\u7684\u77e9\u9635\u7248\uff0c\u90fd\u6709\u8bad\u7ec3\u5931\u8d25\u7684\u95ee\u9898\uff0cGPT \u63d0\u51fa\uff0c\u6743\u91cd\u521d\u59cb\u5316\u53ef\u80fd\u662f\u91cd\u8981\u539f\u56e0\u4e4b\u4e00\uff0c\u8fd9\u7bc7\u535a\u5ba2\u6211\u4eec\u5c31\u6765\u7814\u7a76\u5b83\u3002 \u90a3\u4e48\uff0c\u968f\u673a\u521d\u59cb\u5316\u6743\u91cd\u7684\u6570\u503c\uff0c\u6709\u4ec0\u4e48\u95ee\u9898\u5462\uff1f \u968f\u673a\u521d\u59cb\u5316\u5230\u5e95\u6709\u4ec0\u4e48\u95ee\u9898\uff1f \u6765\u770b\u521d\u59cb\u5316\u6743\u91cdW\u77e9\u9635\u7684\u4ee3\u7801\uff1a self.W = np.random [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,23,26,24],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-ai","category-transformer","category-26","category-24"],"_links":{"self":[{"href":"https:\/\/99website.top\/blog\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/99website.top\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/99website.top\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/99website.top\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/99website.top\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":0,"href":"https:\/\/99website.top\/blog\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"wp:attachment":[{"href":"https:\/\/99website.top\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/99website.top\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/99website.top\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}