{"id":5693,"date":"2022-08-10T18:32:38","date_gmt":"2022-08-10T10:32:38","guid":{"rendered":"http:\/\/139.9.1.231\/?p=5693"},"modified":"2022-08-10T18:32:40","modified_gmt":"2022-08-10T10:32:40","slug":"bert-pre-training-of-deep-bidirectional-transformers-for-language-understanding","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/08\/10\/bert-pre-training-of-deep-bidirectional-transformers-for-language-understanding\/","title":{"rendered":"BERT-Pre-training of Deep Bidirectional Transformers for Language Understanding"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"263\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-171-1024x263.png\" alt=\"\" class=\"wp-image-5694\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-171-1024x263.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-171-300x77.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-171-768x197.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-171.png 1122w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Transformer\u6a21\u578b\u662f\u76ee\u524d\u673a\u5668\u7ffb\u8bd1\u7b49NLP\u95ee\u9898\u6700\u597d\u7684\u89e3\u51b3\u529e\u6cd5\uff0c\u6bd4RNN\u6709\u5927\u5e45\u63d0\u9ad8\u3002Bidirectional Encoder Representations from Transformers (BERT) \u662f\u9884\u8bad\u7ec3Transformer\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5927\u5e45\u63d0\u5347Transformer\u7684\u8868\u73b0\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"540\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172-1024x540.png\" alt=\"\" class=\"wp-image-5697\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172-1024x540.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172-300x158.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172-768x405.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172-1536x810.png 1536w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-172.png 1750w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>bert\u4e3b\u8981\u4f7f\u7528\u4e24\u4e2a\u4efb\u52a1\u505a\u8bad\u7ec3\uff1a<\/p>\n\n\n\n<p>1\u3001\u9884\u6d4b\u88ab\u906e\u6321\u7684\u5355\u8bcd<\/p>\n\n\n\n<p>2\u3001\u5224\u65ad\u4e24\u53e5\u8bdd\u662f\u5426\u76f8\u90bb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"921\" height=\"626\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-173.png\" alt=\"\" class=\"wp-image-5699\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-173.png 921w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-173-300x204.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-173-768x522.png 768w\" sizes=\"(max-width: 921px) 100vw, 921px\" \/><\/figure>\n\n\n\n<p>\u4efb\u52a1\u4e00\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"909\" height=\"622\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-175.png\" alt=\"\" class=\"wp-image-5703\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-175.png 909w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-175-300x205.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-175-768x526.png 768w\" sizes=\"(max-width: 909px) 100vw, 909px\" \/><\/figure>\n\n\n\n<p>\u00b7\ud835\udc1e: one-hot vector of the masked word \u201ccat\u201d.<br>\u2022 \ud835\udc29: output probability distribution at the masked position.<br>\u2022 Loss = CrossEntropy\uff08\ud835\udc1e, \ud835\udc29\uff09 .<br>\u2022 Performing one gradient descent to update the model parameters.<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><strong>Task 2: Predict the Next Sentence<\/strong><\/p>\n\n\n\n<p>Given the sentence:<br>\u201ccalculus is a branch of math\u201d.<br>\u2022 Is this the next sentence?<br>\u201cit was developed by newton and leibniz\u201d<\/p>\n\n\n\n<p><strong>Input:<\/strong>\u4e24\u53e5\u8bdd\u4e4b\u95f4\u6709sep\u7b26\u53f7\u5206\u5f00\uff0ccls\u8868\u793a\u5206\u7c7b\u4efb\u52a1<br>[CLS] \u201ccalculus is a branch of math\u201d<br>[SEP] \u201cit was developed by newton and leibniz\u201d<br>\u2022 [CLS] is a token for classification.<br>\u2022 [SEP] is for separating sentences.<\/p>\n\n\n\n<p>Input:<br>[CLS] \u201ccalculus is a branch of math\u201d<br>[SEP] \u201cit was developed by newton and leibniz\u201d<br>\u2022 Target: true<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"566\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-177-1024x566.png\" alt=\"\" class=\"wp-image-5709\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-177-1024x566.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-177-300x166.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-177-768x424.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-177.png 1070w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>Combining the two methods\uff1a<\/h2>\n\n\n\n<p>\u2022 Input:<br>\u201c[CLS] calculus is a [MASK] of math<br>[SEP] it [MASK] developed by newton and leibniz\u201d.<br>\u2022 Targets: true, \u201cbranch\u201d, \u201cwas\u201d.<\/p>\n\n\n\n<p>bert\u540c\u65f6\u4f7f\u7528\u4e24\u79cd\u4efb\u52a1\u7ed3\u5408\uff1a<\/p>\n\n\n\n<p><br>Loss 1 is for binary classification (i.e., predicting the next<br>sentence.)<br>\u2022 Loss 2 and Loss 3 are for multi-class classification (i.e., predicting<br>the masked words.)<br>\u2022 Objective function is the sum of the three loss functions.<br>\u2022 Update model parameters by performing one gradient descent<\/p>\n\n\n\n<p>\u6570\u636e\u96c6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"980\" height=\"306\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-178.png\" alt=\"\" class=\"wp-image-5713\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-178.png 980w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-178-300x94.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/08\/image-178-768x240.png 768w\" sizes=\"(max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<h2 class=\"has-light-pink-background-color has-background\"><strong>BERT\u7684bidirectional\u5982\u4f55\u4f53\u73b0\u7684\uff1f<\/strong><\/h2>\n\n\n\n<p>\u8bba\u6587\u7814\u7a76\u56e2\u961f\u6709\u7406\u7531\u76f8\u4fe1\uff0c\u6df1\u5ea6\u53cc\u5411\u6a21\u578b\u6bd4left-to-right \u6a21\u578b\u6216left-to-right and right-to-left\u6a21\u578b\u7684\u6d45\u5c42\u8fde\u63a5\u66f4\u5f3a\u5927\u3002\u4ece\u4e2d\u53ef\u4ee5\u770b\u51faBERT\u7684\u53cc\u5411\u53eb\u6df1\u5ea6\u53cc\u5411\uff0c\u4e0d\u540c\u4e8e\u4ee5\u5f80\u7684\u53cc\u5411\u7406\u89e3\uff0c\u4ee5\u5f80\u7684\u53cc\u5411\u662f\u4ece\u5de6\u5230\u53f3\u548c\u4ece\u53f3\u5230\u5de6\u7ed3\u5408\uff0c\u8fd9\u79cd\u867d\u7136\u770b\u7740\u662f\u53cc\u5411\u7684\uff0c\u4f46\u662f\u4e24\u4e2a\u65b9\u5411\u7684loss\u8ba1\u7b97\u76f8\u4e92\u72ec\u7acb\uff0c\u6240\u4ee5\u5176\u5b9e\u8fd8\u662f\u5355\u5411\u7684\uff0c\u53ea\u4e0d\u8fc7\u7b80\u5355\u878d\u5408\u4e86\u4e00\u4e0b\uff0c\u800cbert\u7684\u53cc\u5411\u662f\u8981\u540c\u65f6\u770b\u4e0a\u4e0b\u6587\u8bed\u5883\u7684\uff0c\u6240\u6709\u4e0d\u540c\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u8bad\u7ec3\u4e00\u4e2a\u6df1\u5ea6\u53cc\u5411\u8868\u793a\uff08deep bidirectional representation\uff09\uff0c\u7814\u7a76\u56e2\u961f\u91c7\u7528\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5373\u968f\u673a\u5c4f\u853d\uff08masking\uff09\u90e8\u5206\u8f93\u5165token\uff0c\u7136\u540e\u53ea\u9884\u6d4b\u90a3\u4e9b\u88ab\u5c4f\u853d\u7684token\uff0c(<strong>\u6211\u7406\u89e3\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6a21\u578b\u5982\u679c\u60f3\u9884\u6d4b\u51fa\u8fd9\u4e2amasked\u7684\u8bcd\uff0c\u5c31\u5fc5\u987b\u7ed3\u5408\u4e0a\u4e0b\u6587\u6765\u9884\u6d4b\uff0c\u6240\u4ee5\u5c31\u8fbe\u5230\u4e86\u53cc\u5411\u76ee\u7684\uff0c\u6709\u70b9\u7c7b\u4f3c\u4e8e\u6211\u4eec\u5c0f\u5b66\u65f6\u5019\u505a\u7684\u5b8c\u5f62\u586b\u7a7a\u9898\u76ee\uff0c\u4f60\u8981\u586b\u5199\u5bf9\u8fd9\u4e2a\u8bcd\uff0c\u5c31\u5fc5\u987b\u7ed3\u5408\u4e0a\u4e0b\u6587\uff0cBERT\u5c31\u662f\u8fd9\u4e2a\u601d\u8def\u8bad\u7ec3\u673a\u5668\u7684\uff0c\u770b\u6765\u5229\u7528\u5c0f\u5b66\u751f\u7684\u6559\u5b66\u65b9\u5f0f\uff0c\u6709\u52a9\u4e8e\u8bad\u7ec3\u673a\u5668)<\/strong>\u3002\u8bba\u6587\u5c06\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4e3a\u201cMasked Language Model\u201d(MLM)\u3002<\/p>\n\n\n\n<p>Masked\u53cc\u5411\u8bed\u8a00\u6a21\u578b\u8fd9\u4e48\u505a\uff1a\u968f\u673a\u9009\u62e9\u8bed\u6599\u4e2d15%\u7684\u5355\u8bcd\uff0c\u628a\u5b83\u62a0\u6389\uff0c\u4e5f\u5c31\u662f\u7528[Mask]\u63a9\u7801\u4ee3\u66ff\u539f\u59cb\u5355\u8bcd\uff0c\u7136\u540e\u8981\u6c42\u6a21\u578b\u53bb\u6b63\u786e\u9884\u6d4b\u88ab\u62a0\u6389\u7684\u5355\u8bcd\u3002\u4f46\u662f\u8fd9\u91cc\u6709\u4e2a\u95ee\u9898\uff1a\u8bad\u7ec3\u8fc7\u7a0b\u5927\u91cf\u770b\u5230[mask]\u6807\u8bb0\uff0c\u4f46\u662f\u771f\u6b63\u540e\u9762\u7528\u7684\u65f6\u5019\u662f\u4e0d\u4f1a\u6709\u8fd9\u4e2a\u6807\u8bb0\u7684\uff0c\u8fd9\u4f1a\u5f15\u5bfc\u6a21\u578b\u8ba4\u4e3a\u8f93\u51fa\u662f\u9488\u5bf9[mask]\u8fd9\u4e2a\u6807\u8bb0\u7684\uff0c\u4f46\u662f\u5b9e\u9645\u4f7f\u7528\u53c8\u89c1\u4e0d\u5230\u8fd9\u4e2a\u6807\u8bb0\uff0c\u8fd9\u81ea\u7136\u4f1a\u6709\u95ee\u9898\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u4e2a\u95ee\u9898\uff0cBert\u6539\u9020\u4e86\u4e00\u4e0b\uff0c15%\u7684\u88ab\u4e0a\u5929\u9009\u4e2d\u8981\u6267\u884c[mask]\u66ff\u8eab\u8fd9\u9879\u5149\u8363\u4efb\u52a1\u7684\u5355\u8bcd\u4e2d\uff0c\u53ea\u670980%\u771f\u6b63\u88ab\u66ff\u6362\u6210[mask]\u6807\u8bb0\uff0c10%\u88ab\u72f8\u732b\u6362\u592a\u5b50\u968f\u673a\u66ff\u6362\u6210\u53e6\u5916\u4e00\u4e2a\u5355\u8bcd\uff0c10%\u60c5\u51b5\u8fd9\u4e2a\u5355\u8bcd\u8fd8\u5f85\u5728\u539f\u5730\u4e0d\u505a\u6539\u52a8\u3002\u8fd9\u5c31\u662fMasked\u53cc\u5411\u8bed\u97f3\u6a21\u578b\u7684\u5177\u4f53\u505a\u6cd5\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u5728\u8fd9\u4e2a\u53e5\u5b50\u201cmy dog is hairy\u201d\u4e2d\uff0c\u5b83\u9009\u62e9\u7684token\u662f\u201chairy\u201d\u3002\u7136\u540e\uff0c\u6267\u884c\u4ee5\u4e0b\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<p>\u6570\u636e\u751f\u6210\u5668\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff0c\u800c\u4e0d\u662f\u59cb\u7ec8\u7528[MASK]\u66ff\u6362\u6240\u9009\u5355\u8bcd\uff1a<\/p>\n\n\n\n<p>80\uff05\u7684\u65f6\u95f4\uff1a\u7528[MASK]\u6807\u8bb0\u66ff\u6362\u5355\u8bcd\uff0c\u4f8b\u5982\uff0cmy dog is hairy \u2192 my dog is [MASK]<br>10\uff05\u7684\u65f6\u95f4\uff1a\u7528\u4e00\u4e2a\u968f\u673a\u7684\u5355\u8bcd\u66ff\u6362\u8be5\u5355\u8bcd\uff0c\u4f8b\u5982\uff0cmy dog is hairy \u2192 my dog is apple<br>10\uff05\u7684\u65f6\u95f4\uff1a\u4fdd\u6301\u5355\u8bcd\u4e0d\u53d8\uff0c\u4f8b\u5982\uff0cmy dog is hairy \u2192 my dog is hairy. \u8fd9\u6837\u505a\u7684\u76ee\u7684\u662f\u5c06\u8868\u793a\u504f\u5411\u4e8e\u5b9e\u9645\u89c2\u5bdf\u5230\u7684\u5355\u8bcd\u3002<\/p>\n\n\n\n<p><br>Transformer encoder\u4e0d\u77e5\u9053\u5b83\u5c06\u88ab\u8981\u6c42\u9884\u6d4b\u54ea\u4e9b\u5355\u8bcd\u6216\u54ea\u4e9b\u5355\u8bcd\u5df2\u88ab\u968f\u673a\u5355\u8bcd\u66ff\u6362\uff0c\u56e0\u6b64\u5b83\u88ab\u8feb\u4fdd\u6301\u6bcf\u4e2a\u8f93\u5165token\u7684\u5206\u5e03\u5f0f\u4e0a\u4e0b\u6587\u8868\u793a\u3002\u6b64\u5916\uff0c\u56e0\u4e3a\u968f\u673a\u66ff\u6362\u53ea\u53d1\u751f\u5728\u6240\u6709token\u76841.5\uff05\uff08\u537315\uff05\u768410\uff05\uff09\uff0c\u8fd9\u4f3c\u4e4e\u4e0d\u4f1a\u635f\u5bb3\u6a21\u578b\u7684\u8bed\u8a00\u7406\u89e3\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528MLM\u7684\u7b2c\u4e8c\u4e2a\u7f3a\u70b9\u662f\u6bcf\u4e2abatch\u53ea\u9884\u6d4b\u4e8615\uff05\u7684token\uff0c\u8fd9\u8868\u660e\u6a21\u578b\u53ef\u80fd\u9700\u8981\u66f4\u591a\u7684\u9884\u8bad\u7ec3\u6b65\u9aa4\u624d\u80fd\u6536\u655b\u3002\u56e2\u961f\u8bc1\u660eMLM\u7684\u6536\u655b\u901f\u5ea6\u7565\u6162\u4e8e left-to-right\u7684\u6a21\u578b\uff08\u9884\u6d4b\u6bcf\u4e2atoken\uff09\uff0c\u4f46MLM\u6a21\u578b\u5728\u5b9e\u9a8c\u4e0a\u83b7\u5f97\u7684\u63d0\u5347\u8fdc\u8fdc\u8d85\u8fc7\u589e\u52a0\u7684\u8bad\u7ec3\u6210\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Transformer\u6a21\u578b\u662f\u76ee\u524d\u673a\u5668\u7ffb\u8bd1\u7b49NLP\u95ee\u9898\u6700\u597d\u7684\u89e3\u51b3\u529e\u6cd5\uff0c\u6bd4RNN\u6709\u5927\u5e45\u63d0\u9ad8\u3002Bidirection &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/08\/10\/bert-pre-training-of-deep-bidirectional-transformers-for-language-understanding\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">BERT-Pre-training of Deep Bidirectional Transformers for Language Understanding<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5693"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=5693"}],"version-history":[{"count":14,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5693\/revisions"}],"predecessor-version":[{"id":5715,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5693\/revisions\/5715"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=5693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=5693"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=5693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}