{"id":105029,"date":"2026-09-13T16:33:11","date_gmt":"2026-09-13T08:33:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/105029.html"},"modified":"2026-09-13T16:33:11","modified_gmt":"2026-09-13T08:33:11","slug":"%e4%b8%80%e6%96%87%e6%a2%b3%e7%90%86-transformer%ef%bc%9a%e4%bb%8e%e6%a8%a1%e5%9e%8b%e7%bb%93%e6%9e%84%e3%80%81self-attention-%e5%88%b0%e5%a4%a7%e6%a8%a1%e5%9e%8b%e8%ae%ad%e7%bb%83%e4%b8%8e%e6%8e%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/105029.html","title":{"rendered":"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406"},"content":{"rendered":"<p>\u8fd9\u7bc7\u7b14\u8bb0\u4e3b\u8981\u7528\u4e8e\u5feb\u901f\u68b3\u7406 Transformer\u3001\u5927\u8bed\u8a00\u6a21\u578b\u3001Self-Attention\u3001\u8bad\u7ec3\u6d41\u7a0b\u548c\u63a8\u7406\u6d41\u7a0b\u3002<\/p>\n<p>\u4e0d\u8ffd\u6c42\u590d\u6742\u6570\u5b66\u63a8\u5bfc&#xff0c;\u800c\u662f\u5c3d\u91cf\u628a\u5404\u4e2a\u6982\u5ff5\u4e32\u6210\u4e00\u6761\u5b8c\u6574\u7684\u903b\u8f91\u94fe\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u7406\u89e3 Transformer \u5728\u505a\u4ec0\u4e48<\/h3>\n<p>Transformer \u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u67b6\u6784\u3002<\/p>\n<p>\u5728\u5927\u8bed\u8a00\u6a21\u578b\u4e2d&#xff0c;\u5927\u91cf\u8ba1\u7b97\u6700\u7ec8\u90fd\u4f1a\u8f6c\u5316\u4e3a&#xff1a;<\/p>\n<p>\u77e9\u9635\u8fd0\u7b97<br \/>\n&#043;<br \/>\n\u524d\u5411\u4f20\u64ad<br \/>\n&#043;<br \/>\n\u635f\u5931\u8ba1\u7b97<br \/>\n&#043;<br \/>\n\u53cd\u5411\u4f20\u64ad<br \/>\n&#043;<br \/>\n\u53c2\u6570\u66f4\u65b0<\/p>\n<p>\u8bad\u7ec3\u6a21\u578b\u65f6&#xff0c;\u53ef\u4ee5\u5148\u628a\u6574\u4e2a\u8fc7\u7a0b\u7b80\u5355\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>\u8f93\u5165\u8bad\u7ec3\u6570\u636e<br \/>\n    \u2193<br \/>\n\u6a21\u578b\u8fdb\u884c\u9884\u6d4b<br \/>\n    \u2193<br \/>\n\u4e0e\u6b63\u786e\u7b54\u6848\u6bd4\u8f83<br \/>\n    \u2193<br \/>\n\u8ba1\u7b97 Loss<br \/>\n    \u2193<br \/>\n\u53cd\u5411\u4f20\u64ad<br \/>\n    \u2193<br \/>\n\u8ba1\u7b97\u68af\u5ea6<br \/>\n    \u2193<br \/>\nOptimizer \u66f4\u65b0\u53c2\u6570<br \/>\n    \u2193<br \/>\n\u7ee7\u7eed\u4e0b\u4e00\u6279\u6570\u636e<br \/>\n    \u2193<br \/>\n\u4e0d\u65ad\u91cd\u590d<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5927\u8bed\u8a00\u6a21\u578b\u8bad\u7ec3\u7684\u6838\u5fc3\u5c31\u662f&#xff1a;<\/p>\n<p>\u4e0d\u65ad\u6839\u636e\u6a21\u578b\u9884\u6d4b\u7ed3\u679c\u548c\u6b63\u786e\u7b54\u6848\u4e4b\u95f4\u7684\u8bef\u5dee&#xff0c;\u8c03\u6574\u6a21\u578b\u5185\u90e8\u5927\u91cf\u53c2\u6570\u3002<\/p>\n<p>\u8bad\u7ec3\u8fc7\u7a0b\u4e2d&#xff1a;<\/p>\n<p>\u53c2\u6570\u7684\u503c<br \/>\n\u4f1a\u4e0d\u65ad\u53d8\u5316<\/p>\n<p>\u4f46\u662f<\/p>\n<p>\u53c2\u6570\u7684\u6570\u91cf<br \/>\n\u901a\u5e38\u4e0d\u4f1a\u53d8\u5316<\/p>\n<hr \/>\n<h2>\u4e8c\u3001Transformer\u3001GPT \u548c\u5927\u8bed\u8a00\u6a21\u578b\u662f\u4ec0\u4e48\u5173\u7cfb&#xff1f;<\/h2>\n<p>\u9996\u5148\u9700\u8981\u533a\u5206&#xff1a;<\/p>\n<p>Transformer<\/p>\n<p>\u548c&#xff1a;<\/p>\n<p>GPT<\/p>\n<p>Transformer \u662f\u4e00\u79cd\u901a\u7528\u6a21\u578b\u67b6\u6784\u3002<\/p>\n<p>\u539f\u59cb Transformer \u91c7\u7528&#xff1a;<\/p>\n<p>Encoder<br \/>\n   &#043;<br \/>\nDecoder<\/p>\n<p>\u4e5f\u5c31\u662f&#xff1a;<\/p>\n<p>\u8f93\u5165\u5e8f\u5217<br \/>\n   \u2193<br \/>\nEncoder<br \/>\n   \u2193<br \/>\n\u4e2d\u95f4\u8868\u793a<br \/>\n   \u2193<br \/>\nDecoder<br \/>\n   \u2193<br \/>\n\u8f93\u51fa\u5e8f\u5217<\/p>\n<p>\u800c GPT \u7cfb\u5217\u91c7\u7528\u7684\u662f Transformer \u7684\u4e00\u79cd\u53d8\u4f53&#xff1a;<\/p>\n<p>Decoder-only<\/p>\n<p>\u5373\u4e3b\u8981\u4fdd\u7559 Decoder \u7ed3\u6784\u3002<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a&#xff1a;<\/p>\n<p>Transformer<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Encoder-only<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Encoder &#043; Decoder<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 Decoder-only<br \/>\n      \u2193<br \/>\n     GPT<\/p>\n<p>\u9700\u8981\u6ce8\u610f&#xff1a;<\/p>\n<p>GPT \u53ea\u4f7f\u7528 Decoder&#xff0c;\u5e76\u4e0d\u4ee3\u8868\u5b83\u4e0d\u4f1a\u5904\u7406\u548c\u7406\u89e3\u8f93\u5165\u3002<\/p>\n<p>\u8f93\u5165\u4fe1\u606f\u7684\u5904\u7406\u3001\u4e0a\u4e0b\u6587\u5efa\u6a21\u4ee5\u53ca\u540e\u7eed Token \u9884\u6d4b&#xff0c;\u90fd\u53ef\u4ee5\u5728 Decoder Block \u4e2d\u5b8c\u6210\u3002<\/p>\n<hr \/>\n<h2>\u4e09\u3001GPT \u7c7b\u5927\u8bed\u8a00\u6a21\u578b\u6574\u4f53\u7ed3\u6784<\/h2>\n<p>\u5148\u770b\u4e00\u904d\u5b8c\u6574\u6d41\u7a0b&#xff1a;<\/p>\n<p>\u8f93\u5165\u6587\u672c<br \/>\n\u4f8b\u5982&#xff1a;<\/p>\n<p>&#034;\u4eba\u5de5\u667a\u80fd\u6b63\u5728\u6539\u53d8\u4e16\u754c&#034;<\/p>\n<p>        \u2193<\/p>\n<p>Tokenizer<br \/>\n\u3010\u5206\u8bcd\u5668\u3011<\/p>\n<p>\u628a\u6587\u672c\u5207\u5206\u6210 Token<\/p>\n<p>        \u2193<\/p>\n<p>Token ID<br \/>\n\u3010Token \u5bf9\u5e94\u7684\u6570\u5b57\u7f16\u53f7\u3011<\/p>\n<p>        \u2193<\/p>\n<p>Token Embedding<br \/>\n\u3010\u628a Token ID \u8f6c\u6362\u6210\u5411\u91cf\u3011<\/p>\n<p>        \u2193<\/p>\n<p>Position Embedding<br \/>\n\u3010\u52a0\u5165 Token \u7684\u4f4d\u7f6e\u4fe1\u606f\u3011<\/p>\n<p>        \u2193<\/p>\n<p>\u8f93\u5165\u5411\u91cf<\/p>\n<p>        \u2193<\/p>\n<p>Transformer Block 1<\/p>\n<p>        \u2193<\/p>\n<p>Transformer Block 2<\/p>\n<p>        \u2193<\/p>\n<p>Transformer Block 3<\/p>\n<p>        \u2193<\/p>\n<p>&#8230;<\/p>\n<p>        \u2193<\/p>\n<p>Transformer Block N<\/p>\n<p>        \u2193<\/p>\n<p>\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u5f97\u5230\u4e0b\u4e00\u4e2a Token \u7684\u6982\u7387\u5206\u5e03<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5927\u8bed\u8a00\u6a21\u578b\u53ef\u4ee5\u7c97\u7565\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>Tokenizer<br \/>\n    \u2193<br \/>\nEmbedding<br \/>\n    \u2193<br \/>\n\u5927\u91cf Transformer Block<br \/>\n    \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<hr \/>\n<h2>\u56db\u3001Token\u3001Token ID\u3001Embedding \u5206\u522b\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>\u8fd9\u51e0\u4e2a\u6982\u5ff5\u975e\u5e38\u5bb9\u6613\u6df7\u3002<\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u8bb0\u6210&#xff1a;<\/p>\n<p>\u6587\u672c<br \/>\n \u2193<br \/>\nToken<br \/>\n \u2193<br \/>\nToken ID<br \/>\n \u2193<br \/>\nEmbedding<br \/>\n \u2193<br \/>\n\u5411\u91cf<\/p>\n<hr \/>\n<h3>1. Token<\/h3>\n<p>Token \u662f\u5927\u8bed\u8a00\u6a21\u578b\u5904\u7406\u6587\u672c\u7684\u57fa\u672c\u5355\u4f4d\u3002<\/p>\n<p>\u4e00\u4e2a Token \u53ef\u80fd\u5bf9\u5e94&#xff1a;<\/p>\n<p>\u4e00\u4e2a\u5b57<\/p>\n<p>\u4e00\u4e2a\u8bcd<\/p>\n<p>\u4e00\u4e2a\u8bcd\u7684\u4e00\u90e8\u5206<\/p>\n<p>\u4e00\u4e2a\u6807\u70b9\u7b26\u53f7<\/p>\n<p>\u56e0\u6b64&#xff1a;<\/p>\n<p>Token \u4e0d\u4e00\u5b9a\u7b49\u4e8e\u4e00\u4e2a\u6c49\u5b57&#xff0c;\u4e5f\u4e0d\u4e00\u5b9a\u7b49\u4e8e\u4e00\u4e2a\u5b8c\u6574\u82f1\u6587\u5355\u8bcd\u3002<\/p>\n<hr \/>\n<h3>2. Token ID<\/h3>\n<p>\u6a21\u578b\u4e0d\u80fd\u76f4\u63a5\u5904\u7406\u6587\u5b57\u3002<\/p>\n<p>\u6240\u4ee5 Token \u4f1a\u88ab\u8f6c\u6362\u6210\u6570\u5b57\u7f16\u53f7\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>&#034;AI&#034;<br \/>\n \u2193<br \/>\nToken ID<br \/>\n \u2193<br \/>\n12345<\/p>\n<p>\u8fd9\u4e2a\u6570\u5b57\u672c\u8d28\u4e0a\u76f8\u5f53\u4e8e&#xff1a;<\/p>\n<p>Token \u5728\u8bcd\u8868 Vocabulary \u4e2d\u7684\u7f16\u53f7\u3002<\/p>\n<hr \/>\n<h3>3. Embedding<\/h3>\n<p>Token ID \u672c\u8eab\u53ea\u662f\u4e00\u4e2a\u6574\u6570&#xff0c;\u5e76\u4e0d\u80fd\u76f4\u63a5\u8868\u8fbe\u590d\u6742\u8bed\u4e49\u3002<\/p>\n<p>\u6240\u4ee5\u8fd8\u9700\u8981\u7ecf\u8fc7 Embedding&#xff1a;<\/p>\n<p>Token ID<\/p>\n<p>12345<\/p>\n<p>   \u2193<\/p>\n<p>Embedding<\/p>\n<p>   \u2193<\/p>\n<p>[0.21, -0.53, 0.76, &#8230;]<\/p>\n<p>\u6700\u7ec8&#xff0c;\u4e00\u4e2a Token \u4f1a\u88ab\u8868\u793a\u6210\u4e00\u4e2a\u5411\u91cf\u3002<\/p>\n<hr \/>\n<h2>\u4e94\u3001Position Embedding \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Transformer \u672c\u8eab\u9700\u8981\u77e5\u9053&#xff1a;<\/p>\n<p>Token \u51fa\u73b0\u5728\u53e5\u5b50\u7684\u4ec0\u4e48\u4f4d\u7f6e\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u6211 \u559c\u6b22 AI<\/p>\n<p>\u4e0e&#xff1a;<\/p>\n<p>AI \u559c\u6b22 \u6211<\/p>\n<p>\u5373\u4f7f\u5305\u542b\u76f8\u4f3c Token&#xff0c;\u987a\u5e8f\u4e0d\u540c&#xff0c;\u542b\u4e49\u4e5f\u53ef\u80fd\u5b8c\u5168\u4e0d\u540c\u3002<\/p>\n<p>\u56e0\u6b64\u901a\u5e38\u9700\u8981\u52a0\u5165\u4f4d\u7f6e\u4fe1\u606f&#xff1a;<\/p>\n<p>Token Embedding<br \/>\n       &#043;<br \/>\nPosition Embedding<br \/>\n       \u2193<br \/>\n\u6700\u7ec8\u8f93\u5165\u5411\u91cf<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a&#xff1a;<\/p>\n<p>Token Embedding<br \/>\n\u544a\u8bc9\u6a21\u578b&#xff1a;<\/p>\n<p>\u201c\u8fd9\u662f\u4ec0\u4e48\u201d<\/p>\n<p>Position Embedding<br \/>\n\u544a\u8bc9\u6a21\u578b&#xff1a;<\/p>\n<p>\u201c\u5b83\u5728\u54ea\u91cc\u201d<\/p>\n<hr \/>\n<h2>\u516d\u3001Transformer \u6a21\u578b\u5185\u90e8\u5230\u5e95\u662f\u4ec0\u4e48\u7ed3\u6784&#xff1f;<\/h2>\n<p>Transformer \u5e76\u4e0d\u662f\u4e00\u4e2a\u5de8\u5927\u7684\u5355\u5c42\u7f51\u7edc\u3002<\/p>\n<p>\u800c\u662f\u7531\u5f88\u591a\u5c42\u4e0d\u65ad\u5806\u53e0\u3002<\/p>\n<p>\u6574\u4f53\u5c42\u7ea7\u53ef\u4ee5\u8868\u793a\u6210&#xff1a;<\/p>\n<p>Model<br \/>\n\u6a21\u578b<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Layer \/ Block 1<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Layer \/ Block 2<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Layer \/ Block 3<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 &#8230;<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 Layer \/ Block N<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<p>Layer<\/p>\n<p>\u548c&#xff1a;<\/p>\n<p>Block<\/p>\n<p>\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\u90fd\u53ef\u4ee5\u7406\u89e3\u6210\u4e00\u4e2a\u5b8c\u6574\u7684 Transformer \u5904\u7406\u5355\u5143\u3002<\/p>\n<hr \/>\n<h2>\u4e03\u3001Layer\u3001Block\u3001Module\u3001Linear \u7684\u5173\u7cfb<\/h2>\n<p>\u8fd9\u662f\u7406\u89e3 Transformer \u7ed3\u6784\u975e\u5e38\u91cd\u8981\u7684\u4e00\u7ec4\u6982\u5ff5\u3002<\/p>\n<p>\u4ece\u5927\u5230\u5c0f\u53ef\u4ee5\u8bb0\u6210&#xff1a;<\/p>\n<p>Model<br \/>\n  \u2193<br \/>\nLayer \/ Block<br \/>\n  \u2193<br \/>\nModule<br \/>\n  \u2193<br \/>\nLinear<br \/>\n  \u2193<br \/>\nWeight \/ Bias<\/p>\n<p>\u66f4\u52a0\u5b8c\u6574\u4e00\u70b9&#xff1a;<\/p>\n<p>GPT Model<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Transformer Block 1<br \/>\n\u2502     \u2502<br \/>\n\u2502     \u251c\u2500\u2500 Attention Module<br \/>\n\u2502     \u2502      \u2502<br \/>\n\u2502     \u2502      \u251c\u2500\u2500 Linear<br \/>\n\u2502     \u2502      \u251c\u2500\u2500 Linear<br \/>\n\u2502     \u2502      \u251c\u2500\u2500 Linear<br \/>\n\u2502     \u2502      \u2514\u2500\u2500 Linear<br \/>\n\u2502     \u2502<br \/>\n\u2502     \u251c\u2500\u2500 Feed Forward Module<br \/>\n\u2502     \u2502      \u2502<br \/>\n\u2502     \u2502      \u251c\u2500\u2500 Linear<br \/>\n\u2502     \u2502      \u2514\u2500\u2500 Linear<br \/>\n\u2502     \u2502<br \/>\n\u2502     \u2514\u2500\u2500 LayerNorm \u7b49<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Transformer Block 2<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Transformer Block 3<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 &#8230;<\/p>\n<p>\u6240\u4ee5\u53ef\u4ee5\u603b\u7ed3\u4e3a&#xff1a;<\/p>\n<p>Model<br \/>\n\u7531\u5f88\u591a Block \u7ec4\u6210<\/p>\n<p>Block<br \/>\n\u7531\u5f88\u591a Module \u7ec4\u6210<\/p>\n<p>Module<br \/>\n\u5185\u90e8\u53c8\u5305\u542b Linear \u7b49\u57fa\u7840\u7ed3\u6784<\/p>\n<p>Linear<br \/>\n\u5185\u90e8\u5305\u542b Weight\u3001Bias \u7b49\u53c2\u6570<\/p>\n<hr \/>\n<h2>\u516b\u3001\u4e00\u4e2a Transformer Block \u5185\u90e8\u6709\u4ec0\u4e48&#xff1f;<\/h2>\n<p>\u4e00\u4e2a Transformer Block \u901a\u5e38\u4e3b\u8981\u5305\u542b\u4e24\u5927\u90e8\u5206&#xff1a;<\/p>\n<p>Multi-Head Self-Attention<\/p>\n<p>\u548c&#xff1a;<\/p>\n<p>Feed Forward Network<\/p>\n<p>\u518d\u914d\u5408&#xff1a;<\/p>\n<p>Residual Connection<\/p>\n<p>LayerNorm<\/p>\n<p>\u53ef\u4ee5\u7b80\u5316\u6210&#xff1a;<\/p>\n<p>\u8f93\u5165 X<br \/>\n  \u2193<\/p>\n<p>Multi-Head Self-Attention<br \/>\n\u3010\u8ba9\u4e0d\u540c Token \u4e4b\u95f4\u8fdb\u884c\u4fe1\u606f\u4ea4\u4e92\u3011<\/p>\n<p>  \u2193<\/p>\n<p>Residual Connection<br \/>\n\u3010\u4fdd\u7559\u539f\u59cb\u4fe1\u606f\u3011<\/p>\n<p>  \u2193<\/p>\n<p>LayerNorm<br \/>\n\u3010\u8ba9\u8bad\u7ec3\u66f4\u52a0\u7a33\u5b9a\u3011<\/p>\n<p>  \u2193<\/p>\n<p>Feed Forward Network<br \/>\n\u3010\u8fdb\u4e00\u6b65\u5904\u7406\u7279\u5f81\u3011<\/p>\n<p>  \u2193<\/p>\n<p>Residual Connection<\/p>\n<p>  \u2193<\/p>\n<p>LayerNorm<\/p>\n<p>  \u2193<\/p>\n<p>\u8f93\u51fa X&#039;<\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p>Block 1 \u8f93\u51fa<br \/>\n      \u2193<br \/>\nBlock 2 \u8f93\u5165<br \/>\n      \u2193<br \/>\nBlock 2 \u8f93\u51fa<br \/>\n      \u2193<br \/>\nBlock 3<br \/>\n      \u2193<br \/>\n&#8230;<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u8fde\u7eed\u5806\u53e0\u5f88\u591a\u5c42\u3002<\/p>\n<hr \/>\n<h2>\u4e5d\u3001Self-Attention \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Self-Attention \u53ef\u4ee5\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>\u6a21\u578b\u5728\u5904\u7406\u5f53\u524d Token \u65f6&#xff0c;\u5224\u65ad\u5e8f\u5217\u4e2d\u5176\u4ed6 Token \u5bf9\u5b83\u6709\u591a\u91cd\u8981\u3002<\/p>\n<p>\u4f8b\u5982\u4e00\u53e5\u8bdd&#xff1a;<\/p>\n<p>\u5c0f\u660e\u62ff\u8d77\u82f9\u679c&#xff0c;\u56e0\u4e3a\u4ed6\u997f\u4e86\u3002<\/p>\n<p>\u5f53\u6a21\u578b\u5904\u7406&#xff1a;<\/p>\n<p>\u4ed6<\/p>\n<p>\u7684\u65f6\u5019&#xff0c;\u9700\u8981\u5224\u65ad&#xff1a;<\/p>\n<p>\u201c\u4ed6\u201d\u548c\u201c\u5c0f\u660e\u201d\u5173\u7cfb\u5f88\u5f3a<\/p>\n<p>\u201c\u4ed6\u201d\u548c\u201c\u82f9\u679c\u201d\u5173\u7cfb\u76f8\u5bf9\u5f31\u4e00\u4e9b<\/p>\n<p>\u8fd9\u5c31\u662f Attention \u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e4b\u4e00\u3002<\/p>\n<hr \/>\n<h2>\u5341\u3001Q\u3001K\u3001V \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Self-Attention \u4e2d\u6700\u6838\u5fc3\u7684\u4e09\u4e2a\u6982\u5ff5\u5c31\u662f&#xff1a;<\/p>\n<p>Q<br \/>\nK<br \/>\nV<\/p>\n<p>\u5206\u522b\u662f&#xff1a;<\/p>\n<p>Q &#061; Query<\/p>\n<p>K &#061; Key<\/p>\n<p>V &#061; Value<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u7c7b\u6bd4\u6210\u4e00\u6b21\u201c\u641c\u7d22\u201d\u3002<\/p>\n<hr \/>\n<h3>Query<\/h3>\n<p>Query \u8868\u793a&#xff1a;<\/p>\n<p>\u6211\u73b0\u5728\u60f3\u627e\u4ec0\u4e48&#xff1f;<\/p>\n<hr \/>\n<h3>Key<\/h3>\n<p>Key \u8868\u793a&#xff1a;<\/p>\n<p>\u6bcf\u4e2a Token \u53ef\u4ee5\u7528\u4ec0\u4e48\u7279\u5f81\u88ab\u5339\u914d&#xff1f;<\/p>\n<hr \/>\n<h3>Value<\/h3>\n<p>Value \u8868\u793a&#xff1a;<\/p>\n<p>\u8fd9\u4e2a Token \u771f\u6b63\u643a\u5e26\u4e86\u4ec0\u4e48\u4fe1\u606f&#xff1f;<\/p>\n<p>\u4e8e\u662f\u6574\u4e2a\u6d41\u7a0b\u53ef\u4ee5\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>Query<br \/>\n  \u2193<br \/>\n\u548c\u6240\u6709 Key \u8fdb\u884c\u5339\u914d<br \/>\n  \u2193<br \/>\n\u5224\u65ad\u54ea\u4e9b Token \u66f4\u91cd\u8981<br \/>\n  \u2193<br \/>\n\u5f97\u5230\u6ce8\u610f\u529b\u6743\u91cd<br \/>\n  \u2193<br \/>\n\u6839\u636e\u6743\u91cd\u8bfb\u53d6\u5bf9\u5e94 Value<br \/>\n  \u2193<br \/>\n\u5f97\u5230\u65b0\u7684\u8868\u793a<\/p>\n<hr \/>\n<h2>\u5341\u4e00\u3001Self-Attention \u5b8c\u6574\u8ba1\u7b97\u6d41\u7a0b<\/h2>\n<p>\u53ef\u4ee5\u628a Attention \u8ba1\u7b97\u8fc7\u7a0b\u8bb0\u6210\u4e0b\u9762\u8fd9\u5f20\u6587\u5b57\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<p>\u8f93\u5165\u5411\u91cf X<br \/>\n   \u2502<br \/>\n   \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n   \u2193             \u2193             \u2193<\/p>\n<p>Linear         Linear         Linear<\/p>\n<p>   \u2193             \u2193             \u2193<\/p>\n<p>   Q             K             V<\/p>\n<p>Query           Key          Value<\/p>\n<p>   \u2502             \u2502<br \/>\n   \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n          \u2193<\/p>\n<p>       Q \u00d7 K\u1d40<br \/>\n\u3010\u8ba1\u7b97 Token \u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3011<\/p>\n<p>          \u2193<\/p>\n<p>       \u7f29\u653e\u5904\u7406<\/p>\n<p>          \u2193<\/p>\n<p>       Softmax<br \/>\n\u3010\u628a\u5206\u6570\u53d8\u6210\u6ce8\u610f\u529b\u6743\u91cd\u3011<\/p>\n<p>          \u2193<\/p>\n<p>   Attention Weight<br \/>\n\u3010\u6bcf\u4e2a Token \u5e94\u8be5\u5173\u6ce8\u591a\u5c11\u3011<\/p>\n<p>          \u2193<\/p>\n<p>   Attention Weight \u00d7 V<\/p>\n<p>          \u2193<\/p>\n<p>     Attention Output<\/p>\n<p>\u6838\u5fc3\u53ef\u4ee5\u538b\u7f29\u6210&#xff1a;<\/p>\n<p>Q \u548c K<br \/>\n \u2193<br \/>\n\u51b3\u5b9a\u5173\u6ce8\u8c01<\/p>\n<p>V<br \/>\n \u2193<br \/>\n\u63d0\u4f9b\u771f\u6b63\u7684\u4fe1\u606f<\/p>\n<hr \/>\n<h2>\u5341\u4e8c\u3001\u4e3a\u4ec0\u4e48\u8981\u7528 Softmax&#xff1f;<\/h2>\n<p>\u5728 Attention \u4e2d&#xff1a;<\/p>\n<p>Q \u00d7 K\u1d40<\/p>\n<p>\u4f1a\u5f97\u5230\u4e00\u7ec4\u76f8\u5173\u6027\u5206\u6570\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>Token 1&#xff1a;2.3<br \/>\nToken 2&#xff1a;7.8<br \/>\nToken 3&#xff1a;1.5<br \/>\nToken 4&#xff1a;4.2<\/p>\n<p>\u8fd9\u4e9b\u53ea\u662f\u539f\u59cb\u5206\u6570\u3002<\/p>\n<p>\u7ecf\u8fc7 Softmax \u540e&#xff0c;\u53ef\u4ee5\u8f6c\u6210\u66f4\u5bb9\u6613\u4f7f\u7528\u7684\u6743\u91cd\u5206\u5e03&#xff1a;<\/p>\n<p>Token 1<br \/>\n  \u2193<br \/>\n\u4e00\u5b9a\u7684\u6ce8\u610f\u529b\u6743\u91cd<\/p>\n<p>Token 2<br \/>\n  \u2193<br \/>\n\u66f4\u5927\u7684\u6ce8\u610f\u529b\u6743\u91cd<\/p>\n<p>Token 3<br \/>\n  \u2193<br \/>\n\u8f83\u5c0f\u7684\u6ce8\u610f\u529b\u6743\u91cd<\/p>\n<p>\u56e0\u6b64\u53ef\u4ee5\u7b80\u5355\u8bb0&#xff1a;<\/p>\n<p>Softmax \u628a\u4e00\u7ec4\u5206\u6570\u8f6c\u6362\u6210\u4e00\u4e2a\u6982\u7387\u5f0f\u7684\u6743\u91cd\u5206\u5e03&#xff0c;\u8ba9\u6a21\u578b\u77e5\u9053\u5e94\u8be5\u91cd\u70b9\u5173\u6ce8\u54ea\u4e9b Token\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e09\u3001Attention \u548c\u4f59\u5f26\u76f8\u4f3c\u5ea6\u4e0d\u8981\u6df7\u6dc6<\/h2>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5f88\u5bb9\u6613\u6df7\u7684\u77e5\u8bc6\u70b9\u3002<\/p>\n<p>\u5728 Transformer Self-Attention \u4e2d&#xff0c;\u6807\u51c6 Attention \u4e3b\u8981\u4f7f\u7528&#xff1a;<\/p>\n<p>Q \u00d7 K\u1d40<\/p>\n<p>\u4e5f\u5c31\u662f Q \u548c K \u4e4b\u95f4\u7684\u70b9\u79ef\u5173\u7cfb\u3002<\/p>\n<p>\u800c\u5728 RAG\u3001Embedding\u3001\u5411\u91cf\u6570\u636e\u5e93\u4e2d&#xff0c;\u7ecf\u5e38\u4f1a\u770b\u5230&#xff1a;<\/p>\n<p>Cosine Similarity<br \/>\n\u4f59\u5f26\u76f8\u4f3c\u5ea6<\/p>\n<p>\u56e0\u6b64\u53ef\u4ee5\u8fd9\u6837\u8bb0&#xff1a;<\/p>\n<p>Transformer Self-Attention<br \/>\n          \u2193<br \/>\n     Q \u548c K \u70b9\u79ef<\/p>\n<p>RAG \/ Vector Database<br \/>\n          \u2193<br \/>\n\u7ecf\u5e38\u4f7f\u7528\u4f59\u5f26\u76f8\u4f3c\u5ea6<\/p>\n<p>\u4e0d\u8981\u628a\u4e24\u4e2a\u573a\u666f\u6df7\u5728\u4e00\u8d77\u3002<\/p>\n<hr \/>\n<h2>\u5341\u56db\u3001Feed Forward Network \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Attention \u505a\u5b8c Token \u4e4b\u95f4\u7684\u4fe1\u606f\u4ea4\u4e92\u4e4b\u540e&#xff0c;\u8fd8\u9700\u8981\u8fdb\u4e00\u6b65\u5904\u7406\u6bcf\u4e2a Token \u7684\u7279\u5f81\u3002<\/p>\n<p>\u8fd9\u901a\u5e38\u7531&#xff1a;<\/p>\n<p>Feed Forward Network<\/p>\n<p>\u5b8c\u6210\u3002<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u8868\u793a\u6210&#xff1a;<\/p>\n<p>Attention \u8f93\u51fa<br \/>\n     \u2193<\/p>\n<p>Linear<br \/>\n     \u2193<\/p>\n<p>\u6fc0\u6d3b\u51fd\u6570<br \/>\n     \u2193<\/p>\n<p>Linear<br \/>\n     \u2193<\/p>\n<p>\u65b0\u7684\u7279\u5f81\u8868\u793a<\/p>\n<p>\u56e0\u6b64\u4e00\u4e2a Block \u4e2d\u4e24\u5927\u6838\u5fc3\u90e8\u5206\u53ef\u4ee5\u7b80\u5355\u8bb0\u6210&#xff1a;<\/p>\n<p>Attention<br \/>\n   \u2193<br \/>\n\u8d1f\u8d23 Token \u4e4b\u95f4\u7684\u4fe1\u606f\u4ea4\u4e92<\/p>\n<p>FFN<br \/>\n   \u2193<br \/>\n\u8d1f\u8d23\u8fdb\u4e00\u6b65\u5904\u7406 Token \u81ea\u8eab\u7279\u5f81<\/p>\n<hr \/>\n<h2>\u5341\u4e94\u3001Transformer \u5b8c\u6574\u524d\u5411\u4f20\u64ad\u6d41\u7a0b<\/h2>\n<p>\u628a\u524d\u9762\u7684\u5185\u5bb9\u4e32\u8d77\u6765&#xff1a;<\/p>\n<p>\u8f93\u5165\u6587\u672c<br \/>\n   \u2193<\/p>\n<p>Tokenizer<br \/>\n   \u2193<\/p>\n<p>Token<br \/>\n   \u2193<\/p>\n<p>Token ID<br \/>\n   \u2193<\/p>\n<p>Token Embedding<br \/>\n   \u2193<\/p>\n<p>Position Embedding<br \/>\n   \u2193<\/p>\n<p>\u8f93\u5165\u5411\u91cf<br \/>\n   \u2193<\/p>\n<p>Transformer Block 1<br \/>\n   \u2193<\/p>\n<p>Transformer Block 2<br \/>\n   \u2193<\/p>\n<p>Transformer Block 3<br \/>\n   \u2193<\/p>\n<p>&#8230;<\/p>\n<p>   \u2193<\/p>\n<p>Transformer Block N<br \/>\n   \u2193<\/p>\n<p>\u6a21\u578b\u8f93\u51fa<br \/>\n   \u2193<\/p>\n<p>\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>\u5176\u4e2d\u6bcf\u4e00\u4e2a Transformer Block \u5185\u90e8\u53c8\u662f&#xff1a;<\/p>\n<p>\u8f93\u5165<br \/>\n \u2193<br \/>\nSelf-Attention<br \/>\n \u2193<br \/>\nResidual<br \/>\n \u2193<br \/>\nLayerNorm<br \/>\n \u2193<br \/>\nFeed Forward<br \/>\n \u2193<br \/>\nResidual<br \/>\n \u2193<br \/>\nLayerNorm<br \/>\n \u2193<br \/>\n\u8f93\u51fa<\/p>\n<hr \/>\n<h2>\u5341\u516d\u3001\u5927\u8bed\u8a00\u6a21\u578b\u5b8c\u6574\u8bad\u7ec3\u6d41\u7a0b<\/h2>\n<p>\u8bad\u7ec3\u9636\u6bb5\u6700\u91cd\u8981\u3002<\/p>\n<p>\u5b8c\u6574\u6d41\u7a0b\u53ef\u4ee5\u8bb0\u6210&#xff1a;<\/p>\n<p>\u8bad\u7ec3\u6587\u672c<\/p>\n<p>        \u2193<\/p>\n<p>Tokenizer<br \/>\n\u3010\u628a\u6587\u672c\u8f6c\u6362\u6210 Token\u3011<\/p>\n<p>        \u2193<\/p>\n<p>Token ID<\/p>\n<p>        \u2193<\/p>\n<p>Embedding<br \/>\n\u3010Token \u8f6c\u6362\u6210\u5411\u91cf\u3011<\/p>\n<p>        \u2193<\/p>\n<p>Transformer<\/p>\n<p>        \u2193<\/p>\n<p>\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u548c\u6b63\u786e Token \u6bd4\u8f83<\/p>\n<p>        \u2193<\/p>\n<p>Loss<br \/>\n\u3010\u8ba1\u7b97\u9884\u6d4b\u7ed3\u679c\u548c\u6b63\u786e\u7b54\u6848\u4e4b\u95f4\u7684\u5dee\u8ddd\u3011<\/p>\n<p>        \u2193<\/p>\n<p>Backward<br \/>\n\u53cd\u5411\u4f20\u64ad<\/p>\n<p>        \u2193<\/p>\n<p>Gradient<br \/>\n\u68af\u5ea6<\/p>\n<p>        \u2193<\/p>\n<p>Optimizer<\/p>\n<p>        \u2193<\/p>\n<p>\u66f4\u65b0\u6a21\u578b\u53c2\u6570<\/p>\n<p>        \u2193<\/p>\n<p>\u4e0b\u4e00\u6279\u8bad\u7ec3\u6570\u636e<\/p>\n<p>        \u2193<\/p>\n<p>\u518d\u6b21\u8fdb\u884c\u524d\u5411\u4f20\u64ad<\/p>\n<p>        \u2193<\/p>\n<p>\u4e0d\u65ad\u91cd\u590d<\/p>\n<p>\u628a\u5b83\u518d\u538b\u7f29\u4e00\u4e0b&#xff0c;\u5176\u5b9e\u8bad\u7ec3\u53ea\u6709\u56db\u4e2a\u6700\u91cd\u8981\u7684\u9636\u6bb5&#xff1a;<\/p>\n<p>Forward<br \/>\n\u524d\u5411\u4f20\u64ad<br \/>\n   \u2193<\/p>\n<p>Loss<br \/>\n\u8ba1\u7b97\u635f\u5931<br \/>\n   \u2193<\/p>\n<p>Backward<br \/>\n\u53cd\u5411\u4f20\u64ad<br \/>\n   \u2193<\/p>\n<p>Optimizer<br \/>\n\u66f4\u65b0\u53c2\u6570<\/p>\n<hr \/>\n<h2>\u5341\u4e03\u3001Forward \u524d\u5411\u4f20\u64ad\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Forward \u5c31\u662f&#xff1a;<\/p>\n<p>\u8f93\u5165\u6570\u636e\u4ece\u6a21\u578b\u524d\u9762\u4e00\u8def\u8ba1\u7b97\u5230\u6a21\u578b\u8f93\u51fa\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u6587\u672c<br \/>\n \u2193<br \/>\nEmbedding<br \/>\n \u2193<br \/>\nAttention<br \/>\n \u2193<br \/>\nFFN<br \/>\n \u2193<br \/>\n\u591a\u5c42 Transformer<br \/>\n \u2193<br \/>\n\u9884\u6d4b\u7ed3\u679c<\/p>\n<p>\u8fd9\u6574\u4e2a\u8fc7\u7a0b\u5c31\u662f&#xff1a;<\/p>\n<p>Forward Pass<br \/>\n\u524d\u5411\u4f20\u64ad<\/p>\n<hr \/>\n<h2>\u5341\u516b\u3001Loss \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>\u6a21\u578b\u8bad\u7ec3\u65f6&#xff0c;\u6a21\u578b\u4f1a\u9884\u6d4b\u7b54\u6848\u3002<\/p>\n<p>\u4f8b\u5982\u6b63\u786e Token \u662f&#xff1a;<\/p>\n<p>\u4e16\u754c<\/p>\n<p>\u4f46\u6a21\u578b\u9884\u6d4b\u6210&#xff1a;<\/p>\n<p>\u793e\u4f1a<\/p>\n<p>\u5c31\u9700\u8981\u8ba1\u7b97&#xff1a;<\/p>\n<p>\u6a21\u578b\u9884\u6d4b<br \/>\n   \u2193<br \/>\n\u548c\u6b63\u786e\u7b54\u6848\u6bd4\u8f83<br \/>\n   \u2193<br \/>\n\u5dee\u591a\u5c11&#xff1f;<br \/>\n   \u2193<br \/>\nLoss<\/p>\n<p>\u56e0\u6b64\u53ef\u4ee5\u7b80\u5355\u7406\u89e3&#xff1a;<\/p>\n<p>Loss \u8868\u793a\u6a21\u578b\u5f53\u524d\u9884\u6d4b\u5f97\u6709\u591a\u5dee\u3002<\/p>\n<p>Loss \u8d8a\u5927&#xff1a;<\/p>\n<p>\u8bf4\u660e\u9884\u6d4b\u8bef\u5dee\u8d8a\u5927<\/p>\n<p>Loss \u8d8a\u5c0f&#xff1a;<\/p>\n<p>\u8bf4\u660e\u9884\u6d4b\u7ed3\u679c\u901a\u5e38\u8d8a\u63a5\u8fd1\u8bad\u7ec3\u76ee\u6807<\/p>\n<hr \/>\n<h2>\u5341\u4e5d\u3001Backward \u53cd\u5411\u4f20\u64ad\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>\u6709\u4e86 Loss \u4e4b\u540e&#xff0c;\u8fd8\u9700\u8981\u77e5\u9053&#xff1a;<\/p>\n<p>\u5230\u5e95\u5e94\u8be5\u8c03\u6574\u54ea\u4e9b\u53c2\u6570&#xff1f;<\/p>\n<p>\u4e8e\u662f\u8fdb\u884c&#xff1a;<\/p>\n<p>Backward<br \/>\n\u53cd\u5411\u4f20\u64ad<\/p>\n<p>\u5927\u81f4\u8fc7\u7a0b&#xff1a;<\/p>\n<p>Loss<br \/>\n \u2193<br \/>\n\u4ece\u6a21\u578b\u8f93\u51fa\u5411\u524d\u53cd\u63a8<br \/>\n \u2193<br \/>\n\u7ecf\u8fc7\u6700\u540e\u4e00\u5c42<br \/>\n \u2193<br \/>\n\u7ecf\u8fc7\u524d\u9762\u7684 Transformer Block<br \/>\n \u2193<br \/>\n\u4e00\u76f4\u4f20\u64ad\u5230\u6a21\u578b\u524d\u9762<br \/>\n \u2193<br \/>\n\u8ba1\u7b97\u5404\u53c2\u6570\u5bf9\u5e94\u7684\u68af\u5ea6<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u3001Gradient \u68af\u5ea6\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Gradient \u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u6210&#xff1a;<\/p>\n<p>\u53c2\u6570\u5e94\u8be5\u671d\u4ec0\u4e48\u65b9\u5411\u8c03\u6574&#xff0c;\u4ee5\u53ca\u8c03\u6574\u8d8b\u52bf\u6709\u591a\u5927\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u53c2\u6570 W<br \/>\n\u5f53\u524d\u503c&#xff1a;<\/p>\n<p>0.53<\/p>\n<p>\u6a21\u578b\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u5f97\u5230\u5bf9\u5e94\u68af\u5ea6\u3002<\/p>\n<p>Optimizer \u518d\u6839\u636e\u68af\u5ea6\u51b3\u5b9a\u5982\u4f55\u4fee\u6539&#xff1a;<\/p>\n<p>0.53<br \/>\n \u2193<br \/>\n\u8c03\u6574\u4e00\u70b9<br \/>\n \u2193<br \/>\n\u65b0\u7684\u53c2\u6570\u503c<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e00\u3001Optimizer \u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Optimizer \u5c31\u662f&#xff1a;<\/p>\n<p>\u6839\u636e\u68af\u5ea6\u771f\u6b63\u66f4\u65b0\u6a21\u578b\u53c2\u6570\u7684\u5de5\u5177\u3002<\/p>\n<p>\u6574\u4e2a\u5173\u7cfb\u53ef\u4ee5\u8868\u793a\u6210&#xff1a;<\/p>\n<p>Loss<br \/>\n \u2193<br \/>\n\u6a21\u578b\u9519\u591a\u5c11<\/p>\n<p>Backward<br \/>\n \u2193<br \/>\n\u8ba1\u7b97\u9519\u8bef\u5982\u4f55\u5f71\u54cd\u5404\u53c2\u6570<\/p>\n<p>Gradient<br \/>\n \u2193<br \/>\n\u5f97\u5230\u53c2\u6570\u8c03\u6574\u65b9\u5411<\/p>\n<p>Optimizer<br \/>\n \u2193<br \/>\n\u771f\u6b63\u66f4\u65b0\u53c2\u6570<\/p>\n<p>\u6240\u4ee5\u4e0d\u8981\u628a\u8fd9\u4e9b\u6982\u5ff5\u6df7\u5728\u4e00\u8d77\u3002<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u8bb0\u6210&#xff1a;<\/p>\n<p>Loss<br \/>\n\u8d1f\u8d23\u8861\u91cf\u8bef\u5dee<\/p>\n<p>Backward<br \/>\n\u8d1f\u8d23\u8ba1\u7b97\u68af\u5ea6<\/p>\n<p>Gradient<br \/>\n\u8868\u793a\u8c03\u6574\u65b9\u5411<\/p>\n<p>Optimizer<br \/>\n\u8d1f\u8d23\u66f4\u65b0\u53c2\u6570<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e8c\u3001Transformer \u7684\u53c2\u6570\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>Transformer \u5185\u90e8\u5b58\u5728\u5927\u91cf\u53c2\u6570\u3002<\/p>\n<p>\u4e3b\u8981\u5305\u62ec&#xff1a;<\/p>\n<p>Embedding \u53c2\u6570<\/p>\n<p>Attention \u53c2\u6570<\/p>\n<p>Feed Forward \u53c2\u6570<\/p>\n<p>LayerNorm \u53c2\u6570<\/p>\n<p>\u5404\u79cd Weight<\/p>\n<p>\u5404\u79cd Bias<\/p>\n<p>\u4f8b\u5982\u6700\u666e\u901a\u7684 Linear \u5c42&#xff1a;<\/p>\n<p>Y &#061; XW &#043; b<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<p>W<br \/>\n&#061;<br \/>\nWeight<\/p>\n<p>b<br \/>\n&#061;<br \/>\nBias<\/p>\n<p>\u8fd9\u4e9b Weight \u548c Bias \u5c31\u5c5e\u4e8e&#xff1a;<\/p>\n<p>\u6a21\u578b\u53c2\u6570<\/p>\n<p>\u8bad\u7ec3\u6a21\u578b&#xff0c;\u672c\u8d28\u4e0a\u5c31\u662f\u4e0d\u65ad\u8c03\u6574\u8fd9\u4e9b\u53c2\u6570\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e09\u3001\u4e3a\u4ec0\u4e48\u5927\u8bed\u8a00\u6a21\u578b\u4f1a\u6709\u51e0\u5341\u4ebf\u751a\u81f3\u66f4\u591a\u53c2\u6570&#xff1f;<\/h2>\n<p>\u56e0\u4e3a Transformer \u4e2d\u5b58\u5728\u5927\u91cf&#xff1a;<\/p>\n<p>Linear<\/p>\n<p>Attention<\/p>\n<p>Feed Forward<\/p>\n<p>Embedding<\/p>\n<p>\u800c\u6bcf\u4e00\u4e2a Linear \u5c42\u4e2d\u53c8\u53ef\u80fd\u5b58\u5728\u975e\u5e38\u5927\u7684\u6743\u91cd\u77e9\u9635\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>Transformer Block 1<br \/>\n \u2193<br \/>\n\u5927\u91cf\u53c2\u6570<\/p>\n<p>Transformer Block 2<br \/>\n \u2193<br \/>\n\u5927\u91cf\u53c2\u6570<\/p>\n<p>Transformer Block 3<br \/>\n \u2193<br \/>\n\u5927\u91cf\u53c2\u6570<\/p>\n<p>&#8230;<\/p>\n<p>Transformer Block N<br \/>\n \u2193<br \/>\n\u5927\u91cf\u53c2\u6570<\/p>\n<p>\u5927\u91cf Block \u5806\u53e0\u540e&#xff1a;<\/p>\n<p>\u53c2\u6570\u91cf<br \/>\n\u4e0d\u65ad\u7d2f\u79ef<\/p>\n<p>\u56e0\u6b64\u6a21\u578b\u53ef\u80fd\u8fbe\u5230&#xff1a;<\/p>\n<p>\u4ebf\u7ea7\u53c2\u6570<\/p>\n<p>\u5341\u4ebf\u7ea7\u53c2\u6570<\/p>\n<p>\u767e\u4ebf\u7ea7\u53c2\u6570<\/p>\n<p>\u5343\u4ebf\u7ea7\u53c2\u6570<\/p>\n<p>\u751a\u81f3\u66f4\u5927\u89c4\u6a21<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u56db\u3001\u8bad\u7ec3\u65f6\u53c2\u6570\u6570\u91cf\u4f1a\u4e0d\u4f1a\u53d8\u5316&#xff1f;<\/h2>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b&#xff1a;<\/p>\n<p>\u53c2\u6570\u7684\u6570\u503c<br \/>\n\u4e0d\u65ad\u53d8\u5316<\/p>\n<p>\u4f46\u662f&#xff1a;<\/p>\n<p>\u53c2\u6570\u6570\u91cf<br \/>\n\u4e0d\u4f1a\u56e0\u4e3a\u666e\u901a\u8bad\u7ec3\u8fc7\u7a0b\u4e0d\u65ad\u53d8\u5316<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u8bad\u7ec3\u4e4b\u524d&#xff1a;<\/p>\n<p>W &#061; 0.52<\/p>\n<p>\u8bad\u7ec3\u4e4b\u540e&#xff1a;<\/p>\n<p>W &#061; 0.47<\/p>\n<p>\u53d8\u5316\u7684\u662f&#xff1a;<\/p>\n<p>\u53c2\u6570\u503c<\/p>\n<p>\u800c\u4e0d\u662f&#xff1a;<\/p>\n<p>\u53c2\u6570\u4e2a\u6570<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e94\u3001\u8bad\u7ec3\u548c\u63a8\u7406\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/h2>\n<p>\u8fd9\u662f\u5b66\u4e60\u5927\u8bed\u8a00\u6a21\u578b\u65f6\u975e\u5e38\u91cd\u8981\u7684\u4e00\u7ec4\u533a\u522b\u3002<\/p>\n<h3>\u8bad\u7ec3<\/h3>\n<p>\u8f93\u5165\u6570\u636e<br \/>\n \u2193<br \/>\nForward<br \/>\n \u2193<br \/>\n\u9884\u6d4b\u7ed3\u679c<br \/>\n \u2193<br \/>\nLoss<br \/>\n \u2193<br \/>\nBackward<br \/>\n \u2193<br \/>\nGradient<br \/>\n \u2193<br \/>\nOptimizer<br \/>\n \u2193<br \/>\n\u66f4\u65b0\u53c2\u6570<\/p>\n<p>\u8bad\u7ec3\u9636\u6bb5\u7684\u6838\u5fc3&#xff1a;<\/p>\n<p>\u53c2\u6570\u4f1a\u66f4\u65b0<\/p>\n<hr \/>\n<h3>\u63a8\u7406<\/h3>\n<p>\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u4e4b\u540e&#xff0c;\u5c31\u8fdb\u5165\u63a8\u7406\u9636\u6bb5\u3002<\/p>\n<p>\u63a8\u7406\u53ef\u4ee5\u7b80\u5316\u6210&#xff1a;<\/p>\n<p>\u7528\u6237\u8f93\u5165 Prompt<\/p>\n<p>        \u2193<\/p>\n<p>Tokenizer<\/p>\n<p>        \u2193<\/p>\n<p>Token ID<\/p>\n<p>        \u2193<\/p>\n<p>Embedding<\/p>\n<p>        \u2193<\/p>\n<p>Transformer<\/p>\n<p>        \u2193<\/p>\n<p>\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u9009\u62e9\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u8ffd\u52a0\u5230\u5f53\u524d\u5e8f\u5217<\/p>\n<p>        \u2193<\/p>\n<p>\u7ee7\u7eed\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u4e0d\u65ad\u91cd\u590d<\/p>\n<p>\u63a8\u7406\u9636\u6bb5\u4e3b\u8981\u8fdb\u884c&#xff1a;<\/p>\n<p>Forward<\/p>\n<p>\u800c\u4e0d\u4f1a\u50cf\u666e\u901a\u8bad\u7ec3\u90a3\u6837&#xff1a;<\/p>\n<p>Loss<br \/>\n \u2193<br \/>\nBackward<br \/>\n \u2193<br \/>\nOptimizer<br \/>\n \u2193<br \/>\n\u66f4\u65b0\u53c2\u6570<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u516d\u3001\u4ec0\u4e48\u662f\u81ea\u56de\u5f52\u751f\u6210&#xff1f;<\/h2>\n<p>GPT \u7c7b\u5927\u8bed\u8a00\u6a21\u578b\u901a\u5e38\u91c7\u7528&#xff1a;<\/p>\n<p>Autoregressive Generation<br \/>\n\u81ea\u56de\u5f52\u751f\u6210<\/p>\n<p>\u610f\u601d\u662f&#xff1a;<\/p>\n<p>\u6bcf\u6b21\u9884\u6d4b\u4e0b\u4e00\u4e2a Token&#xff0c;\u7136\u540e\u628a\u65b0\u751f\u6210\u7684 Token \u52a0\u5230\u5df2\u6709\u5e8f\u5217\u4e2d&#xff0c;\u518d\u7ee7\u7eed\u9884\u6d4b\u4e0b\u4e00\u4e2a\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;<\/p>\n<p>\u6211\u559c\u6b22\u5b66\u4e60<\/p>\n<p>        \u2193<\/p>\n<p>\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<\/p>\n<p>        \u2193<\/p>\n<p>\u4eba\u5de5<\/p>\n<p>        \u2193<\/p>\n<p>\u65b0\u7684\u5e8f\u5217&#xff1a;<\/p>\n<p>\u6211\u559c\u6b22\u5b66\u4e60\u4eba\u5de5<\/p>\n<p>        \u2193<\/p>\n<p>\u7ee7\u7eed\u9884\u6d4b<\/p>\n<p>        \u2193<\/p>\n<p>\u667a\u80fd<\/p>\n<p>        \u2193<\/p>\n<p>\u65b0\u7684\u5e8f\u5217&#xff1a;<\/p>\n<p>\u6211\u559c\u6b22\u5b66\u4e60\u4eba\u5de5\u667a\u80fd<\/p>\n<p>\u771f\u6b63\u5904\u7406\u7684\u662f Token&#xff0c;\u6240\u4ee5\u66f4\u52a0\u51c6\u786e\u7684\u6d41\u7a0b\u662f&#xff1a;<\/p>\n<p>Token 1<br \/>\n   \u2193<br \/>\n\u9884\u6d4b Token 2<\/p>\n<p>Token 1 &#043; Token 2<br \/>\n   \u2193<br \/>\n\u9884\u6d4b Token 3<\/p>\n<p>Token 1 &#043; Token 2 &#043; Token 3<br \/>\n   \u2193<br \/>\n\u9884\u6d4b Token 4<\/p>\n<p>&#8230;<\/p>\n<p>\u8fd9\u5c31\u662f&#xff1a;<\/p>\n<p>\u81ea\u56de\u5f52\u751f\u6210<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e03\u3001\u8bad\u7ec3\u548c\u63a8\u7406\u6d41\u7a0b\u5bf9\u6bd4<\/h2>\n<p>\u628a\u4e24\u4e2a\u6d41\u7a0b\u653e\u5728\u4e00\u8d77\u5c31\u975e\u5e38\u6e05\u695a\u4e86\u3002<\/p>\n<p>&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u8bad\u7ec3 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>\u8f93\u5165\u6587\u672c<br \/>\n   \u2193<br \/>\nTokenizer<br \/>\n   \u2193<br \/>\nEmbedding<br \/>\n   \u2193<br \/>\nTransformer<br \/>\n   \u2193<br \/>\n\u9884\u6d4b Token<br \/>\n   \u2193<br \/>\n\u4e0e\u6b63\u786e Token \u6bd4\u8f83<br \/>\n   \u2193<br \/>\nLoss<br \/>\n   \u2193<br \/>\nBackward<br \/>\n   \u2193<br \/>\nGradient<br \/>\n   \u2193<br \/>\nOptimizer<br \/>\n   \u2193<br \/>\n\u66f4\u65b0\u53c2\u6570<\/p>\n<p>&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u63a8\u7406 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p>\u7528\u6237 Prompt<br \/>\n   \u2193<br \/>\nTokenizer<br \/>\n   \u2193<br \/>\nEmbedding<br \/>\n   \u2193<br \/>\nTransformer<br \/>\n   \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n\u9009\u62e9 Token<br \/>\n   \u2193<br \/>\n\u52a0\u5165\u5f53\u524d\u5e8f\u5217<br \/>\n   \u2193<br \/>\n\u518d\u6b21 Forward<br \/>\n   \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n\u4e0d\u65ad\u91cd\u590d<\/p>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3&#xff1a;<\/p>\n<p>\u8bad\u7ec3<br \/>\n&#061;<br \/>\nForward &#043; Backward &#043; Update<\/p>\n<p>\u63a8\u7406<br \/>\n&#061;<br \/>\n\u4e0d\u65ad Forward &#043; \u751f\u6210 Token<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u516b\u3001Attention\u3001RAG \u4e2d\u7684\u76f8\u4f3c\u5ea6\u518d\u5bf9\u6bd4\u4e00\u6b21<\/h2>\n<p>\u8fd9\u4e2a\u77e5\u8bc6\u70b9\u975e\u5e38\u5bb9\u6613\u6df7&#xff0c;\u6240\u4ee5\u6700\u540e\u518d\u603b\u7ed3\u4e00\u6b21\u3002<\/p>\n<p>Transformer Self-Attention<\/p>\n<p>Q<br \/>\n \u2193<br \/>\n\u548c K \u505a\u70b9\u79ef<br \/>\n \u2193<br \/>\n\u8ba1\u7b97\u76f8\u5173\u6027<br \/>\n \u2193<br \/>\nSoftmax<br \/>\n \u2193<br \/>\n\u5f97\u5230 Attention Weight<br \/>\n \u2193<br \/>\n\u52a0\u6743 V<\/p>\n<p>\u800c&#xff1a;<\/p>\n<p>RAG \/ Vector Database<\/p>\n<p>Query<br \/>\n \u2193<br \/>\nEmbedding<br \/>\n \u2193<br \/>\n\u5411\u91cf<br \/>\n \u2193<br \/>\n\u4e0e\u6587\u6863\u5411\u91cf\u8ba1\u7b97\u76f8\u4f3c\u5ea6<br \/>\n \u2193<br \/>\n\u627e\u6700\u76f8\u5173\u7684\u6587\u6863<\/p>\n<p>\u6240\u4ee5&#xff1a;<\/p>\n<p>Transformer Attention<\/p>\n<p>\u91cd\u70b9&#xff1a;<br \/>\nQ \u00d7 K\u1d40<\/p>\n<p>RAG<\/p>\n<p>\u7ecf\u5e38\u5173\u6ce8&#xff1a;<br \/>\nCosine Similarity<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e5d\u3001PyTorch\u3001TensorFlow\u3001Hugging Face Transformers \u7684\u5173\u7cfb<\/h2>\n<p>\u5b9e\u73b0 Transformer \u65f6\u7ecf\u5e38\u4f1a\u9047\u5230&#xff1a;<\/p>\n<table>\n<tr>\u5de5\u5177\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u6210<\/tr>\n<tbody>\n<tr>\n<td>PyTorch<\/td>\n<td>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6<\/td>\n<\/tr>\n<tr>\n<td>TensorFlow<\/td>\n<td>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6<\/td>\n<\/tr>\n<tr>\n<td>Hugging Face Transformers<\/td>\n<td>\u9884\u8bad\u7ec3 Transformer \u6a21\u578b\u5e93&#xff0c;\u65b9\u4fbf\u52a0\u8f7d\u3001\u8bad\u7ec3\u548c\u63a8\u7406\u6a21\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>PyTorch<br \/>\n \u2193<br \/>\n\u8d1f\u8d23\u5e95\u5c42 Tensor\u3001\u68af\u5ea6\u3001\u795e\u7ecf\u7f51\u7edc\u8ba1\u7b97<\/p>\n<p>Hugging Face Transformers<br \/>\n \u2193<br \/>\n\u5728\u4e0a\u5c42\u63d0\u4f9b GPT\u3001BERT \u7b49\u6a21\u578b\u5b9e\u73b0<\/p>\n<hr \/>\n<h2>\u4e09\u5341\u3001\u6a21\u578b\u7ed3\u6784\u603b\u590d\u4e60\u56fe<\/h2>\n<p>\u6700\u540e\u628a\u6574\u4e2a\u6a21\u578b\u7ed3\u6784\u538b\u7f29\u6210\u4e00\u5f20\u56fe&#xff1a;<\/p>\n<p>\u5927\u8bed\u8a00\u6a21\u578b<br \/>\nGPT \u7c7b\u6a21\u578b<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nTokenizer<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nToken ID<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nEmbedding<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502 Transformer Block 1     \u2502<br \/>\n\u2502                         \u2502<br \/>\n\u2502 Self-Attention          \u2502<br \/>\n\u2502       \u2193                 \u2502<br \/>\n\u2502 Residual &#043; LayerNorm    \u2502<br \/>\n\u2502       \u2193                 \u2502<br \/>\n\u2502 Feed Forward            \u2502<br \/>\n\u2502       \u2193                 \u2502<br \/>\n\u2502 Residual &#043; LayerNorm    \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nTransformer Block 2<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nTransformer Block 3<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\n&#8230;<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\nTransformer Block N<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n      \u2502<br \/>\n      \u2193<br \/>\n\u4e0b\u4e00\u4e2a Token \u6982\u7387\u5206\u5e03<\/p>\n<p>\u800c Attention \u5185\u90e8\u662f&#xff1a;<\/p>\n<p>\u8f93\u5165 X<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Linear \u2192 Q<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Linear \u2192 K<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 Linear \u2192 V<\/p>\n<p>Q \u00d7 K\u1d40<br \/>\n   \u2193<br \/>\n\u76f8\u5173\u6027\u5206\u6570<br \/>\n   \u2193<br \/>\nSoftmax<br \/>\n   \u2193<br \/>\nAttention Weight<br \/>\n   \u2193<br \/>\nAttention Weight \u00d7 V<br \/>\n   \u2193<br \/>\nAttention Output<\/p>\n<hr \/>\n<h2>\u4e09\u5341\u4e00\u3001\u8bad\u7ec3\u5b8c\u6574\u603b\u590d\u4e60\u56fe<\/h2>\n<p>\u8bad\u7ec3\u6587\u672c<br \/>\n   \u2193<br \/>\nTokenizer<br \/>\n   \u2193<br \/>\nToken ID<br \/>\n   \u2193<br \/>\nEmbedding<br \/>\n   \u2193<br \/>\nTransformer<br \/>\n   \u2193<br \/>\nSelf-Attention<br \/>\n   \u2193<br \/>\nFFN<br \/>\n   \u2193<br \/>\n\u591a\u5c42 Block<br \/>\n   \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n\u4e0e\u6b63\u786e Token \u6bd4\u8f83<br \/>\n   \u2193<br \/>\nLoss<br \/>\n   \u2193<br \/>\nBackward<br \/>\n   \u2193<br \/>\nGradient<br \/>\n   \u2193<br \/>\nOptimizer<br \/>\n   \u2193<br \/>\n\u66f4\u65b0 Weight \/ Bias<br \/>\n   \u2193<br \/>\n\u7ee7\u7eed\u4e0b\u4e00\u6279\u6570\u636e<br \/>\n   \u2193<br \/>\n\u4e0d\u65ad\u91cd\u590d<\/p>\n<hr \/>\n<h2>\u4e09\u5341\u4e8c\u3001\u63a8\u7406\u5b8c\u6574\u603b\u590d\u4e60\u56fe<\/h2>\n<p>\u7528\u6237 Prompt<br \/>\n   \u2193<br \/>\nTokenizer<br \/>\n   \u2193<br \/>\nToken ID<br \/>\n   \u2193<br \/>\nEmbedding<br \/>\n   \u2193<br \/>\nTransformer<br \/>\n   \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n\u5f97\u5230 Token \u6982\u7387\u5206\u5e03<br \/>\n   \u2193<br \/>\n\u9009\u62e9\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n\u52a0\u5165\u5f53\u524d\u5e8f\u5217<br \/>\n   \u2193<br \/>\n\u91cd\u65b0\u8fdb\u884c Forward<br \/>\n   \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n   \u2193<br \/>\n&#8230;<br \/>\n   \u2193<br \/>\n\u5b8c\u6210\u751f\u6210<\/p>\n<hr \/>\n<h2>\u4e09\u5341\u4e09\u3001\u6700\u540e\u53ea\u9700\u8981\u8bb0\u4f4f\u8fd9\u6761\u4e3b\u7ebf<\/h2>\n<p>\u5982\u679c\u53ea\u662f\u5feb\u901f\u590d\u4e60 Transformer \u548c\u5927\u8bed\u8a00\u6a21\u578b&#xff0c;\u53ef\u4ee5\u53ea\u8bb0\u4e0b\u9762\u8fd9\u4e00\u6761&#xff1a;<\/p>\n<p>\u6587\u672c<br \/>\n \u2193<br \/>\nToken<br \/>\n \u2193<br \/>\nToken ID<br \/>\n \u2193<br \/>\nEmbedding<br \/>\n \u2193<br \/>\nTransformer Block \u00d7 N<br \/>\n \u2193<br \/>\nSelf-Attention &#043; FFN<br \/>\n \u2193<br \/>\n\u9884\u6d4b\u4e0b\u4e00\u4e2a Token<br \/>\n      \u2502<br \/>\n      \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n      \u2193               \u2193<br \/>\n    \u8bad\u7ec3              \u63a8\u7406<br \/>\n      \u2193               \u2193<br \/>\n    Loss           \u9009\u62e9 Token<br \/>\n      \u2193               \u2193<br \/>\n  Backward         \u52a0\u5165\u5e8f\u5217<br \/>\n      \u2193               \u2193<br \/>\n  Gradient        \u518d\u6b21 Forward<br \/>\n      \u2193               \u2193<br \/>\n Optimizer        \u4e0b\u4e00\u4e2a Token<br \/>\n      \u2193<br \/>\n  \u66f4\u65b0\u53c2\u6570<\/p>\n<p>\u8fdb\u4e00\u6b65\u538b\u7f29&#xff1a;<\/p>\n<p>Transformer \u6a21\u578b\u7ed3\u6784&#xff1a;<\/p>\n<p>Embedding<br \/>\n    \u2193<br \/>\nAttention<br \/>\n    \u2193<br \/>\nFFN<br \/>\n    \u2193<br \/>\n\u91cd\u590d\u591a\u5c42<br \/>\n    \u2193<br \/>\n\u9884\u6d4b Token<\/p>\n<p>\u8bad\u7ec3&#xff1a;<\/p>\n<p>Forward<br \/>\n  \u2193<br \/>\nLoss<br \/>\n  \u2193<br \/>\nBackward<br \/>\n  \u2193<br \/>\nOptimizer<br \/>\n  \u2193<br \/>\n\u66f4\u65b0\u53c2\u6570<\/p>\n<p>\u63a8\u7406&#xff1a;<\/p>\n<p>Forward<br \/>\n  \u2193<br \/>\n\u9884\u6d4b Token<br \/>\n  \u2193<br \/>\n\u8ffd\u52a0 Token<br \/>\n  \u2193<br \/>\n\u518d\u6b21 Forward<br \/>\n  \u2193<br \/>\n\u6301\u7eed\u751f\u6210<\/p>\n<p>\u638c\u63e1\u8fd9\u4e09\u6761\u4e3b\u7ebf\u4e4b\u540e&#xff0c;Transformer\u3001\u5927\u8bed\u8a00\u6a21\u578b\u8bad\u7ec3\u548c\u63a8\u7406\u7684\u6574\u4f53\u903b\u8f91\u57fa\u672c\u5c31\u4e32\u8d77\u6765\u4e86\u3002<\/p>\n<hr \/>\n<p>&#x1f4ee; \u5173\u6ce8\u3010YoanAILab\u3011&#xff0c;\u6301\u7eed\u5206\u4eab AI \u5de5\u7a0b\u5b9e\u6218 \u00d7 \u6a21\u578b\u90e8\u7f72\u6280\u5de7 \u00d7 \u8f6c\u578b\u6210\u957f\u7ecf\u9a8c<br \/>\n&#x1f4ac; \u5982\u679c\u4f60\u89c9\u5f97\u672c\u6587\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1\u652f\u6301&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u7b14\u8bb0\u4e3b\u8981\u7528\u4e8e\u5feb\u901f\u68b3\u7406 Transformer\u3001\u5927\u8bed\u8a00\u6a21\u578b\u3001Self-Attention\u3001\u8bad\u7ec3\u6d41\u7a0b\u548c\u63a8\u7406\u6d41\u7a0b\u3002<br \/>\n\u4e0d\u8ffd\u6c42\u590d\u6742\u6570\u5b66\u63a8\u5bfc&#xff0c;\u800c\u662f\u5c3d\u91cf\u628a\u5404\u4e2a\u6982\u5ff5\u4e32\u6210\u4e00\u6761\u5b8c\u6574\u7684\u903b\u8f91\u94fe\u3002\u4e00\u3001\u5148\u7406\u89e3 Transformer \u5728\u505a\u4ec0\u4e48<br \/>\nTransformer \u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u67b6\u6784\u3002<br \/>\n\u5728\u5927\u8bed\u8a00\u6a21\u578b\u4e2d&#xff0c;\u5927\u91cf\u8ba1\u7b97\u6700\u7ec8\u90fd\u4f1a\u8f6c\u5316\u4e3a&#xff1a;<br \/>\n\u77e9\u9635\u8fd0\u7b97<\/p>\n<p>\u524d\u5411\u4f20\u64ad<\/p>\n<p>\u635f\u5931\u8ba1\u7b97<\/p>\n<p>\u53cd\u5411\u4f20\u64ad<\/p>\n<p>\u53c2\u6570\u66f4\u65b0\u8bad\u7ec3\u6a21\u578b\u65f6&#xff0c;\u53ef\u4ee5\u5148\u628a\u6574\u4e2a\u8fc7\u7a0b\u7b80\u5355\u7406\u89e3\u6210&amp;#xff1<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[841,50,86],"topic":[],"class_list":["post-105029","post","type-post","status-publish","format-standard","hentry","category-server","tag-transformer","tag-50","tag-86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/105029.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u8fd9\u7bc7\u7b14\u8bb0\u4e3b\u8981\u7528\u4e8e\u5feb\u901f\u68b3\u7406 Transformer\u3001\u5927\u8bed\u8a00\u6a21\u578b\u3001Self-Attention\u3001\u8bad\u7ec3\u6d41\u7a0b\u548c\u63a8\u7406\u6d41\u7a0b\u3002 \u4e0d\u8ffd\u6c42\u590d\u6742\u6570\u5b66\u63a8\u5bfc&#xff0c;\u800c\u662f\u5c3d\u91cf\u628a\u5404\u4e2a\u6982\u5ff5\u4e32\u6210\u4e00\u6761\u5b8c\u6574\u7684\u903b\u8f91\u94fe\u3002\u4e00\u3001\u5148\u7406\u89e3 Transformer \u5728\u505a\u4ec0\u4e48 Transformer \u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u67b6\u6784\u3002 \u5728\u5927\u8bed\u8a00\u6a21\u578b\u4e2d&#xff0c;\u5927\u91cf\u8ba1\u7b97\u6700\u7ec8\u90fd\u4f1a\u8f6c\u5316\u4e3a&#xff1a; \u77e9\u9635\u8fd0\u7b97 \u524d\u5411\u4f20\u64ad \u635f\u5931\u8ba1\u7b97 \u53cd\u5411\u4f20\u64ad \u53c2\u6570\u66f4\u65b0\u8bad\u7ec3\u6a21\u578b\u65f6&#xff0c;\u53ef\u4ee5\u5148\u628a\u6574\u4e2a\u8fc7\u7a0b\u7b80\u5355\u7406\u89e3\u6210&amp;#xff1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/105029.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-13T08:33:11+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/105029.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/105029.html\",\"name\":\"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-13T08:33:11+00:00\",\"dateModified\":\"2026-09-13T08:33:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/105029.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/105029.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/105029.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/105029.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u8fd9\u7bc7\u7b14\u8bb0\u4e3b\u8981\u7528\u4e8e\u5feb\u901f\u68b3\u7406 Transformer\u3001\u5927\u8bed\u8a00\u6a21\u578b\u3001Self-Attention\u3001\u8bad\u7ec3\u6d41\u7a0b\u548c\u63a8\u7406\u6d41\u7a0b\u3002 \u4e0d\u8ffd\u6c42\u590d\u6742\u6570\u5b66\u63a8\u5bfc&#xff0c;\u800c\u662f\u5c3d\u91cf\u628a\u5404\u4e2a\u6982\u5ff5\u4e32\u6210\u4e00\u6761\u5b8c\u6574\u7684\u903b\u8f91\u94fe\u3002\u4e00\u3001\u5148\u7406\u89e3 Transformer \u5728\u505a\u4ec0\u4e48 Transformer \u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u67b6\u6784\u3002 \u5728\u5927\u8bed\u8a00\u6a21\u578b\u4e2d&#xff0c;\u5927\u91cf\u8ba1\u7b97\u6700\u7ec8\u90fd\u4f1a\u8f6c\u5316\u4e3a&#xff1a; \u77e9\u9635\u8fd0\u7b97 \u524d\u5411\u4f20\u64ad \u635f\u5931\u8ba1\u7b97 \u53cd\u5411\u4f20\u64ad \u53c2\u6570\u66f4\u65b0\u8bad\u7ec3\u6a21\u578b\u65f6&#xff0c;\u53ef\u4ee5\u5148\u628a\u6574\u4e2a\u8fc7\u7a0b\u7b80\u5355\u7406\u89e3\u6210&amp;#xff1","og_url":"https:\/\/www.wsisp.com\/helps\/105029.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-13T08:33:11+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/105029.html","url":"https:\/\/www.wsisp.com\/helps\/105029.html","name":"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-13T08:33:11+00:00","dateModified":"2026-09-13T08:33:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/105029.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/105029.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/105029.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e00\u6587\u68b3\u7406 Transformer\uff1a\u4ece\u6a21\u578b\u7ed3\u6784\u3001Self-Attention \u5230\u5927\u6a21\u578b\u8bad\u7ec3\u4e0e\u63a8\u7406"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/105029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=105029"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/105029\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=105029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=105029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=105029"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=105029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}