{"id":46125,"date":"2025-07-30T02:26:43","date_gmt":"2025-07-29T18:26:43","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46125.html"},"modified":"2025-07-30T02:26:43","modified_gmt":"2025-07-29T18:26:43","slug":"transformer%e7%bc%96%e7%a0%81%e5%99%a8%e9%83%a8%e5%88%86%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46125.html","title":{"rendered":"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0"},"content":{"rendered":"<h2>\u4e00.\u524d\u8a00<\/h2>\n<p>\u4e0a\u7ae0\u8282\u4ecb\u7ecd\u4e86\u8f93\u5165\u90e8\u5206\u5b9e\u73b0&#xff0c;\u672c\u7ae0\u8282\u6765\u4ecb\u7ecd\u4e00\u4e0b\u7f16\u7801\u5668\u7684\u5b9e\u73b0&#xff0c;\u7f16\u7801\u5668\u5185\u5bb9\u6709\u70b9\u591a&#xff0c;\u8bf7\u5927\u5bb6\u505a\u597d\u51c6\u5907&#xff0c;\u4e86\u89e3\u7f16\u7801\u5668\u4e2d\u5404\u4e2a\u7ec4\u6210\u90e8\u5206\u7684\u4f5c\u7528\u5e76\u4e14\u638c\u63e1\u7f16\u7801\u5668\u4e2d\u5404\u4e2a\u7ec4\u6210\u90e8\u5206\u7684\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n<h2>\u4e8c.\u7f16\u7801\u5668\u4ecb\u7ecd<\/h2>\n<p>\u7f16\u7801\u5668\u90e8\u5206: * \u7531N\u4e2a\u7f16\u7801\u5668\u5c42\u5806\u53e0\u800c\u6210 * \u6bcf\u4e2a\u7f16\u7801\u5668\u5c42\u7531\u4e24\u4e2a\u5b50\u5c42\u8fde\u63a5\u7ed3\u6784\u7ec4\u6210 * \u7b2c\u4e00\u4e2a\u5b50\u5c42\u8fde\u63a5\u7ed3\u6784\u5305\u62ec\u4e00\u4e2a\u591a\u5934\u81ea\u6ce8\u610f\u529b\u5b50\u5c42\u548c\u89c4\u8303\u5316\u5c42\u4ee5\u53ca\u4e00\u4e2a\u6b8b\u5dee\u8fde\u63a5 * \u7b2c\u4e8c\u4e2a\u5b50\u5c42\u8fde\u63a5\u7ed3\u6784\u5305\u62ec\u4e00\u4e2a\u524d\u9988\u5168\u8fde\u63a5\u5b50\u5c42\u548c\u89c4\u8303\u5316\u5c42\u4ee5\u53ca\u4e00\u4e2a\u6b8b\u5dee\u8fde\u63a5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912625b0ae.png\" width=\"757\" \/><\/p>\n<h2>\u4e09.\u63a9\u7801\u5f20\u91cf\u00a0<\/h2>\n<h3>3.1 \u63a9\u7801\u5f20\u91cf\u4ecb\u7ecd\u00a0<\/h3>\n<p>\u63a9\u4ee3\u8868\u906e\u63a9&#xff0c;\u7801\u5c31\u662f\u6211\u4eec\u5f20\u91cf\u4e2d\u7684\u6570\u503c&#xff0c;\u5b83\u7684\u5c3a\u5bf8\u4e0d\u5b9a&#xff0c;\u91cc\u9762\u4e00\u822c\u53ea\u67091\u548c0\u7684\u5143\u7d20&#xff0c;\u4ee3\u8868\u4f4d\u7f6e\u88ab\u906e\u63a9\u6216\u8005\u4e0d\u88ab\u906e\u63a9&#xff0c;\u81f3\u4e8e\u662f0\u4f4d\u7f6e\u88ab\u906e\u63a9\u8fd8\u662f1\u4f4d\u7f6e\u88ab\u906e\u63a9\u53ef\u4ee5\u81ea\u5b9a\u4e49&#xff0c;\u56e0\u6b64\u5b83\u7684\u4f5c\u7528\u5c31\u662f\u8ba9\u53e6\u5916\u4e00\u4e2a\u5f20\u91cf\u4e2d\u7684\u4e00\u4e9b\u6570\u503c\u88ab\u906e\u63a9&#xff0c;\u4e5f\u53ef\u4ee5\u8bf4\u88ab\u66ff\u6362, \u5b83\u7684\u8868\u73b0\u5f62\u5f0f\u662f\u4e00\u4e2a\u5f20\u91cf.<\/p>\n<h3>3.2\u00a0\u63a9\u7801\u5f20\u91cf\u7684\u4f5c\u7528<\/h3>\n<p>\u5728transformer\u4e2d, \u63a9\u7801\u5f20\u91cf\u7684\u4e3b\u8981\u4f5c\u7528\u5728\u5e94\u7528attention(\u5c06\u5728\u4e0b\u4e00\u5c0f\u8282\u8bb2\u89e3)\u65f6&#xff0c;\u6709\u4e00\u4e9b\u751f\u6210\u7684attention\u5f20\u91cf\u4e2d\u7684\u503c\u8ba1\u7b97\u6709\u53ef\u80fd\u5df2\u77e5\u4e86\u672a\u6765\u4fe1\u606f\u800c\u5f97\u5230\u7684&#xff0c;\u672a\u6765\u4fe1\u606f\u88ab\u770b\u5230\u662f\u56e0\u4e3a\u8bad\u7ec3\u65f6\u4f1a\u628a\u6574\u4e2a\u8f93\u51fa\u7ed3\u679c\u90fd\u4e00\u6b21\u6027\u8fdb\u884cEmbedding&#xff0c;\u4f46\u662f\u7406\u8bba\u4e0a\u89e3\u7801\u5668\u7684\u7684\u8f93\u51fa\u5374\u4e0d\u662f\u4e00\u6b21\u5c31\u80fd\u4ea7\u751f\u6700\u7ec8\u7ed3\u679c\u7684&#xff0c;\u800c\u662f\u4e00\u6b21\u6b21\u901a\u8fc7\u4e0a\u4e00\u6b21\u7ed3\u679c\u7efc\u5408\u5f97\u51fa\u7684&#xff0c;\u56e0\u6b64&#xff0c;\u672a\u6765\u7684\u4fe1\u606f\u53ef\u80fd\u88ab\u63d0\u524d\u5229\u7528. \u6240\u4ee5&#xff0c;\u6211\u4eec\u4f1a\u8fdb\u884c\u906e\u63a9. \u5173\u4e8e\u89e3\u7801\u5668\u7684\u6709\u5173\u77e5\u8bc6\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8bb2\u89e3.<\/p>\n<h3>3.3\u00a0\u751f\u6210\u63a9\u7801\u5f20\u91cf\u7684\u4ee3\u7801\u5206\u6790<\/h3>\n<p># \u5bfc\u5165\u5fc5\u5907\u7684\u5de5\u5177\u5305<br \/>\nimport torch<br \/>\nimport numpy as np<\/p>\n<p>def subsequent_mask(size):<br \/>\n    &#034;&#034;&#034;\u751f\u6210\u5411\u540e\u906e\u63a9\u7684\u63a9\u7801\u5f20\u91cf, \u53c2\u6570size\u662f\u63a9\u7801\u5f20\u91cf\u6700\u540e\u4e24\u4e2a\u7ef4\u5ea6\u7684\u5927\u5c0f, \u5b83\u7684\u6700\u540e\u4e24\u7ef4\u5f62\u6210\u4e00\u4e2a\u65b9\u9635&#034;&#034;&#034;<br \/>\n    # \u5728\u51fd\u6570\u4e2d, \u9996\u5148\u5b9a\u4e49\u63a9\u7801\u5f20\u91cf\u7684\u5f62\u72b6<br \/>\n    attn_shape &#061; (1, size, size)<\/p>\n<p>    # \u7136\u540e\u4f7f\u7528np.ones\u65b9\u6cd5\u5411\u8fd9\u4e2a\u5f62\u72b6\u4e2d\u6dfb\u52a01\u5143\u7d20,\u5f62\u6210\u4e0a\u4e09\u89d2\u9635, \u6700\u540e\u4e3a\u4e86\u8282\u7ea6\u7a7a\u95f4,<br \/>\n    # \u518d\u4f7f\u5176\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u53d8\u4e3a\u65e0\u7b26\u53f78\u4f4d\u6574\u5f62unit8<br \/>\n    subsequent_mask &#061; np.triu(np.ones(attn_shape), k&#061;1).astype(&#039;uint8&#039;)<\/p>\n<p>    # \u6700\u540e\u5c06numpy\u7c7b\u578b\u8f6c\u5316\u4e3atorch\u4e2d\u7684tensor, \u5185\u90e8\u505a\u4e00\u4e2a1 &#8211; \u7684\u64cd\u4f5c,<br \/>\n    # \u5728\u8fd9\u4e2a\u5176\u5b9e\u662f\u505a\u4e86\u4e00\u4e2a\u4e09\u89d2\u9635\u7684\u53cd\u8f6c, subsequent_mask\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u4f1a\u88ab1\u51cf,<br \/>\n    # \u5982\u679c\u662f0, subsequent_mask\u4e2d\u7684\u8be5\u4f4d\u7f6e\u75310\u53d8\u62101<br \/>\n    # \u5982\u679c\u662f1, subsequent_mask\u4e2d\u7684\u8be5\u4f4d\u7f6e\u75311\u53d8\u62100<br \/>\n    return torch.from_numpy(1 &#8211; subsequent_mask)<\/p>\n<ul>\n<li>np.triu\u6f14\u793a:<\/li>\n<\/ul>\n<p>\u00a0&gt;&gt;&gt; np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], k&#061;-1)<\/p>\n<p>array([[ 1, 2, 3],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 4, 5, 6],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 8, 9],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 12]])<\/p>\n<\/p>\n<p>&gt;&gt;&gt; np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], k&#061;0)<\/p>\n<p>array([[ 1, 2, 3],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 5, 6],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 9],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 0]])<\/p>\n<\/p>\n<p>&gt;&gt;&gt; np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], k&#061;1)<\/p>\n<p>array([[ 0, 2, 3],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 6],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 0],<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [ 0, 0, 0]])<\/p>\n<ul>\n<li>\u8f93\u5165\u5b9e\u4f8b:<\/li>\n<\/ul>\n<p>\u00a0# \u751f\u6210\u7684\u63a9\u7801\u5f20\u91cf\u7684\u6700\u540e\u4e24\u7ef4\u7684\u5927\u5c0f<\/p>\n<p>size &#061; 5<\/p>\n<ul>\n<li>\u8c03\u7528:<\/li>\n<\/ul>\n<p>\u00a0sm &#061; subsequent_mask(size)<\/p>\n<p>print(&#034;sm:&#034;, sm)<\/p>\n<ul>\n<li>\u8f93\u51fa\u6548\u679c:<\/li>\n<\/ul>\n<p># \u6700\u540e\u4e24\u7ef4\u5f62\u6210\u4e00\u4e2a\u4e0b\u4e09\u89d2\u9635\u00a0<\/p>\n<p>sm: tensor([[[1, 0, 0, 0, 0],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1, 1, 0, 0, 0],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1, 1, 1, 0, 0],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1, 1, 1, 1, 0],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1, 1, 1, 1, 1]]], dtype&#061;torch.uint8)<\/p>\n<h3>\u00a03.4 \u63a9\u7801\u5f20\u91cf\u7684\u53ef\u89c6\u5316<\/h3>\n<p>plt.figure(figsize&#061;(5, 5))<br \/>\nplt.imshow(subsequent_mask(20)[0])<br \/>\nplt.show()<\/p>\n<ul>\n<li>\u8f93\u51fa\u6548\u679c:<\/li>\n<\/ul>\n<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"500\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912626a485.png\" width=\"500\" \/><\/p>\n<ul>\n<li>\u6548\u679c\u5206\u6790:<\/li>\n<li>\u901a\u8fc7\u89c2\u5bdf\u53ef\u89c6\u5316\u65b9\u9635, \u9ec4\u8272\u662f1\u7684\u90e8\u5206, \u8fd9\u91cc\u4ee3\u8868\u88ab\u906e\u63a9, \u7d2b\u8272\u4ee3\u8868\u6ca1\u6709\u88ab\u906e\u63a9\u7684\u4fe1\u606f, \u6a2a\u5750\u6807\u4ee3\u8868\u76ee\u6807\u8bcd\u6c47\u7684\u4f4d\u7f6e, \u7eb5\u5750\u6807\u4ee3\u8868\u53ef\u67e5\u770b\u7684\u4f4d\u7f6e;<\/li>\n<li>\u6211\u4eec\u770b\u5230, \u57280\u7684\u4f4d\u7f6e\u6211\u4eec\u4e00\u770b\u671b\u8fc7\u53bb\u90fd\u662f\u9ec4\u8272\u7684, \u90fd\u88ab\u906e\u4f4f\u4e86&#xff0c;1\u7684\u4f4d\u7f6e\u4e00\u773c\u671b\u8fc7\u53bb\u8fd8\u662f\u9ec4\u8272, \u8bf4\u660e\u7b2c\u4e00\u6b21\u8bcd\u8fd8\u6ca1\u6709\u4ea7\u751f, \u4ece\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u770b\u8fc7\u53bb, \u5c31\u80fd\u770b\u5230\u4f4d\u7f6e1\u7684\u8bcd, \u5176\u4ed6\u4f4d\u7f6e\u770b\u4e0d\u5230, \u4ee5\u6b64\u7c7b\u63a8.<\/li>\n<\/ul>\n<h3>3.5 \u63a9\u7801\u5f20\u91cf\u603b\u7ed3\u00a0<\/h3>\n<ul>\n<li>\n<p>\u5b66\u4e60\u4e86\u4ec0\u4e48\u662f\u63a9\u7801\u5f20\u91cf:<\/p>\n<ul>\n<li>\u63a9\u4ee3\u8868\u906e\u63a9&#xff0c;\u7801\u5c31\u662f\u6211\u4eec\u5f20\u91cf\u4e2d\u7684\u6570\u503c&#xff0c;\u5b83\u7684\u5c3a\u5bf8\u4e0d\u5b9a&#xff0c;\u91cc\u9762\u4e00\u822c\u53ea\u67091\u548c0\u7684\u5143\u7d20&#xff0c;\u4ee3\u8868\u4f4d\u7f6e\u88ab\u906e\u63a9\u6216\u8005\u4e0d\u88ab\u906e\u63a9&#xff0c;\u81f3\u4e8e\u662f0\u4f4d\u7f6e\u88ab\u906e\u63a9\u8fd8\u662f1\u4f4d\u7f6e\u88ab\u906e\u63a9\u53ef\u4ee5\u81ea\u5b9a\u4e49&#xff0c;\u56e0\u6b64\u5b83\u7684\u4f5c\u7528\u5c31\u662f\u8ba9\u53e6\u5916\u4e00\u4e2a\u5f20\u91cf\u4e2d\u7684\u4e00\u4e9b\u6570\u503c\u88ab\u906e\u63a9, \u4e5f\u53ef\u4ee5\u8bf4\u88ab\u66ff\u6362, \u5b83\u7684\u8868\u73b0\u5f62\u5f0f\u662f\u4e00\u4e2a\u5f20\u91cf.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u4e86\u63a9\u7801\u5f20\u91cf\u7684\u4f5c\u7528:<\/p>\n<ul>\n<li>\u5728transformer\u4e2d, \u63a9\u7801\u5f20\u91cf\u7684\u4e3b\u8981\u4f5c\u7528\u5728\u5e94\u7528attention(\u5c06\u5728\u4e0b\u4e00\u5c0f\u8282\u8bb2\u89e3)\u65f6&#xff0c;\u6709\u4e00\u4e9b\u751f\u6210\u7684attetion\u5f20\u91cf\u4e2d\u7684\u503c\u8ba1\u7b97\u6709\u53ef\u80fd\u5df2\u77e5\u91cf\u672a\u6765\u4fe1\u606f\u800c\u5f97\u5230\u7684&#xff0c;\u672a\u6765\u4fe1\u606f\u88ab\u770b\u5230\u662f\u56e0\u4e3a\u8bad\u7ec3\u65f6\u4f1a\u628a\u6574\u4e2a\u8f93\u51fa\u7ed3\u679c\u90fd\u4e00\u6b21\u6027\u8fdb\u884cEmbedding&#xff0c;\u4f46\u662f\u7406\u8bba\u4e0a\u89e3\u7801\u5668\u7684\u7684\u8f93\u51fa\u5374\u4e0d\u662f\u4e00\u6b21\u5c31\u80fd\u4ea7\u751f\u6700\u7ec8\u7ed3\u679c\u7684&#xff0c;\u800c\u662f\u4e00\u6b21\u6b21\u901a\u8fc7\u4e0a\u4e00\u6b21\u7ed3\u679c\u7efc\u5408\u5f97\u51fa\u7684&#xff0c;\u56e0\u6b64&#xff0c;\u672a\u6765\u7684\u4fe1\u606f\u53ef\u80fd\u88ab\u63d0\u524d\u5229\u7528. \u6240\u4ee5&#xff0c;\u6211\u4eec\u4f1a\u8fdb\u884c\u906e\u63a9. \u5173\u4e8e\u89e3\u7801\u5668\u7684\u6709\u5173\u77e5\u8bc6\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8bb2\u89e3.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u5e76\u5b9e\u73b0\u4e86\u751f\u6210\u5411\u540e\u906e\u63a9\u7684\u63a9\u7801\u5f20\u91cf\u51fd\u6570: subsequent_mask<\/p>\n<ul>\n<li>\u5b83\u7684\u8f93\u5165\u662fsize, \u4ee3\u8868\u63a9\u7801\u5f20\u91cf\u7684\u5927\u5c0f.<\/li>\n<li>\u5b83\u7684\u8f93\u51fa\u662f\u4e00\u4e2a\u6700\u540e\u4e24\u7ef4\u5f62\u62101\u65b9\u9635\u7684\u4e0b\u4e09\u89d2\u9635.<\/li>\n<li>\u6700\u540e\u5bf9\u751f\u6210\u7684\u63a9\u7801\u5f20\u91cf\u8fdb\u884c\u4e86\u53ef\u89c6\u5316\u5206\u6790, \u66f4\u6df1\u4e00\u6b65\u7406\u89e3\u4e86\u5b83\u7684\u7528\u9014.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u56db.\u6ce8\u610f\u529b\u673a\u5236<\/h2>\n<p>\u6211\u4eec\u8fd9\u91cc\u4f7f\u7528\u7684\u6ce8\u610f\u529b\u7684\u8ba1\u7b97\u89c4\u5219:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"77\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912627b28e.png\" width=\"589\" \/><\/p>\n<h3>4.1 \u6ce8\u610f\u529b\u8ba1\u7b97\u89c4\u5219\u7684\u4ee3\u7801\u5206\u6790\u00a0<\/h3>\n<\/p>\n<p>import torch<br \/>\nimport torch.nn.functional as F<\/p>\n<p>def attention(query, key, value, mask&#061;None, dropout&#061;None):<br \/>\n    &#034;&#034;&#034;\u6ce8\u610f\u529b\u673a\u5236\u7684\u5b9e\u73b0, \u8f93\u5165\u5206\u522b\u662fquery, key, value, mask: \u63a9\u7801\u5f20\u91cf,<br \/>\n       dropout\u662fnn.Dropout\u5c42\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61, \u9ed8\u8ba4\u4e3aNone&#034;&#034;&#034;<br \/>\n    # \u5728\u51fd\u6570\u4e2d, \u9996\u5148\u53d6query\u7684\u6700\u540e\u4e00\u7ef4\u7684\u5927\u5c0f, \u4e00\u822c\u60c5\u51b5\u4e0b\u5c31\u7b49\u540c\u4e8e\u6211\u4eec\u7684\u8bcd\u5d4c\u5165\u7ef4\u5ea6, \u547d\u540d\u4e3ad_k<br \/>\n    d_k &#061; query.size(-1)<br \/>\n    # \u6309\u7167\u6ce8\u610f\u529b\u516c\u5f0f, \u5c06query\u4e0ekey\u7684\u8f6c\u7f6e\u76f8\u4e58, \u8fd9\u91cc\u9762key\u662f\u5c06\u6700\u540e\u4e24\u4e2a\u7ef4\u5ea6\u8fdb\u884c\u8f6c\u7f6e, \u518d\u9664\u4ee5\u7f29\u653e\u7cfb\u6570\u6839\u53f7\u4e0bd_k, \u8fd9\u79cd\u8ba1\u7b97\u65b9\u6cd5\u4e5f\u79f0\u4e3a\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b\u8ba1\u7b97.<br \/>\n    # \u5f97\u5230\u6ce8\u610f\u529b\u5f97\u5206\u5f20\u91cfscores<br \/>\n    scores &#061; torch.matmul(query, key.transpose(-2, -1)) \/ math.sqrt(d_k)<\/p>\n<p>    # \u63a5\u7740\u5224\u65ad\u662f\u5426\u4f7f\u7528\u63a9\u7801\u5f20\u91cf<br \/>\n    if mask is not None:<br \/>\n        # \u4f7f\u7528tensor\u7684masked_fill\u65b9\u6cd5, \u5c06\u63a9\u7801\u5f20\u91cf\u548cscores\u5f20\u91cf\u6bcf\u4e2a\u4f4d\u7f6e\u4e00\u4e00\u6bd4\u8f83, \u5982\u679c\u63a9\u7801\u5f20\u91cf\u5904\u4e3a0<br \/>\n        # \u5219\u5bf9\u5e94\u7684scores\u5f20\u91cf\u7528-1e9\u8fd9\u4e2a\u503c\u6765\u66ff\u6362, \u5982\u4e0b\u6f14\u793a<br \/>\n        scores &#061; scores.masked_fill(mask &#061;&#061; 0, -1e9)<\/p>\n<p>    # \u5bf9scores\u7684\u6700\u540e\u4e00\u7ef4\u8fdb\u884csoftmax\u64cd\u4f5c, \u4f7f\u7528F.softmax\u65b9\u6cd5, \u7b2c\u4e00\u4e2a\u53c2\u6570\u662fsoftmax\u5bf9\u8c61, \u7b2c\u4e8c\u4e2a\u662f\u76ee\u6807\u7ef4\u5ea6.<br \/>\n    # \u8fd9\u6837\u83b7\u5f97\u6700\u7ec8\u7684\u6ce8\u610f\u529b\u5f20\u91cf<br \/>\n    p_attn &#061; F.softmax(scores, dim &#061; -1)<\/p>\n<p>    # \u4e4b\u540e\u5224\u65ad\u662f\u5426\u4f7f\u7528dropout\u8fdb\u884c\u968f\u673a\u7f6e0<br \/>\n    if dropout is not None:<br \/>\n        # \u5c06p_attn\u4f20\u5165dropout\u5bf9\u8c61\u4e2d\u8fdb\u884c&#039;\u4e22\u5f03&#039;\u5904\u7406<br \/>\n        p_attn &#061; dropout(p_attn)<\/p>\n<p>    # \u6700\u540e, \u6839\u636e\u516c\u5f0f\u5c06p_attn\u4e0evalue\u5f20\u91cf\u76f8\u4e58\u83b7\u5f97\u6700\u7ec8\u7684query\u6ce8\u610f\u529b\u8868\u793a, \u540c\u65f6\u8fd4\u56de\u6ce8\u610f\u529b\u5f20\u91cf<br \/>\n    return torch.matmul(p_attn, value), p_attn<\/p>\n<ul>\n<li>tensor.masked_fill\u6f14\u793a:<\/li>\n<\/ul>\n<p>\u00a0&gt;&gt;&gt; input &#061; Variable(torch.randn(5, 5))<\/p>\n<p>&gt;&gt;&gt; input<\/p>\n<p>Variable containing:<\/p>\n<p>2.0344 -0.5450 0.3365 -0.1888 -2.1803<\/p>\n<p>1.5221 -0.3823 0.8414 0.7836 -0.8481<\/p>\n<p>-0.0345 -0.8643 0.6476 -0.2713 1.5645<\/p>\n<p>0.8788 -2.2142 0.4022 0.1997 0.1474<\/p>\n<p>2.9109 0.6006 -0.6745 -1.7262 0.6977<\/p>\n<p>[torch.FloatTensor of size 5&#215;5]<\/p>\n<\/p>\n<p>&gt;&gt;&gt; mask &#061; Variable(torch.zeros(5, 5))<\/p>\n<p>&gt;&gt;&gt; mask Variable containing:<\/p>\n<p>0 0 0 0 0<\/p>\n<p>0 0 0 0 0<\/p>\n<p>0 0 0 0 0<\/p>\n<p>0 0 0 0 0<\/p>\n<p>0 0 0 0 0<\/p>\n<p>[torch.FloatTensor of size 5&#215;5]<\/p>\n<\/p>\n<p>&gt;&gt;&gt; input.masked_fill(mask &#061;&#061; 0, -1e9)<\/p>\n<p>Variable containing:<\/p>\n<p>-1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09<\/p>\n<p>-1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09<\/p>\n<p>-1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09<\/p>\n<p>-1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09<\/p>\n<p>-1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09 -1.0000e&#043;09<\/p>\n<p>[torch.FloatTensor of size 5&#215;5]<\/p>\n<ul>\n<li>\u8f93\u5165\u53c2\u6570:<\/li>\n<\/ul>\n<p>\u00a0# \u6211\u4eec\u4ee4\u8f93\u5165\u7684query, key, value\u90fd\u76f8\u540c, \u4f4d\u7f6e\u7f16\u7801\u7684\u8f93\u51fa<\/p>\n<p>query &#061; key &#061; value &#061; pe_result<\/p>\n<p>Variable containing:<\/p>\n<p>( 0 ,.,.) &#061;<\/p>\n<p>46.5196 16.2057 -41.5581 &#8230; -16.0242 -17.8929 -43.0405<\/p>\n<p>-32.6040 16.1096 -29.5228 &#8230; 4.2721 20.6034 -1.2747<\/p>\n<p>-18.6235 14.5076 -2.0105 &#8230; 15.6462 -24.6081 -30.3391<\/p>\n<p>0.0000 -66.1486 -11.5123 &#8230; 20.1519 -4.6823 0.4916<\/p>\n<\/p>\n<p>( 1 ,.,.) &#061;<\/p>\n<p>-24.8681 7.5495 -5.0765 &#8230; -7.5992 -26.6630 40.9517<\/p>\n<p>13.1581 -3.1918 -30.9001 &#8230; 25.1187 -26.4621 2.9542<\/p>\n<p>-49.7690 -42.5019 8.0198 &#8230; -5.4809 25.9403 -27.4931<\/p>\n<p>-52.2775 10.4006 0.0000 &#8230; -1.9985 7.0106 -0.5189<\/p>\n<p>[torch.FloatTensor of size 2x4x512]<\/p>\n<ul>\n<li>\u8c03\u7528:<\/li>\n<\/ul>\n<p>attn, p_attn &#061; attention(query, key, value)<\/p>\n<p>print(&#034;attn:&#034;, attn)<\/p>\n<p>print(&#034;p_attn:&#034;, p_attn)<\/p>\n<h3>4.2\u00a0\u5e26\u6709mask\u7684\u8f93\u5165\u53c2\u6570\u00a0<\/h3>\n<p>query &#061; key &#061; value &#061; pe_result<\/p>\n<p># \u4ee4mask\u4e3a\u4e00\u4e2a2x4x4\u7684\u96f6\u5f20\u91cf<br \/>\nmask &#061; Variable(torch.zeros(2, 4, 4))<\/p>\n<ul>\n<li>\u8c03\u7528:<\/li>\n<\/ul>\n<p>\u00a0attn, p_attn &#061; attention(query, key, value, mask&#061;mask)<\/p>\n<p>print(&#034;attn:&#034;, attn)<\/p>\n<p>print(&#034;p_attn:&#034;, p_attn)<\/p>\n<h3>4.3\u00a0\u6ce8\u610f\u529b\u673a\u5236\u603b\u7ed3\u00a0<\/h3>\n<ul>\n<li>\u5b66\u4e60\u5e76\u5b9e\u73b0\u4e86\u6ce8\u610f\u529b\u8ba1\u7b97\u89c4\u5219\u7684\u51fd\u6570: attention\n<ul>\n<li>\u5b83\u7684\u8f93\u5165\u5c31\u662fQ&#xff0c;K&#xff0c;V\u4ee5\u53camask\u548cdropout, mask\u7528\u4e8e\u63a9\u7801, dropout\u7528\u4e8e\u968f\u673a\u7f6e0.<\/li>\n<li>\u5b83\u7684\u8f93\u51fa\u6709\u4e24\u4e2a, query\u7684\u6ce8\u610f\u529b\u8868\u793a\u4ee5\u53ca\u6ce8\u610f\u529b\u5f20\u91cf.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e94.\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u00a0<\/h2>\n<h3>5.1\u00a0\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u6982\u5ff5\u00a0<\/h3>\n<ul>\n<li>\u4ece\u591a\u5934\u6ce8\u610f\u529b\u7684\u7ed3\u6784\u56fe\u4e2d&#xff0c;\u8c8c\u4f3c\u8fd9\u4e2a\u6240\u8c13\u7684\u591a\u4e2a\u5934\u5c31\u662f\u6307\u591a\u7ec4\u7ebf\u6027\u53d8\u6362\u5c42&#xff0c;\u5176\u5b9e\u5e76\u4e0d\u662f&#xff0c;\u6211\u53ea\u6709\u4f7f\u7528\u4e86\u4e00\u7ec4\u7ebf\u6027\u53d8\u5316\u5c42&#xff0c;\u5373\u4e09\u4e2a\u53d8\u6362\u5f20\u91cf\u5bf9Q&#xff0c;K&#xff0c;V\u5206\u522b\u8fdb\u884c\u7ebf\u6027\u53d8\u6362&#xff0c;\u8fd9\u4e9b\u53d8\u6362\u4e0d\u4f1a\u6539\u53d8\u539f\u6709\u5f20\u91cf\u7684\u5c3a\u5bf8&#xff0c;\u56e0\u6b64\u6bcf\u4e2a\u53d8\u6362\u77e9\u9635\u90fd\u662f\u65b9\u9635&#xff0c;\u5f97\u5230\u8f93\u51fa\u7ed3\u679c\u540e&#xff0c;\u591a\u5934\u7684\u4f5c\u7528\u624d\u5f00\u59cb\u663e\u73b0&#xff0c;\u6bcf\u4e2a\u5934\u5f00\u59cb\u4ece\u8bcd\u4e49\u5c42\u9762\u5206\u5272\u8f93\u51fa\u7684\u5f20\u91cf&#xff0c;\u4e5f\u5c31\u662f\u6bcf\u4e2a\u5934\u90fd\u60f3\u83b7\u5f97\u4e00\u7ec4Q&#xff0c;K&#xff0c;V\u8fdb\u884c\u6ce8\u610f\u529b\u673a\u5236\u7684\u8ba1\u7b97&#xff0c;\u4f46\u662f\u53e5\u5b50\u4e2d\u7684\u6bcf\u4e2a\u8bcd\u7684\u8868\u793a\u53ea\u83b7\u5f97\u4e00\u90e8\u5206&#xff0c;\u4e5f\u5c31\u662f\u53ea\u5206\u5272\u4e86\u6700\u540e\u4e00\u7ef4\u7684\u8bcd\u5d4c\u5165\u5411\u91cf. \u8fd9\u5c31\u662f\u6240\u8c13\u7684\u591a\u5934&#xff0c;\u5c06\u6bcf\u4e2a\u5934\u7684\u83b7\u5f97\u7684\u8f93\u5165\u9001\u5230\u6ce8\u610f\u529b\u673a\u5236\u4e2d, \u5c31\u5f62\u6210\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236.<\/li>\n<\/ul>\n<h3>5.2\u00a0\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u7ed3\u6784\u56fe<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"591\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-6889126283fbd.png\" width=\"740\" \/><\/p>\n<h3>5.3\u00a0\u00a0\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u7684\u4f5c\u7528\u00a0<\/h3>\n<ul>\n<li>\u8fd9\u79cd\u7ed3\u6784\u8bbe\u8ba1\u80fd\u8ba9\u6bcf\u4e2a\u6ce8\u610f\u529b\u673a\u5236\u53bb\u4f18\u5316\u6bcf\u4e2a\u8bcd\u6c47\u7684\u4e0d\u540c\u7279\u5f81\u90e8\u5206&#xff0c;\u4ece\u800c\u5747\u8861\u540c\u4e00\u79cd\u6ce8\u610f\u529b\u673a\u5236\u53ef\u80fd\u4ea7\u751f\u7684\u504f\u5dee&#xff0c;\u8ba9\u8bcd\u4e49\u62e5\u6709\u6765\u81ea\u66f4\u591a\u5143\u7684\u8868\u8fbe&#xff0c;\u5b9e\u9a8c\u8868\u660e\u53ef\u4ee5\u4ece\u800c\u63d0\u5347\u6a21\u578b\u6548\u679c.<\/li>\n<\/ul>\n<h2>\u516d.\u524d\u9988\u5168\u8fde\u63a5\u5c42<\/h2>\n<h3>6.1\u00a0\u524d\u9988\u5168\u8fde\u63a5\u5c42\u00a0<\/h3>\n<ul>\n<li>\n<p>\u5728Transformer\u4e2d\u524d\u9988\u5168\u8fde\u63a5\u5c42\u5c31\u662f\u5177\u6709\u4e24\u5c42\u7ebf\u6027\u5c42\u7684\u5168\u8fde\u63a5\u7f51\u7edc.<\/p>\n<\/li>\n<li>\n<p>\u524d\u9988\u5168\u8fde\u63a5\u5c42\u7684\u4f5c\u7528:<\/p>\n<ul>\n<li>\u8003\u8651\u6ce8\u610f\u529b\u673a\u5236\u53ef\u80fd\u5bf9\u590d\u6742\u8fc7\u7a0b\u7684\u62df\u5408\u7a0b\u5ea6\u4e0d\u591f, \u901a\u8fc7\u589e\u52a0\u4e24\u5c42\u7f51\u7edc\u6765\u589e\u5f3a\u6a21\u578b\u7684\u80fd\u529b.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>6.2 \u524d\u9988\u5168\u8fde\u63a5\u5c42\u7684\u4ee3\u7801\u5206\u6790\u00a0<\/h3>\n<p>import torch.nn as nn<br \/>\nimport torch.nn.functional as F<\/p>\n<p># \u901a\u8fc7\u7c7bPositionwiseFeedForward\u6765\u5b9e\u73b0\u524d\u9988\u5168\u8fde\u63a5\u5c42<br \/>\nclass PositionwiseFeedForward(nn.Module):<br \/>\n    def __init__(self, d_model, d_ff, dropout&#061;0.1):<br \/>\n        &#034;&#034;&#034;\u521d\u59cb\u5316\u51fd\u6570\u6709\u4e09\u4e2a\u8f93\u5165\u53c2\u6570\u5206\u522b\u662fd_model, d_ff,\u548cdropout&#061;0.1&#xff0c;\u7b2c\u4e00\u4e2a\u662f\u7ebf\u6027\u5c42\u7684\u8f93\u5165\u7ef4\u5ea6\u4e5f\u662f\u7b2c\u4e8c\u4e2a\u7ebf\u6027\u5c42\u7684\u8f93\u51fa\u7ef4\u5ea6&#xff0c;<br \/>\n           \u56e0\u4e3a\u6211\u4eec\u5e0c\u671b\u8f93\u5165\u901a\u8fc7\u524d\u9988\u5168\u8fde\u63a5\u5c42\u540e\u8f93\u5165\u548c\u8f93\u51fa\u7684\u7ef4\u5ea6\u4e0d\u53d8. \u7b2c\u4e8c\u4e2a\u53c2\u6570d_ff\u5c31\u662f\u7b2c\u4e8c\u4e2a\u7ebf\u6027\u5c42\u7684\u8f93\u5165\u7ef4\u5ea6\u548c\u7b2c\u4e00\u4e2a\u7ebf\u6027\u5c42\u7684\u8f93\u51fa\u7ef4\u5ea6.<br \/>\n           \u6700\u540e\u4e00\u4e2a\u662fdropout\u7f6e0\u6bd4\u7387.&#034;&#034;&#034;<br \/>\n        super(PositionwiseFeedForward, self).__init__()<\/p>\n<p>        # \u9996\u5148\u6309\u7167\u6211\u4eec\u9884\u671f\u4f7f\u7528nn\u5b9e\u4f8b\u5316\u4e86\u4e24\u4e2a\u7ebf\u6027\u5c42\u5bf9\u8c61&#xff0c;self.w1\u548cself.w2<br \/>\n        # \u5b83\u4eec\u7684\u53c2\u6570\u5206\u522b\u662fd_model, d_ff\u548cd_ff, d_model<br \/>\n        self.w1 &#061; nn.Linear(d_model, d_ff)<br \/>\n        self.w2 &#061; nn.Linear(d_ff, d_model)<br \/>\n        # \u7136\u540e\u4f7f\u7528nn\u7684Dropout\u5b9e\u4f8b\u5316\u4e86\u5bf9\u8c61self.dropout<br \/>\n        self.dropout &#061; nn.Dropout(dropout)<\/p>\n<p>    def forward(self, x):<br \/>\n        &#034;&#034;&#034;\u8f93\u5165\u53c2\u6570\u4e3ax&#xff0c;\u4ee3\u8868\u6765\u81ea\u4e0a\u4e00\u5c42\u7684\u8f93\u51fa&#034;&#034;&#034;<br \/>\n        # \u9996\u5148\u7ecf\u8fc7\u7b2c\u4e00\u4e2a\u7ebf\u6027\u5c42&#xff0c;\u7136\u540e\u4f7f\u7528Funtional\u4e2drelu\u51fd\u6570\u8fdb\u884c\u6fc0\u6d3b,<br \/>\n        # \u4e4b\u540e\u518d\u4f7f\u7528dropout\u8fdb\u884c\u968f\u673a\u7f6e0&#xff0c;\u6700\u540e\u901a\u8fc7\u7b2c\u4e8c\u4e2a\u7ebf\u6027\u5c42w2&#xff0c;\u8fd4\u56de\u6700\u7ec8\u7ed3\u679c.<br \/>\n        return self.w2(self.dropout(F.relu(self.w1(x))))<\/p>\n<ul>\n<li>\n<p>ReLU\u51fd\u6570\u516c\u5f0f: ReLU(x)&#061;max(0, x)<\/p>\n<\/li>\n<li>\n<p>ReLU\u51fd\u6570\u56fe\u50cf:<\/p>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"497\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912629cdca.png\" width=\"753\" \/><\/p>\n<ul>\n<li>\u5b9e\u4f8b\u5316\u53c2\u6570:<\/li>\n<\/ul>\n<p>d_model &#061; 512<\/p>\n<\/p>\n<p># \u7ebf\u6027\u53d8\u5316\u7684\u7ef4\u5ea6<\/p>\n<p>d_ff &#061; 64<\/p>\n<\/p>\n<p>dropout &#061; 0.2\u00a0<\/p>\n<ul>\n<li>\u8f93\u5165\u53c2\u6570:<\/li>\n<\/ul>\n<p># \u8f93\u5165\u53c2\u6570x\u53ef\u4ee5\u662f\u6ce8\u610f\u529b\u5c42\u7684\u8f93\u51fa<\/p>\n<p>x &#061; attn\u00a0<\/p>\n<ul>\n<li>\u8c03\u7528:<\/li>\n<\/ul>\n<p>ff &#061; PositionwiseFeedForward(d_model, d_ff, dropout)<\/p>\n<p>ff_result &#061; ff(x)<\/p>\n<p>print(ff_result)<\/p>\n<p>print(ff_result.shape)\u00a0<\/p>\n<h3>6.3\u00a0\u524d\u9988\u5168\u8fde\u63a5\u5c42\u603b\u7ed3\u00a0<\/h3>\n<ul>\n<li>\n<p>\u5b66\u4e60\u4e86\u4ec0\u4e48\u662f\u524d\u9988\u5168\u8fde\u63a5\u5c42:<\/p>\n<ul>\n<li>\u5728Transformer\u4e2d\u524d\u9988\u5168\u8fde\u63a5\u5c42\u5c31\u662f\u5177\u6709\u4e24\u5c42\u7ebf\u6027\u5c42\u7684\u5168\u8fde\u63a5\u7f51\u7edc.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u4e86\u524d\u9988\u5168\u8fde\u63a5\u5c42\u7684\u4f5c\u7528:<\/p>\n<ul>\n<li>\u8003\u8651\u6ce8\u610f\u529b\u673a\u5236\u53ef\u80fd\u5bf9\u590d\u6742\u8fc7\u7a0b\u7684\u62df\u5408\u7a0b\u5ea6\u4e0d\u591f, \u901a\u8fc7\u589e\u52a0\u4e24\u5c42\u7f51\u7edc\u6765\u589e\u5f3a\u6a21\u578b\u7684\u80fd\u529b.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u5e76\u5b9e\u73b0\u4e86\u524d\u9988\u5168\u8fde\u63a5\u5c42\u7684\u7c7b: PositionwiseFeedForward<\/p>\n<ul>\n<li>\u5b83\u7684\u5b9e\u4f8b\u5316\u53c2\u6570\u4e3ad_model, d_ff, dropout, \u5206\u522b\u4ee3\u8868\u8bcd\u5d4c\u5165\u7ef4\u5ea6, \u7ebf\u6027\u53d8\u6362\u7ef4\u5ea6, \u548c\u7f6e\u96f6\u6bd4\u7387.<\/li>\n<li>\u5b83\u7684\u8f93\u5165\u53c2\u6570x, \u8868\u793a\u4e0a\u5c42\u7684\u8f93\u51fa.<\/li>\n<li>\u5b83\u7684\u8f93\u51fa\u662f\u7ecf\u8fc72\u5c42\u7ebf\u6027\u7f51\u7edc\u53d8\u6362\u7684\u7279\u5f81\u8868\u793a.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e03.\u89c4\u8303\u5316\u5c42\u00a0<\/h2>\n<h3>7.1 \u89c4\u8303\u5316\u5c42\u7684\u4f5c\u7528\u00a0<\/h3>\n<ul>\n<li>\u5b83\u662f\u6240\u6709\u6df1\u5c42\u7f51\u7edc\u6a21\u578b\u90fd\u9700\u8981\u7684\u6807\u51c6\u7f51\u7edc\u5c42&#xff0c;\u56e0\u4e3a\u968f\u7740\u7f51\u7edc\u5c42\u6570\u7684\u589e\u52a0&#xff0c;\u901a\u8fc7\u591a\u5c42\u7684\u8ba1\u7b97\u540e\u53c2\u6570\u53ef\u80fd\u5f00\u59cb\u51fa\u73b0\u8fc7\u5927\u6216\u8fc7\u5c0f\u7684\u60c5\u51b5&#xff0c;\u8fd9\u6837\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5b66\u4e60\u8fc7\u7a0b\u51fa\u73b0\u5f02\u5e38&#xff0c;\u6a21\u578b\u53ef\u80fd\u6536\u655b\u975e\u5e38\u7684\u6162. \u56e0\u6b64\u90fd\u4f1a\u5728\u4e00\u5b9a\u5c42\u6570\u540e\u63a5\u89c4\u8303\u5316\u5c42\u8fdb\u884c\u6570\u503c\u7684\u89c4\u8303\u5316&#xff0c;\u4f7f\u5176\u7279\u5f81\u6570\u503c\u5728\u5408\u7406\u8303\u56f4\u5185.<\/li>\n<\/ul>\n<h3>7.2\u00a0\u89c4\u8303\u5316\u5c42\u7684\u4ee3\u7801\u5b9e\u73b0\u00a0<\/h3>\n<ul>\n<li>\u5b9e\u4f8b\u5316\u53c2\u6570:<\/li>\n<\/ul>\n<p>features &#061; d_model &#061; 512<\/p>\n<p>eps &#061; 1e-6\u00a0<\/p>\n<ul>\n<li>\u8f93\u5165\u53c2\u6570:<\/li>\n<\/ul>\n<p># \u8f93\u5165x\u6765\u81ea\u524d\u9988\u5168\u8fde\u63a5\u5c42\u7684\u8f93\u51fa<\/p>\n<p>x &#061; ff_result\u00a0<\/p>\n<ul>\n<li>\u8c03\u7528:<\/li>\n<\/ul>\n<p>ln &#061; LayerNorm(features, eps)<\/p>\n<p>ln_result &#061; ln(x)<\/p>\n<p>print(ln_result)<\/p>\n<p>print(ln_result.shape)\u00a0<\/p>\n<h3>6.3\u00a0\u89c4\u8303\u5316\u5c42\u603b\u7ed3\u00a0<\/h3>\n<ul>\n<li>\n<p>\u5b66\u4e60\u4e86\u89c4\u8303\u5316\u5c42\u7684\u4f5c\u7528:<\/p>\n<ul>\n<li>\u5b83\u662f\u6240\u6709\u6df1\u5c42\u7f51\u7edc\u6a21\u578b\u90fd\u9700\u8981\u7684\u6807\u51c6\u7f51\u7edc\u5c42&#xff0c;\u56e0\u4e3a\u968f\u7740\u7f51\u7edc\u5c42\u6570\u7684\u589e\u52a0&#xff0c;\u901a\u8fc7\u591a\u5c42\u7684\u8ba1\u7b97\u540e\u53c2\u6570\u53ef\u80fd\u5f00\u59cb\u51fa\u73b0\u8fc7\u5927\u6216\u8fc7\u5c0f\u7684\u60c5\u51b5&#xff0c;\u8fd9\u6837\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5b66\u4e60\u8fc7\u7a0b\u51fa\u73b0\u5f02\u5e38&#xff0c;\u6a21\u578b\u53ef\u80fd\u6536\u655b\u975e\u5e38\u7684\u6162. \u56e0\u6b64\u90fd\u4f1a\u5728\u4e00\u5b9a\u5c42\u6570\u540e\u63a5\u89c4\u8303\u5316\u5c42\u8fdb\u884c\u6570\u503c\u7684\u89c4\u8303\u5316&#xff0c;\u4f7f\u5176\u7279\u5f81\u6570\u503c\u5728\u5408\u7406\u8303\u56f4\u5185.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u5e76\u5b9e\u73b0\u4e86\u89c4\u8303\u5316\u5c42\u7684\u7c7b: LayerNorm<\/p>\n<ul>\n<li>\u5b83\u7684\u5b9e\u4f8b\u5316\u53c2\u6570\u6709\u4e24\u4e2a, features\u548ceps&#xff0c;\u5206\u522b\u8868\u793a\u8bcd\u5d4c\u5165\u7279\u5f81\u5927\u5c0f&#xff0c;\u548c\u4e00\u4e2a\u8db3\u591f\u5c0f\u7684\u6570.<\/li>\n<li>\u5b83\u7684\u8f93\u5165\u53c2\u6570x\u4ee3\u8868\u6765\u81ea\u4e0a\u4e00\u5c42\u7684\u8f93\u51fa.<\/li>\n<li>\u5b83\u7684\u8f93\u51fa\u5c31\u662f\u7ecf\u8fc7\u89c4\u8303\u5316\u7684\u7279\u5f81\u8868\u793a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 style=\"background-color:transparent\">\u516b.\u603b\u7ed3\u00a0<\/h2>\n<p>\u00a0\u672c\u7ae0\u8282\u7684\u5185\u5bb9\u5f88\u591a&#xff0c;\u4e5f\u7279\u522b\u96be\u7406\u89e3&#xff0c;\u5927\u5bb6\u6d88\u5316\u4e00\u4e0b&#xff0c;\u4f46\u662f\u8fd9\u4e2a\u662f\u975e\u5e38\u91cd\u8981\u7684&#xff0c;\u540e\u9762\u8fd8\u4f1a\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u89e3\u7801\u90e8\u5206&#xff0c;\u671f\u5f85\u5927\u5bb6\u7684\u70b9\u8d5e\u5173\u6ce8\u548c\u6536\u85cf\u3002<\/p>\n<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb636\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Transformer\u6a21\u578b\u4e2d\u7684\u7f16\u7801\u5668\u5b9e\u73b0\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e86\u7f16\u7801\u5668\u7684\u6838\u5fc3\u7ec4\u4ef6\u53ca\u5176\u4f5c\u7528\u3002\u7f16\u7801\u5668\u7531N\u4e2a\u5806\u53e0\u7684\u7f16\u7801\u5668\u5c42\u7ec4\u6210\uff0c\u6bcf\u5c42\u5305\u542b\u591a\u5934\u81ea\u6ce8\u610f\u529b\u673a\u5236\u548c\u524d\u9988\u5168\u8fde\u63a5\u4e24\u4e2a\u5b50\u5c42\uff0c\u5747\u91c7\u7528\u6b8b\u5dee\u8fde\u63a5\u548c\u89c4\u8303\u5316\u5904\u7406\u3002\u8be6\u7ec6\u9610\u8ff0\u4e86\u63a9\u7801\u5f20\u91cf\u7684\u4f5c\u7528\u53ca\u5b9e\u73b0\u65b9\u6cd5\uff0c\u7528\u4e8e\u9632\u6b62\u6a21\u578b\u5728\u8bad\u7ec3\u65f6\u63d0\u524d\u83b7\u53d6\u672a\u6765\u4fe1\u606f\u3002\u6df1\u5165\u5206\u6790\u4e86\u6ce8\u610f\u529b\u673a\u5236\u7684\u8ba1\u7b97\u89c4\u5219\u548c\u4ee3\u7801\u5b9e\u73b0\uff0c\u5305\u62ec\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b\u8ba1\u7b97\u548c\u63a9\u7801\u5904\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u4ecb\u7ecd\u4e86\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u3001\u524d\u9988\u5168\u8fde\u63a5\u5c42\u548c\u89c4\u8303\u5316\u5c42\u7684\u7ed3\u6784\u539f\u7406\u4e0e\u5b9e\u73b0\u4ee3\u7801\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u5171\u540c\u6784\u6210\u4e86Transformer\u7684\u6838\u5fc3\u67b6\u6784\uff0c\u4e3a\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7279\u5f81\u63d0\u53d6\u80fd\u529b<\/p>\n","protected":false},"author":2,"featured_media":46120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4386,841,50,86],"topic":[],"class_list":["post-46125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ai","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>Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \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\/46125.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb636\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Transformer\u6a21\u578b\u4e2d\u7684\u7f16\u7801\u5668\u5b9e\u73b0\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e86\u7f16\u7801\u5668\u7684\u6838\u5fc3\u7ec4\u4ef6\u53ca\u5176\u4f5c\u7528\u3002\u7f16\u7801\u5668\u7531N\u4e2a\u5806\u53e0\u7684\u7f16\u7801\u5668\u5c42\u7ec4\u6210\uff0c\u6bcf\u5c42\u5305\u542b\u591a\u5934\u81ea\u6ce8\u610f\u529b\u673a\u5236\u548c\u524d\u9988\u5168\u8fde\u63a5\u4e24\u4e2a\u5b50\u5c42\uff0c\u5747\u91c7\u7528\u6b8b\u5dee\u8fde\u63a5\u548c\u89c4\u8303\u5316\u5904\u7406\u3002\u8be6\u7ec6\u9610\u8ff0\u4e86\u63a9\u7801\u5f20\u91cf\u7684\u4f5c\u7528\u53ca\u5b9e\u73b0\u65b9\u6cd5\uff0c\u7528\u4e8e\u9632\u6b62\u6a21\u578b\u5728\u8bad\u7ec3\u65f6\u63d0\u524d\u83b7\u53d6\u672a\u6765\u4fe1\u606f\u3002\u6df1\u5165\u5206\u6790\u4e86\u6ce8\u610f\u529b\u673a\u5236\u7684\u8ba1\u7b97\u89c4\u5219\u548c\u4ee3\u7801\u5b9e\u73b0\uff0c\u5305\u62ec\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b\u8ba1\u7b97\u548c\u63a9\u7801\u5904\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u4ecb\u7ecd\u4e86\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u3001\u524d\u9988\u5168\u8fde\u63a5\u5c42\u548c\u89c4\u8303\u5316\u5c42\u7684\u7ed3\u6784\u539f\u7406\u4e0e\u5b9e\u73b0\u4ee3\u7801\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u5171\u540c\u6784\u6210\u4e86Transformer\u7684\u6838\u5fc3\u67b6\u6784\uff0c\u4e3a\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7279\u5f81\u63d0\u53d6\u80fd\u529b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46125.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T18:26:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912625b0ae.png\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46125.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46125.html\",\"name\":\"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T18:26:43+00:00\",\"dateModified\":\"2025-07-29T18:26:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46125.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46125.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46125.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0\"}]},{\"@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":"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \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\/46125.html","og_locale":"zh_CN","og_type":"article","og_title":"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb636\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Transformer\u6a21\u578b\u4e2d\u7684\u7f16\u7801\u5668\u5b9e\u73b0\uff0c\u91cd\u70b9\u8bb2\u89e3\u4e86\u7f16\u7801\u5668\u7684\u6838\u5fc3\u7ec4\u4ef6\u53ca\u5176\u4f5c\u7528\u3002\u7f16\u7801\u5668\u7531N\u4e2a\u5806\u53e0\u7684\u7f16\u7801\u5668\u5c42\u7ec4\u6210\uff0c\u6bcf\u5c42\u5305\u542b\u591a\u5934\u81ea\u6ce8\u610f\u529b\u673a\u5236\u548c\u524d\u9988\u5168\u8fde\u63a5\u4e24\u4e2a\u5b50\u5c42\uff0c\u5747\u91c7\u7528\u6b8b\u5dee\u8fde\u63a5\u548c\u89c4\u8303\u5316\u5904\u7406\u3002\u8be6\u7ec6\u9610\u8ff0\u4e86\u63a9\u7801\u5f20\u91cf\u7684\u4f5c\u7528\u53ca\u5b9e\u73b0\u65b9\u6cd5\uff0c\u7528\u4e8e\u9632\u6b62\u6a21\u578b\u5728\u8bad\u7ec3\u65f6\u63d0\u524d\u83b7\u53d6\u672a\u6765\u4fe1\u606f\u3002\u6df1\u5165\u5206\u6790\u4e86\u6ce8\u610f\u529b\u673a\u5236\u7684\u8ba1\u7b97\u89c4\u5219\u548c\u4ee3\u7801\u5b9e\u73b0\uff0c\u5305\u62ec\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b\u8ba1\u7b97\u548c\u63a9\u7801\u5904\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u4ecb\u7ecd\u4e86\u591a\u5934\u6ce8\u610f\u529b\u673a\u5236\u3001\u524d\u9988\u5168\u8fde\u63a5\u5c42\u548c\u89c4\u8303\u5316\u5c42\u7684\u7ed3\u6784\u539f\u7406\u4e0e\u5b9e\u73b0\u4ee3\u7801\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u5171\u540c\u6784\u6210\u4e86Transformer\u7684\u6838\u5fc3\u67b6\u6784\uff0c\u4e3a\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7279\u5f81\u63d0\u53d6\u80fd\u529b","og_url":"https:\/\/www.wsisp.com\/helps\/46125.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T18:26:43+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729182642-688912625b0ae.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46125.html","url":"https:\/\/www.wsisp.com\/helps\/46125.html","name":"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T18:26:43+00:00","dateModified":"2025-07-29T18:26:43+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46125.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46125.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46125.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Transformer\u7f16\u7801\u5668\u90e8\u5206\u5b9e\u73b0"}]},{"@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\/46125","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=46125"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46125\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/46120"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46125"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}