{"id":3381,"date":"2020-03-27T15:03:57","date_gmt":"2020-03-27T07:03:57","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=3381"},"modified":"2020-03-27T15:03:57","modified_gmt":"2020-03-27T07:03:57","slug":"%e3%80%90%e5%90%b4%e6%81%a9%e8%be%be%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e3%80%91%e5%ba%8f%e5%88%97%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/deep-learning\/3381\/","title":{"rendered":"\u3010\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u3011\u5e8f\u5217\u6a21\u578b"},"content":{"rendered":"\n<p>\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u7b2c\u4e94\u8bfe\u7b2c\u4e00\u5468\uff1a\u5e8f\u5217\u6a21\u578b<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"283\" height=\"364\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-194.png\" alt=\"\" class=\"wp-image-3400\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-194.png 283w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-194-233x300.png 233w\" sizes=\"(max-width: 283px) 100vw, 283px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">1.\u4e3a\u4ec0\u4e48\u9009\u62e9\u5e8f\u5217\u6a21\u578b<\/h2>\n\n\n<p>\u5f88\u591a\u4efb\u52a1\u4e2d\u6570\u636e\u5bf9\u5148\u540e\u654f\u611f\uff0c\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0cI love u \u548cu love i\uff0c\u610f\u601d\u660e\u663e\u4e0d\u540c\uff0c\u56e0\u6b64\u9700\u8981\u5bf9\u987a\u5e8f\u654f\u611f\u7684\u6a21\u578b\u6765\u5904\u7406\u7c7b\u4f3c\u6570\u636e\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"326\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-176.png\" alt=\"\" class=\"wp-image-3382\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-176.png 627w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-176-300x156.png 300w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">2.\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\uff08RNN\uff09<\/h2>\n\n\n<p>\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\u5c31\u662f\u5c06\u4e0a\u4e00\u4e2a\u8f93\u5165\u4f5c\u4e3a\u4e0b\u4e00\u4e2a\u7684\u8f93\u5165<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"269\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-177.png\" alt=\"\" class=\"wp-image-3383\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-177.png 600w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-177-300x135.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure><\/div>\n\n\n<p>\u7f51\u7edc\u524d\u5411\u4f20\u64ad\u793a\u610f\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"197\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-178.png\" alt=\"\" class=\"wp-image-3384\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-178.png 628w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-178-300x94.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">3.\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\u7684\u53cd\u5411\u4f20\u64ad<\/h2>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"252\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-179.png\" alt=\"\" class=\"wp-image-3385\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-179.png 677w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-179-300x112.png 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">4.\u4e0d\u540c\u7c7b\u578b\u7684\u5faa\u73af\u795e\u7ecf\u7f51\u7edc<\/h2>\n\n\n<p>\u6839\u636e\u8f93\u5165\u8f93\u51fa\u4e2a\u6570\u7684\u4e0d\u540c\uff0c\u5927\u6982\u5206\u4e3a\u51e0\u7c7b\uff1a<\/p>\n\n\n<p>many-to-many\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"259\" height=\"183\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-180.png\" alt=\"\" class=\"wp-image-3386\"\/><\/figure><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"411\" height=\"239\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-184.png\" alt=\"\" class=\"wp-image-3390\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-184.png 411w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-184-300x174.png 300w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><\/figure><\/div>\n\n\n<p>many-to-one\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"243\" height=\"166\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-181.png\" alt=\"\" class=\"wp-image-3387\"\/><\/figure><\/div>\n\n\n<p>one-to-one\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"96\" height=\"186\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-182.png\" alt=\"\" class=\"wp-image-3388\"\/><\/figure><\/div>\n\n\n<p>one-to-many\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"248\" height=\"219\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-183.png\" alt=\"\" class=\"wp-image-3389\"\/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">5.\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\u7684\u68af\u5ea6\u6d88\u5931<\/h2>\n\n\n<p>\u7531\u4e8e\u6211\u4eec\u7684\u65f6\u95f4\u5e8f\u5217\u5e38\u5e38\u5bfc\u81f4\u795e\u7ecf\u7f51\u7edc\u5f88\u6df1\uff0c\u56e0\u6b64\u4e5f\u5c31\u4f1a\u4ea7\u751f\u68af\u5ea6\u6d88\u5931\u548c\u68af\u5ea6\u7206\u70b8\u7684\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u622a\u53d6\u53c2\u6570\u6765\u907f\u514d\u68af\u5ea6\u7206\u70b8\uff0c\u90a3\u4e48\u68af\u5ea6\u6d88\u5931\u600e\u4e48\u5904\u7406\u5462\u3002<\/p>\n\n\n<p>\u7279\u522b\u662f\u5bf9\u4e8e <\/p>\n\n\n<p><strong>The cat, which already ate \u2026\u2026, was full.<\/strong> <\/p>\n\n\n<p><strong>The cats, which ate \u2026\u2026, were full.<\/strong><\/p>\n\n\n<p>\u6211\u4eec\u5c31\u9700\u8981\u8bb0\u5f55\u4e00\u4e2a\u503cc\uff0c\u6765\u544a\u8bc9\u540e\u9762\uff0c\u524d\u9762\u7684\u540d\u8bcd\u662f\u5355\u6570\u3002<\/p>\n\n\n<p>\u8fd9\u79cd\u7c7b\u4f3c\u7684\u95ee\u9898\uff0c\u8fc7\u957f\u7684\u8ddd\u79bb\u53ef\u80fd\u5bfc\u81f4\u5dee\u5f02\u6839\u672c\u5f71\u54cd\u4e0d\u5230\uff0c\u56e0\u6b64\u5f15\u5165\u95e8\u7684\u6982\u5ff5\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">6.GRU\u5355\u5143<\/h2>\n\n\n<p>GRU\u5355\u5143\u5c31\u662f\u901a\u8fc7\u95e8\u63a7\u5faa\u73af\u5355\u5143\u6539\u53d8RNN\u9690\u85cf\u5c42\u7ed3\u6784\uff0c\u4f7f\u5979\u53ef\u4ee5\u66f4\u597d\u5730\u6355\u6349\u6df1\u5c42\u8fde\u63a5\uff0c\u6539\u5584\u4e86\u68af\u5ea6\u6d88\u5931\u3002<\/p>\n\n\n<p>GRU\u5355\u5143\u5b9e\u9645\u4e0a\u5c31\u662f\u901a\u8fc7\u4e00\u4e2a\u503c\uff0c\u6765\u51b3\u5b9a\u5f53\u524d\u5f53\u524d\u7ed3\u70b9\u8ba1\u7b97\u7684\u503c\u548c\u524d\u4e00\u4e2a\u9636\u6bb5\u7684\u7ed3\u679c\u7684\u5360\u6bd4\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"231\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-188.png\" alt=\"\" class=\"wp-image-3394\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-188.png 586w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-188-300x118.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/figure><\/div>\n\n\n<p>\u5b9e\u9645\u4e0a\u5b8c\u6574\u7684GRU\u5355\u5143\u8fd8\u6709\u4e00\u4e2a\u95e8\u63a7\uff0c\u5341\u5206\u7c7b\u4f3c\u4e8e\u4e0a\u9762\u8bf4\u7684\u95e8\uff0c\u4e0a\u9762\u7684\u95e8\u8bb0\u5f55\u4e86\u5f53\u524d\u7ed3\u70b9\u548c\u4e0a\u4e00\u4e2a\u7ed3\u70b9\u7684\u5173\u7cfb\uff0c\u56e0\u6b64\u8fd8\u6709\u4e00\u4e2a\u8bb0\u5f55\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u548c\u5f53\u524d\u7ed3\u70b9\u7684\u5173\u7cfb\u3002\u4e5f\u5c31\u662f\uff1a<\/p>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"263\" height=\"75\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-190.png\" alt=\"\" class=\"wp-image-3396\"\/><\/figure>\n\n\n<p>\u56e0\u6b64\u6709\u5b8c\u6574\u516c\u5f0f\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"493\" height=\"223\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-189.png\" alt=\"\" class=\"wp-image-3395\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-189.png 493w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-189-300x136.png 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">7.\u957f\u77ed\u65f6\u8bb0\u5fc6\u7f51\u7edc\uff08LSTM\uff09<\/h2>\n\n\n<p>LSTM\u662f\u4e00\u4e2a\u6bd4GRU\u66f4\u5f3a\u5927\u548c\u901a\u7528\u7684\u7248\u672c<\/p>\n\n\n<p>\u76f8\u6bd4GRU\uff0cLSTM\u6709\u66f4\u65b0\u95e8update\u3001\u9057\u5fd8\u95e8forget\u548c\u8f93\u51fa\u95e8output\u3002<\/p>\n\n\n<p>\u800c\u5bf9\u4e8eupdate\u548cforget\u4ece\u516c\u5f0f\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5b9e\u9645\u4e0a\u5c31\u662fGRU\u7684\uff081- \u0393 \uff09\u53d8\u6210\u4e86\u9057\u5fd8\u95e8\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"635\" height=\"297\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-191.png\" alt=\"\" class=\"wp-image-3397\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-191.png 635w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-191-300x140.png 300w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><\/figure><\/div>\n\n\n<p>\u6211\u4eec\u5f88\u5bb9\u6613\u7684\u53d1\u73b0\uff0cLSTM\u5bf9\u4e8e\u7279\u5f81c\uff08\u5355\u590d\u6570\uff09\u6709\u4e00\u4e2a\u6a2a\u5411\u7684\u4f20\u64ad<\/p>\n\n\n<h2 class=\"wp-block-heading\">8.\u53cc\u5411\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\uff08BRNN\uff09<\/h2>\n\n\n<p>\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u53ef\u4ee5\u4f7f\u7528RNN\u83b7\u5f97\u4e4b\u524d\u5e8f\u5217\u7684\u72b6\u6001\uff0c\u90a3\u4e48\u4e4b\u540e\u5462\uff1f\u6211\u4eec\u4f7f\u7528\u4e24\u4e2aRNN\u7ec4\u5408\u800c\u6210\u7684\u53cc\u5411\u5faa\u73af\u795e\u7ecf\u7f51\u7edcBRNN\u6765\u89e3\u51b3\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"233\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-192.png\" alt=\"\" class=\"wp-image-3398\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-192.png 600w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-192-300x117.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure><\/div>\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u7f51\u7edc\u4e2d\u6709\u4e24\u7ec4RNN\uff0c\u4e00\u4e2a\u5411\u524d\uff0c\u4e00\u4e2a\u5411\u540e\uff0c\u56e0\u6b64\u8fd9\u4e2a\u7f51\u7edc\u5c31\u53ef\u4ee5\u5b8c\u6210\u5bf9\u4e8e\u4e0a\u4e0b\u6587\u7684\u5173\u7cfb\u83b7\u53d6\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">9.\u6df1\u5c42\u5faa\u73af\u795e\u7ecf\u7f51\u7edc<\/h2>\n\n\n<p>\u6211\u4eec\u5728\u4e4b\u524d\u4ecb\u7ecd\u4e86\u5f88\u6df1\u7684CNN\u6a21\u578b\u6216\u8005DNN\u6a21\u578b\uff0c\u5bf9\u4e8eRNN\uff0c\u7531\u4e8e\u65f6\u95f4\u5e8f\u5217\u8f83\u957f\uff0c\u6211\u4eec\u4e00\u822c\u4e0d\u505a\u5f88\u6df1\u7684\u7f51\u7edc\uff0c\u4e09\u5c42\u57fa\u672c\u5c31\u6700\u591a\u4e86\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"636\" height=\"324\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-193.png\" alt=\"\" class=\"wp-image-3399\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-193.png 636w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-193-300x153.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/figure><\/div>\n\n\n<p>\u4f46\u662f\u5bf9\u4e8e\u8f93\u51fa\uff0c\u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u9009\u62e9\u5d4c\u5957DNN\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u6d4b\u9a8c<\/h2>\n\n\n<p><strong>1. \u5047\u8bbe\u4f60\u7684\u8bad\u7ec3\u6837\u672c\u662f\u53e5\u5b50(\u5355\u8bcd\u5e8f\u5217)\uff0c\u4e0b\u9762\u54ea\u4e2a\u9009\u9879\u6307\u7684\u662f\u7b2c<\/strong><em><strong>i<\/strong><\/em><strong>\u4e2a\u8bad\u7ec3\u6837\u672c\u4e2d\u7684\u7b2c<\/strong><em><strong>j<\/strong><\/em><strong>\u4e2a\u8bcd? <\/strong><\/p>\n\n\n<p><em>x<\/em>^{(<em>i<\/em>)&lt;<em>j<\/em>&gt;} <\/p>\n\n\n<p><strong>2. \u770b\u4e00\u4e0b\u4e0b\u9762\u7684\u8fd9\u4e2a\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\uff1a  <\/strong> <\/p>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"894\" height=\"345\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-196.png\" alt=\"\" class=\"wp-image-3402\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-196.png 894w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-196-300x116.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-196-768x296.png 768w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><\/figure>\n\n\n<p> <strong>\u5728\u4e0b\u9762\u7684\u6761\u4ef6\u4e2d\uff0c\u6ee1\u8db3\u4e0a\u56fe\u4e2d\u7684\u7f51\u7edc\u7ed3\u6784\u7684\u53c2\u6570\u662f\uff1a  <\/strong><\/p>\n\n\n<ol><li><em>Tx<\/em>=<em>Ty<\/em><\/li><li><em>Tx<\/em>&lt;<em>Ty<\/em><\/li><li><em>Tx<\/em>&gt;<em>Ty<\/em><\/li><li><em>Tx<\/em> = 1<\/li><\/ol>\n\n\n<p>1\u3002\uff08\u6bcf\u4e00\u4e2a\u8f93\u5165\u90fd\u6709\u4e00\u4e2a\u8f93\u51fa\uff09<\/p>\n\n\n<p><strong>3. \u8fd9\u4e9b\u4efb\u52a1\u4e2d\u7684\u54ea\u4e00\u4e2a\u4f1a\u4f7f\u7528\u591a\u5bf9\u4e00\u7684RNN\u4f53\u7cfb\u7ed3\u6784\uff1f  <\/strong><\/p>\n\n\n<ol><li> \u8bed\u97f3\u8bc6\u522b\uff08\u8f93\u5165\u8bed\u97f3\uff0c\u8f93\u51fa\u6587\u672c\uff09 <\/li><li> \u60c5\u611f\u5206\u7c7b\uff08\u8f93\u5165\u4e00\u6bb5\u6587\u5b57\uff0c\u8f93\u51fa0\u62161\u8868\u793a\u6b63\u9762\u6216\u8005\u8d1f\u9762\u7684\u60c5\u7eea<\/li><li> \u56fe\u50cf\u5206\u7c7b\uff08\u8f93\u5165\u4e00\u5f20\u56fe\u7247\uff0c\u8f93\u51fa\u5bf9\u5e94\u7684\u6807\u7b7e\uff09\u3002 <\/li><li> \u4eba\u58f0\u6027\u522b\u8bc6\u522b\uff08\u8f93\u5165\u8bed\u97f3\uff0c\u8f93\u51fa\u8bf4\u8bdd\u4eba\u7684\u6027\u522b\uff09\u3002 <\/li><\/ol>\n\n\n<p>2\uff0c4\u3002<\/p>\n\n\n<p><strong>4. \u5047\u8bbe\u4f60\u73b0\u5728\u6b63\u5728\u8bad\u7ec3\u4e0b\u9762\u8fd9\u4e2aRNN\u7684\u8bed\u8a00\u6a21\u578b\uff1a  \u5728<\/strong><em><strong>t<\/strong><\/em><strong>\u65f6\uff0c\u8fd9\u4e2aRNN\u5728\u505a\u4ec0\u4e48\uff1f <\/strong><\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"347\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-198.png\" alt=\"\" class=\"wp-image-3404\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-198.png 821w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-198-300x127.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-198-768x325.png 768w\" sizes=\"(max-width: 821px) 100vw, 821px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"39\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-199.png\" alt=\"\" class=\"wp-image-3405\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-199.png 347w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-199-300x34.png 300w\" sizes=\"(max-width: 347px) 100vw, 347px\" \/><\/figure>\n\n\n<p><strong>5. \u4f60\u5df2\u7ecf\u5b8c\u6210\u4e86\u4e00\u4e2a\u8bed\u8a00\u6a21\u578bRNN\u7684\u8bad\u7ec3\uff0c\u5e76\u7528\u5b83\u6765\u5bf9\u53e5\u5b50\u8fdb\u884c\u968f\u673a\u53d6\u6837\uff0c\u5982\u4e0b\u56fe\uff1a  \u5728\u6bcf\u4e2a\u65f6\u95f4\u6b65<\/strong><em><strong>t<\/strong><\/em><strong>\u90fd\u5728\u505a\u4ec0\u4e48\uff1f <\/strong><\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"296\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-200.png\" alt=\"\" class=\"wp-image-3406\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-200.png 904w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-200-300x98.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-200-768x251.png 768w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/figure><\/div>\n\n\n<ol><li>  (1)\u4f7f\u7528RNN\u8f93\u51fa\u7684\u6982\u7387\uff0c\u9009\u62e9\u8be5\u65f6\u95f4\u6b65\u7684\u6700\u9ad8\u6982\u7387\u5355\u8bcd\u4f5c\u4e3a<em>y<\/em>^&lt;<em>t<\/em>&gt;\uff0c(2)\u7136\u540e\u5c06\u8bad\u7ec3\u96c6\u4e2d\u7684\u6b63\u786e\u7684\u5355\u8bcd\u4f20\u9012\u5230\u4e0b\u4e00\u4e2a\u65f6\u95f4\u6b65\u3002 <\/li><li> (i)\u4f7f\u7528\u7531RNN\u8f93\u51fa\u7684\u6982\u7387\u5c06\u8be5\u65f6\u95f4\u6b65\u7684\u6240\u9009\u5355\u8bcd\u8fdb\u884c\u968f\u673a\u91c7\u6837\u4f5c\u4e3a <em>y<\/em>^&lt;<em>t<\/em>&gt;\uff0c(2)\u7136\u540e\u5c06\u8bad\u7ec3\u96c6\u4e2d\u7684\u5b9e\u9645\u5355\u8bcd\u4f20\u9012\u5230\u4e0b\u4e00\u4e2a\u65f6\u95f4\u6b65\u3002 <\/li><li> (1)\u4f7f\u7528\u7531RNN\u8f93\u51fa\u7684\u6982\u7387\u6765\u9009\u62e9\u8be5\u65f6\u95f4\u6b65\u7684\u6700\u9ad8\u6982\u7387\u8bcd\u4f5c\u4e3a <em>y<\/em>^&lt;<em>t<\/em>&gt;\uff0c(2)\u7136\u540e\u5c06\u8be5\u9009\u62e9\u7684\u8bcd\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u65f6\u95f4\u6b65\u3002 <\/li><li> (1)\u4f7f\u7528RNN\u8be5\u65f6\u95f4\u6b65\u8f93\u51fa\u7684\u6982\u7387\u5bf9\u5355\u8bcd\u968f\u673a\u62bd\u6837\u7684\u7ed3\u679c\u4f5c\u4e3a<em>y<\/em>^&lt;<em>t<\/em>&gt;\uff0c(2)\u7136\u540e\u5c06\u6b64\u9009\u5b9a\u5355\u8bcd\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u65f6\u95f4\u6b65\u3002 <\/li><\/ol>\n\n\n<p>4\u3002\uff08\u56e0\u4e3a\u9898\u76ee\u4e2d\u8bf4\u4e86\u5bf9\u53e5\u5b50\u8fdb\u884c\u968f\u673a\u53d6\u6837\uff09<\/p>\n\n\n<p><strong>6. \u4f60\u6b63\u5728\u8bad\u7ec3\u4e00\u4e2aRNN\u7f51\u7edc\uff0c\u4f60\u53d1\u73b0\u4f60\u7684\u6743\u91cd\u4e0e\u6fc0\u6d3b\u503c\u90fd\u662f\u201cNaN\u201d\uff0c\u4e0b\u5217\u9009\u9879\u4e2d\uff0c\u54ea\u4e00\u4e2a\u662f\u5bfc\u81f4\u8fd9\u4e2a\u95ee\u9898\u7684\u6700\u6709\u53ef\u80fd\u7684\u539f\u56e0\uff1f <\/strong><\/p>\n\n\n<p>\u68af\u5ea6\u7206\u70b8\u3002<\/p>\n\n\n<p><strong>7. \u5047\u8bbe\u4f60\u6b63\u5728\u8bad\u7ec3\u4e00\u4e2aLSTM\u7f51\u7edc\uff0c\u4f60\u6709\u4e00\u4e2a10,000\u8bcd\u7684\u8bcd\u6c47\u8868\uff0c\u5e76\u4e14\u4f7f\u7528\u4e00\u4e2a\u6fc0\u6d3b\u503c\u7ef4\u5ea6\u4e3a100\u7684LSTM\u5757\uff0c\u5728\u6bcf\u4e00\u4e2a\u65f6\u95f4\u6b65\u4e2d\uff0c\u0393<\/strong><em><strong>u<\/strong><\/em><strong>\u7684\u7ef4\u5ea6\u662f\u591a\u5c11\uff1f<\/strong> <\/p>\n\n\n<p>100\u3002\uff08\u6fc0\u6d3b\u503c\u7ef4\u5ea6=LSTM\u957f\u5ea6=\u95e8\u63a7\u4e2a\u6570\uff09<\/p>\n\n\n<p><strong>8. \u8fd9\u91cc\u6709\u4e00\u4e9bGRU\u7684\u66f4\u65b0\u65b9\u7a0b\uff1a  \u7231\u4e3d\u4e1d\u5efa\u8bae\u901a\u8fc7\u79fb\u9664 \u0393<\/strong><em><strong>u<\/strong><\/em><strong>\u6765\u7b80\u5316GRU\uff0c\u5373\u8bbe\u7f6e\u0393<\/strong><em><strong>u<\/strong><\/em><strong>\uff1d1\u3002\u8d1d\u8482\u63d0\u51fa\u901a\u8fc7\u79fb\u9664\u0393<\/strong><em><strong>r<\/strong><\/em><strong>\u6765\u7b80\u5316GRU\uff0c\u5373\u8bbe\u7f6e\u0393<\/strong><em><strong>r<\/strong><\/em><strong>\uff1d1\u3002\u54ea\u79cd\u6a21\u578b\u66f4\u5bb9\u6613\u5728\u68af\u5ea6\u4e0d\u6d88\u5931\u95ee\u9898\u7684\u60c5\u51b5\u4e0b\u8bad\u7ec3\uff0c\u5373\u4f7f\u5728\u5f88\u957f\u7684\u8f93\u5165\u5e8f\u5217\u4e0a\u4e5f\u53ef\u4ee5\u8fdb\u884c\u8bad\u7ec3\uff1f <\/strong><\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"381\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-201.png\" alt=\"\" class=\"wp-image-3407\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-201.png 440w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-201-300x260.png 300w\" sizes=\"(max-width: 440px) 100vw, 440px\" \/><\/figure><\/div>\n\n\n<ol><li> \u7231\u4e3d\u4e1d\u7684\u6a21\u578b\uff08\u5373\u79fb\u9664\u0393<em>u<\/em>\uff09\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u4e00\u4e2a\u65f6\u95f4\u6b65\u800c\u8a00\uff0c\u5982\u679c\u0393<em>r<\/em>\u22480\uff0c\u68af\u5ea6\u53ef\u4ee5\u901a\u8fc7\u65f6\u95f4\u6b65\u53cd\u5411\u4f20\u64ad\u800c\u4e0d\u4f1a\u8870\u51cf\u3002<\/li><li> \u7231\u4e3d\u4e1d\u7684\u6a21\u578b\uff08\u5373\u79fb\u9664\u0393<em>u<\/em>\uff09\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u4e00\u4e2a\u65f6\u95f4\u6b65\u800c\u8a00\uff0c\u5982\u679c\u0393<em>r<\/em>\u22481\uff0c\u68af\u5ea6\u53ef\u4ee5\u901a\u8fc7\u65f6\u95f4\u6b65\u53cd\u5411\u4f20\u64ad\u800c\u4e0d\u4f1a\u8870\u51cf\u3002  <\/li><li>  \u8d1d\u8482\u7684\u6a21\u578b\uff08\u5373\u79fb\u9664\u0393<em>r<\/em>\uff09\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u4e00\u4e2a\u65f6\u95f4\u6b65\u800c\u8a00\uff0c\u5982\u679c\u0393<em>u<\/em>\u22480\uff0c\u68af\u5ea6\u53ef\u4ee5\u901a\u8fc7\u65f6\u95f4\u6b65\u53cd\u5411\u4f20\u64ad\u800c\u4e0d\u4f1a\u8870\u51cf\u3002 <\/li><li>  \u8d1d\u8482\u7684\u6a21\u578b\uff08\u5373\u79fb\u9664\u0393<em>r<\/em>\uff09\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u4e00\u4e2a\u65f6\u95f4\u6b65\u800c\u8a00\uff0c\u5982\u679c\u0393<em>u<\/em>\u22481\uff0c\u68af\u5ea6\u53ef\u4ee5\u901a\u8fc7\u65f6\u95f4\u6b65\u53cd\u5411\u4f20\u64ad\u800c\u4e0d\u4f1a\u8870\u51cf\u3002 <\/li><\/ol>\n\n\n<p>3\u3002\uff08 \u8981\u4f7f\u4fe1\u53f7\u53cd\u5411\u4f20\u64ad\u800c\u4e0d\u6d88\u5931\uff0c\u6211\u4eec\u9700\u8981 <em>c<\/em>&lt;<em>t<\/em>&gt;\u9ad8\u5ea6\u4f9d\u8d56\u4e8e<em>c<\/em>&lt;<em>t<\/em>\u22121&gt; \uff09<\/p>\n\n\n<p><strong>9. \u8fd9\u91cc\u6709\u4e00\u4e9bGRU\u548cLSTM\u7684\u65b9\u7a0b:   \u4ece\u8fd9\u4e9b\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5728LSTM\u4e2d\u7684\u66f4\u65b0\u95e8\u548c\u9057\u5fd8\u95e8\u5728GRU\u4e2d\u626e\u6f14\u7c7b\u4f3c \u2013\u2013\u2013\u2013\u2013\u4e0e\u2013\u2013\u2013\u2013\u2013\u7684\u89d2\u8272\uff0c\u7a7a\u767d\u5904\u5e94\u8be5\u586b\u4ec0\u4e48\uff1f <\/strong><\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"411\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-202.png\" alt=\"\" class=\"wp-image-3408\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-202.png 882w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-202-300x140.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-202-768x358.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure><\/div>\n\n\n<p> \u0393<em>u<\/em> \u4e0e 1\u2212\u0393<em>u<\/em><\/p>\n\n\n<p><strong>10. \u4f60\u6709\u4e00\u53ea\u5ba0\u7269\u72d7\uff0c\u5b83\u7684\u5fc3\u60c5\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d6\u51b3\u4e8e\u5f53\u524d\u548c\u8fc7\u53bb\u51e0\u5929\u7684\u5929\u6c14\u3002\u4f60\u5df2\u7ecf\u6536\u96c6\u4e86\u8fc7\u53bb365\u5929\u7684\u5929\u6c14\u6570\u636e<\/strong><em><strong>x<\/strong><\/em><strong>&lt;1&gt;,\u2026,<\/strong><em><strong>x<\/strong><\/em><strong>&lt;365&gt;\uff0c\u8fd9\u4e9b\u6570\u636e\u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u4f60\u8fd8\u6536\u96c6\u4e86\u4f60\u7684\u72d7\u5fc3\u60c5\u7684\u6570\u636e<\/strong><em><strong>y<\/strong><\/em><strong>&lt;1&gt;,\u2026,<\/strong><em><strong>y<\/strong><\/em><strong>&lt;365&gt;\uff0c\u4f60\u60f3\u5efa\u7acb\u4e00\u4e2a\u6a21\u578b\u6765\u4ecex\u5230y\u8fdb\u884c\u6620\u5c04\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528\u5355\u5411RNN\u8fd8\u662f\u53cc\u5411RNN\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f <\/strong><\/p>\n\n\n<p>\u5355\u5411RNN\uff0c\u56e0\u4e3a\u72d7\u4e5f\u4e0d\u80fd\u9884\u77e5\u672a\u6765x\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u7f16\u7a0b\u4f5c\u4e1a<\/h2>\n\n\n<p>\u9996\u5148\u7b80\u5355\u5b9e\u73b0\u4ee5\u4e0bRNN\u548cLSTM\u7136\u540e\u4f7f\u7528RNN\u9884\u6d4b\u6050\u9f99\u540d\u5b57\u3002<\/p>\n\n\n<p> RNN\u6a21\u578b\u548c\u516c\u5f0f\u5982\u4e0b\uff1a <\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"341\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-203.png\" alt=\"\" class=\"wp-image-3412\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-203.png 751w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-203-300x136.png 300w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/figure><\/div>\n\n\n<p>\u9996\u5148\u5bfc\u5305\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br \/>from course_5_week_1 import rnn_utils<\/pre>\n\n\n<p>\u7136\u540e\u662f\u4e00\u4e2acell\u7684\u524d\u5411\u4f20\u64ad\uff0c\u5176\u4e2d\u6700\u4e3b\u8981\u7684\u5c31\u662f\u54ea\u4e24\u4e2a\u516c\u5f0f\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def rnn_cell_forward(xt, a_prev, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    rnn cell<\/em><em>\u524d\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> xt:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> a_prev:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em># \u4eceparameters\u201d\u83b7\u53d6\u53c2\u6570<br \/>    Wax = parameters[\"Wax\"]<br \/>    Waa = parameters[\"Waa\"]<br \/>    Wya = parameters[\"Wya\"]<br \/>    ba = parameters[\"ba\"]<br \/>    by = parameters[\"by\"]<br \/><br \/>    a_next = np.tanh(np.dot(Waa, a_prev) + np.dot(Wax, xt) + ba)<br \/>    # \u4f7f\u7528\u4e0a\u9762\u7684\u516c\u5f0f\u8ba1\u7b97\u5f53\u524d\u5355\u5143\u7684\u8f93\u51fa<br \/>    yt_pred = rnn_utils.softmax(np.dot(Wya, a_next) + by)<br \/><br \/>    # \u4fdd\u5b58\u53cd\u5411\u4f20\u64ad\u9700\u8981\u7684\u503c<br \/>    cache = (a_next, a_prev, xt, parameters)<br \/><br \/>    return a_next, yt_pred, cache<\/pre>\n\n\n<p>\u7136\u540e\u6211\u4eec\u505a\u5168\u90e8\u7684\u524d\u5411\u4f20\u64ad\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def rnn_forward(X, a0, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    rnn <\/em><em>\u524d\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> X:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> a0:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>caches = []<br \/><br \/>    # \u83b7\u53d6x\u548cWya\u7684\u7ef4\u5ea6\u4fe1\u606f<br \/>    n_x, m, T_x = X.shape<br \/>    n_y, n_a = parameters['Wya'].shape<br \/><br \/>    # \u4f7f\u75280\u6765\u521d\u59cb\u5316a\u548cy<br \/>    a = np.zeros([n_a, m, T_x])<br \/>    y_pred = np.zeros([n_y, m, T_x])<br \/><br \/>    # \u521d\u59cb\u5316next<br \/>    a_next = a0<br \/><br \/>    # \u904d\u5386\u6240\u6709\u7684\u5e8f\u5217<br \/>    for i in range(T_x):<br \/>        # cell\u524d\u5411\u4f20\u64ad<br \/>        a_next, yt_pred, cache = rnn_cell_forward(X[:, :, i], a_next, parameters)<br \/>        # \u4f7f\u7528 a \u6765\u4fdd\u5b58\u201cnext\u201d\u9690\u85cf\u72b6\u6001\uff08\u7b2c i\uff09\u4e2a\u4f4d\u7f6e\u3002<br \/>        a[:, :, i] = a_next<br \/>        # \u4fdd\u5b58\u9884\u6d4b\u503c<br \/>        y_pred[:, :, i] = yt_pred<br \/><br \/>        caches.append(cache)<br \/>    caches = (caches, X)<br \/><br \/>    return a, y_pred, caches<br \/><\/pre>\n\n\n<p>\u540c\u6837\uff0c\u5bf9\u4e8eLSTM\uff0c\u6a21\u578b\u548c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"332\" src=\"\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-204.png\" alt=\"\" class=\"wp-image-3413\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-204.png 733w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/03\/\u56fe\u7247-204-300x136.png 300w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/figure><\/div>\n\n\n<p>lstm\u7684cell\u5982\u4e0b\uff0c\u6838\u5fc3\u8fd8\u662f\u90a36\u4e2a\u516c\u5f0f\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def lstm_cell_forward(xt, a_prev, c_prev, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    lstm cell <\/em><em>\u524d\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> xt:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> a_prev:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> c_prev:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em># \u4ece\u201cparameters\u201d\u4e2d\u83b7\u53d6\u76f8\u5173\u503c<br \/>    Wf = parameters[\"Wf\"]<br \/>    bf = parameters[\"bf\"]<br \/>    Wi = parameters[\"Wi\"]<br \/>    bi = parameters[\"bi\"]<br \/>    Wc = parameters[\"Wc\"]<br \/>    bc = parameters[\"bc\"]<br \/>    Wo = parameters[\"Wo\"]<br \/>    bo = parameters[\"bo\"]<br \/>    Wy = parameters[\"Wy\"]<br \/>    by = parameters[\"by\"]<br \/><br \/>    # \u83b7\u53d6x_t\u3001Wy\u7ef4\u5ea6\u4fe1\u606f<br \/>    n_x, m = xt.shape<br \/>    n_y, n_a = Wy.shape<br \/><br \/>    # \u94fe\u63a5a_prev\u4e0ext<br \/>    contact = np.zeros([n_a + n_x, m])<br \/>    contact[:n_a, :] = a_prev<br \/>    contact[n_a:, :] = xt<br \/><br \/>    # \u6839\u636e\u516c\u5f0f\u8ba1\u7b97<br \/>    # \u9057\u5fd8\u95e8\uff0c\u516c\u5f0f1<br \/>    ft = rnn_utils.sigmoid(np.dot(Wf, contact) + bf)<br \/><br \/>    # \u66f4\u65b0\u95e8\uff0c\u516c\u5f0f2<br \/>    ut = rnn_utils.sigmoid(np.dot(Wi, contact) + bi)<br \/><br \/>    # \u66f4\u65b0\u5355\u5143\uff0c\u516c\u5f0f3<br \/>    cct = np.tanh(np.dot(Wc, contact) + bc)<br \/><br \/>    # \u66f4\u65b0\u5355\u5143\uff0c\u516c\u5f0f4<br \/>    c_next = ft * c_prev + ut * cct<br \/>    # \u8f93\u51fa\u95e8\uff0c\u516c\u5f0f5<br \/>    ot = rnn_utils.sigmoid(np.dot(Wo, contact) + bo)<br \/><br \/>    # \u8f93\u51fa\u95e8\uff0c\u516c\u5f0f6<br \/>    # a_next = np.multiply(ot, np.tan(c_next))<br \/>    a_next = ot * np.tanh(c_next)<br \/>    # 3.\u8ba1\u7b97LSTM\u5355\u5143\u7684\u9884\u6d4b\u503c<br \/>    yt_pred = rnn_utils.softmax(np.dot(Wy, a_next) + by)<br \/><br \/>    # \u4fdd\u5b58\u5305\u542b\u4e86\u53cd\u5411\u4f20\u64ad\u6240\u9700\u8981\u7684\u53c2\u6570<br \/>    cache = (a_next, c_next, a_prev, c_prev, ft, ut, cct, ot, xt, parameters)<br \/><br \/>    return a_next, c_next, yt_pred, cache<\/pre>\n\n\n<p>\u56e0\u6b64\u6574\u4e2alstm\u7684\u524d\u5411\u4f20\u64ad\u5982\u4e0b\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def lstm_forward(x, a0, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    lstm<\/em><em>\u524d\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> x:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> a0:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>caches = []<br \/><br \/>    n_x, m, T_x = x.shape<br \/>    n_y, n_a = parameters['Wy'].shape<br \/><br \/>    # \u4f7f\u75280\u6765\u521d\u59cb\u5316a,c,y<br \/>    a = np.zeros([n_a, m, T_x])<br \/>    c = np.zeros([n_a, m, T_x])<br \/>    y = np.zeros([n_y, m, T_x])<br \/><br \/>    # \u521d\u59cb\u5316anext  cnext<br \/>    a_next = a0<br \/>    c_next = np.zeros([n_a, m])<br \/><br \/>    # \u904d\u5386\u6240\u6709\u7684\u65f6\u95f4\u6b65<br \/>    for t in range(T_x):<br \/>        # \u66f4\u65b0\u4e0b\u4e00\u4e2a\u9690\u85cf\u72b6\u6001\uff0c\u4e0b\u4e00\u4e2a\u8bb0\u5fc6\u72b6\u6001\uff0c\u8ba1\u7b97\u9884\u6d4b\u503c\uff0c\u83b7\u53d6cache<br \/>        a_next, c_next, yt_pred, cache = lstm_cell_forward(x[:, :, t], a_next, c_next, parameters)<br \/><br \/>        # \u4fdd\u5b58\u65b0\u7684\u4e0b\u4e00\u4e2a\u9690\u85cf\u72b6\u6001\u5230\u53d8\u91cfa\u4e2d<br \/>        a[:, :, t] = a_next<br \/><br \/>        # \u4fdd\u5b58\u9884\u6d4b\u503c\u5230\u53d8\u91cfy\u4e2d<br \/>        y[:, :, t] = yt_pred<br \/><br \/>        # \u4fdd\u5b58\u4e0b\u4e00\u4e2a\u5355\u5143\u72b6\u6001\u5230\u53d8\u91cfc\u4e2d<br \/>        c[:, :, t] = c_next<br \/><br \/>        # \u628acache\u6dfb\u52a0\u5230caches\u4e2d<br \/>        caches.append(cache)<br \/><br \/>    # \u4fdd\u5b58\u53cd\u5411\u4f20\u64ad\u9700\u8981\u7684\u53c2\u6570<br \/>    caches = (caches, x)<br \/><br \/>    return a, y, c, caches<\/pre>\n\n\n<p>\u7136\u540e\u6211\u4eec\u505a\u4e2a\u7b80\u5355\u7684RNN\u7f51\u7edc\uff1a<\/p>\n\n\n<p>\u9996\u5148\u5bfc\u5305\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br \/>import random<br \/>import time<br \/><br \/>from course_5_week_1 import cllm_utils as utils<\/pre>\n\n\n<p>\u68af\u5ea6\u4fee\u526a\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def clip(gradients, maxValue):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u68af\u5ea6\u4fee\u526a<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> gradients:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> maxValue:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>dWaa, dWax, dWya, db, dby = gradients['dWaa'], gradients['dWax'], gradients['dWya'], gradients['db'], gradients[<br \/>        'dby']<br \/>    # \u68af\u5ea6\u4fee\u526a<br \/>    for gradient in [dWaa, dWax, dWya, db, dby]:<br \/>        np.clip(gradient, -maxValue, maxValue, out=gradient)<br \/><br \/>    gradients = {<br \/>        'dWaa': dWaa,<br \/>        'dWax': dWax,<br \/>        'dWya': dWya,<br \/>        'db': db,<br \/>        'dby': dby<br \/>    }<br \/>    return gradients<br \/><\/pre>\n\n\n<p>\u5728\u7f51\u7edc\u4e2d\u8fdb\u884c\u53d6\u6837\uff0c\u5c31\u662f\u5bf9\u6bcf\u4e00\u4e2aLSTM\u7684cell\u53d6\u51fa\u5355\u8bcd\uff0c\u6c47\u6210\u4e00\u4e2a\u53e5\u5b50\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def sample(parameters, char_to_ix, seed):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u53d6\u6837<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> char_to_is:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> seed:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>Waa, Wax, Wya, by, b = parameters['Waa'], parameters['Wax'], parameters['Wya'], parameters['by'], parameters['b']<br \/>    vocab_size = by.shape[0]<br \/>    n_a = Waa.shape[1]<br \/><br \/>    # \u521b\u5efaone hot \u5411\u91cf<br \/>    x = np.zeros((vocab_size, 1))<br \/>    # \u521d\u59cb\u5316a0<br \/>    a_prev = np.zeros((n_a, 1))<br \/>    # \u8f93\u51fa\u5217\u8868<br \/>    output = []<br \/>    # \u6362\u884c\u6807\u8bb0<br \/>    idx = -1<br \/>    counter = 0<br \/>    newline_character = char_to_ix['\\n']<br \/><br \/>    # \u5982\u679c\u4e0d\u662f\u6362\u884c\u7b26\u6216\u8005\u8f93\u51fa\u4e0d\u8d85\u8fc750\u4e2a<br \/>    while idx != newline_character and counter &lt; 50:<br \/>        # \u524d\u5411\u4f20\u64ad<br \/>        a = np.tanh(np.dot(Wax, x) + np.dot(Waa, a_prev) + b)<br \/>        z = np.dot(Wya, a) + by<br \/>        y = utils.softmax(z)<br \/><br \/>        # \u968f\u673a\u6570\u79cd\u5b50<br \/>        np.random.seed(counter + seed)<br \/><br \/>        # \u4ece\u968f\u673a\u6982\u7387\u5206\u5e03\u4e2d\u83b7\u53d6\u5b57\u7b26<br \/>        idx = np.random.choice(list(range(vocab_size)), p=y.ravel())<br \/><br \/>        # \u6dfb\u52a0\u7d22\u5f15<br \/>        output.append(idx)<br \/><br \/>        x = np.zeros((vocab_size, 1))<br \/>        x[idx] = 1<br \/><br \/>        # \u66f4\u65b0a_prev<br \/>        a_prev = a<br \/><br \/>        seed += 1<br \/>        counter += 1<br \/><br \/>    if counter == 50:<br \/>        output.append(char_to_ix['\\n'])<br \/><br \/>    return output<\/pre>\n\n\n<p>\u7136\u540e\u662f\u4f18\u5316\u65b9\u6cd5\uff0c\u5305\u62ec\u524d\u5411\u3001\u53cd\u5411\u3001\u66f4\u65b0\u53c2\u6570\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def optimize(X, y, a_prev, parameters, learning_rate=0.01):<br \/>    <em>\"\"\"<br \/><\/em><em>    rnn<\/em><em>\u7684\u5355\u6b65\u4f18\u5316<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> X:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> y:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> a_prev:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> learning_rate:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em># \u524d\u5411\u4f20\u64ad<br \/>    loss, cache = utils.rnn_forward(X, y, a_prev, parameters)<br \/>    # \u53cd\u5411\u4f20\u64ad<br \/>    gradients, a = utils.rnn_backward(X, y, parameters, cache)<br \/>    # \u68af\u5ea6\u4fee\u526a<br \/>    gradients = clip(gradients, 5)<br \/>    # \u66f4\u65b0\u53c2\u6570<br \/>    parameters = utils.update_parameters(parameters, gradients, learning_rate)<br \/><br \/>    return loss, gradients, a[len(X) - 1]  # \u4ee3\u4ef7  \u53c2\u6570  \u9690\u85cf\u5c42<\/pre>\n\n\n<p>\u6700\u540e\u5c06\u4ed6\u4eec\u5168\u90e8\u5408\u6210\u4e00\u4e2a\u6a21\u5757\u5e76\u8c03\u7528\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def model(data, ix_to_char, char_to_ix, num_iterations=3500,<br \/>          n_a=50, dino_names=7, vocab_size=27):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u6a21\u578b<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> data:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> ix_to_char:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> char_to_ix:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> num_iterations:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> n_a:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> dino_names:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> vocab_size:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em><br \/><\/em><em>    <\/em># \u4ecevocab_size\u4e2d\u83b7\u53d6n_x\u3001n_y<br \/>    n_x, n_y = vocab_size, vocab_size<br \/><br \/>    # \u521d\u59cb\u5316\u53c2\u6570<br \/>    parameters = utils.initialize_parameters(n_a, n_x, n_y)<br \/><br \/>    # \u521d\u59cb\u5316\u635f\u5931<br \/>    loss = utils.get_initial_loss(vocab_size, dino_names)<br \/><br \/>    # \u6784\u5efa\u6050\u9f99\u540d\u79f0\u5217\u8868<br \/>    with open(\"dinos.txt\") as f:<br \/>        examples = f.readlines()<br \/>    examples = [x.lower().strip() for x in examples]<br \/><br \/>    # \u6253\u4e71\u5168\u90e8\u7684\u6050\u9f99\u540d\u79f0<br \/>    np.random.seed(0)<br \/>    np.random.shuffle(examples)<br \/><br \/>    # \u521d\u59cb\u5316LSTM\u9690\u85cf\u72b6\u6001<br \/>    a_prev = np.zeros((n_a, 1))<br \/><br \/>    # \u5faa\u73af<br \/>    for j in range(num_iterations):<br \/>        # \u5b9a\u4e49\u4e00\u4e2a\u8bad\u7ec3\u6837\u672c<br \/>        index = j % len(examples)<br \/>        X = [None] + [char_to_ix[ch] for ch in examples[index]]<br \/>        Y = X[1:] + [char_to_ix[\"\\n\"]]<br \/><br \/>        # \u6267\u884c\u5355\u6b65\u4f18\u5316\uff1a\u524d\u5411\u4f20\u64ad -&gt; \u53cd\u5411\u4f20\u64ad -&gt; \u68af\u5ea6\u4fee\u526a -&gt; \u66f4\u65b0\u53c2\u6570<br \/>        # \u9009\u62e9\u5b66\u4e60\u7387\u4e3a0.01<br \/>        curr_loss, gradients, a_prev = optimize(X, Y, a_prev, parameters)<br \/><br \/>        # \u4f7f\u7528\u5ef6\u8fdf\u6765\u4fdd\u6301\u635f\u5931\u5e73\u6ed1,\u8fd9\u662f\u4e3a\u4e86\u52a0\u901f\u8bad\u7ec3\u3002<br \/>        loss = utils.smooth(loss, curr_loss)<br \/><br \/>        # \u6bcf2000\u6b21\u8fed\u4ee3\uff0c\u901a\u8fc7sample()\u751f\u6210\u201c\\n\u201d\u5b57\u7b26\uff0c\u68c0\u67e5\u6a21\u578b\u662f\u5426\u5b66\u4e60\u6b63\u786e<br \/>        if j % 2000 == 0:<br \/>            print(\"\u7b2c\" + str(j + 1) + \"\u6b21\u8fed\u4ee3\uff0c\u635f\u5931\u503c\u4e3a\uff1a\" + str(loss))<br \/><br \/>            seed = 0<br \/>            for name in range(dino_names):<br \/>                # \u91c7\u6837<br \/>                sampled_indices = sample(parameters, char_to_ix, seed)<br \/>                utils.print_sample(sampled_indices, ix_to_char)<br \/><br \/>                # \u4e3a\u4e86\u5f97\u5230\u76f8\u540c\u7684\u6548\u679c\uff0c\u968f\u673a\u79cd\u5b50+1<br \/>                seed += 1<br \/><br \/>            print(\"\\n\")<br \/>    return parameters<br \/><br \/><br \/># \u5f00\u59cb\u65f6\u95f4<br \/>start_time = time.clock()<br \/># \u5f00\u59cb\u8bad\u7ec3<br \/>parameters = model(data, ix_to_char, char_to_ix, num_iterations=3500)<br \/># \u7ed3\u675f\u65f6\u95f4<br \/>end_time = time.clock()<br \/># \u8ba1\u7b97\u65f6\u5dee<br \/>minium = end_time - start_time<br \/>print(\"\u6267\u884c\u4e86\uff1a\" + str(int(minium \/ 60)) + \"\u5206\" + str(int(minium % 60)) + \"\u79d2\")<br \/><\/pre>\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>\u7b2c1\u6b21\u8fed\u4ee3\uff0c\u635f\u5931\u503c\u4e3a\uff1a23.0873360855\nNkzxwtdmfqoeyhsqwasjkjvu\nKneb\nKzxwtdmfqoeyhsqwasjkjvu\nNeb\nZxwtdmfqoeyhsqwasjkjvu\nEb\nXwtdmfqoeyhsqwasjkjvu\n\u7b2c2001\u6b21\u8fed\u4ee3\uff0c\u635f\u5931\u503c\u4e3a\uff1a27.8841604914\nLiusskeomnolxeros\nHmdaairus\nHytroligoraurus\nLecalosapaus\nXusicikoraurus\nAbalpsamantisaurus\nTpraneronxeros\n\u6267\u884c\u4e86\uff1a0\u52063\u79d2<\/code><\/pre>\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6548\u679c\u660e\u663e\u53d8\u597d\u4e86\uff0c\u66f4\u50cf\u4e00\u4e2a\u540d\u5b57\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u7b2c\u4e94\u8bfe\u7b2c\u4e00\u5468\uff1a\u5e8f\u5217\u6a21\u578b 1.\u4e3a\u4ec0\u4e48\u9009\u62e9\u5e8f\u5217\u6a21\u578b \u5f88\u591a\u4efb\u52a1\u4e2d\u6570\u636e\u5bf9\u5148\u540e\u654f\u611f\uff0c\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"views":8297,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3381"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=3381"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3381\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3381"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}