{"id":21391,"date":"2024-10-09T14:23:00","date_gmt":"2024-10-09T06:23:00","guid":{"rendered":"http:\/\/139.9.1.231\/?p=21391"},"modified":"2024-10-09T14:23:01","modified_gmt":"2024-10-09T06:23:01","slug":"bert-512","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2024\/10\/09\/bert-512\/","title":{"rendered":"\u4e3a\u4ec0\u4e48BERT\u8f93\u5165\u7684\u6700\u5927\u957f\u5ea6\u8981\u9650\u5236\u4e3a512\uff1f"},"content":{"rendered":"\n<p>\u6765\u81ea <a href=\"https:\/\/www.zhihu.com\/question\/395903256\/answer\/2194033303\" target=\"_blank\" rel=\"noreferrer noopener\">\u77e5\u4e4e<\/a><\/p>\n\n\n\n<p>\u603b\u7684\u6765\u8bf4\u662f\u4e3a\u4e86\u8ba1\u7b97\u6548\u7387\uff0c\u6240\u4ee5\u628a\u957f\u5ea6\u9650\u5236\u5728\u4e86512\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>To speed up pretraing in our experiments, we pre-train the model with sequence length of 128 for 90% of the steps. Then, we train the rest 10% of the steps of sequence of 512 to learn the positional embeddings.<\/p><\/blockquote>\n\n\n\n<p>\u5f53\u7136\uff0c<strong>\u6700\u6700\u672c\u8d28\u7684\u539f\u56e0\u8fd8\u662f\u5728\u4e8eBERT\u4e2d\u7684Positional Embedding\u548cTransformer\u4e2d\u7684Positional Embedding\u5b9e\u73b0\u65b9\u5f0f\u4e0d\u4e00\u6837\uff0c\u540e\u8005\u662f\u901a\u8fc7\u516c\u5f0f\u8ba1\u7b97\u5f97\u5230\u7684\uff0c\u800c\u524d\u8005\u672c\u8d28\u4e0a\u5219\u662f\u4e00\u4e2a\u53ef\u5b66\u4e60\u7684\u53c2\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\u6bcf\u4e2a\u4f4d\u7f6e\u6240\u5bf9\u5e94\u7684\u5411\u91cf\u5c31\u7c7b\u4f3c\u4e8eToken Embedding\u4e2d\u6bcf\u4e2a\u8bcd\u5bf9\u5e94\u7684\u8bcd\u5411\u91cf\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class PositionalEmbedding(nn.Module):\n    \"\"\"\n    \u4f4d\u7f6e\u7f16\u7801\u3002\n      *** \u6ce8\u610f\uff1a Bert\u4e2d\u7684\u4f4d\u7f6e\u7f16\u7801\u5b8c\u5168\u4e0d\u540c\u4e8eTransformer\u4e2d\u7684\u4f4d\u7f6e\u7f16\u7801\uff0c\n                \u524d\u8005\u672c\u8d28\u4e0a\u4e5f\u662f\u4e00\u4e2a\u666e\u901a\u7684Embedding\u5c42\uff0c\u800c\u540e\u8005\u662f\u901a\u8fc7\u516c\u5f0f\u8ba1\u7b97\u5f97\u5230\uff0c\n                \u800c\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48Bert\u53ea\u80fd\u63a5\u53d7\u957f\u5ea6\u4e3a512\u5b57\u7b26\u7684\u539f\u56e0\uff0c\u56e0\u4e3a\u4f4d\u7f6e\u7f16\u7801\u7684\u6700\u5927size\u4e3a512 ***\n      # Since the position embedding table is a learned variable, we create it\n      # using a (long) sequence length `max_position_embeddings`. The actual\n      # sequence length might be shorter than this, for faster training of\n      # tasks that do not have long sequences.\n                                                 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014  GoogleResearch\n    https:&#47;&#47;github.com\/google-research\/bert\/blob\/eedf5716ce1268e56f0a50264a88cafad334ac61\/modeling.py\n    \"\"\"\n\n    def __init__(self, hidden_size, max_position_embeddings=512, initializer_range=0.02):\n        super(PositionalEmbedding, self).__init__()\n        self.embedding = nn.Embedding(max_position_embeddings, hidden_size)\n        self._reset_parameters(initializer_range)<\/code><\/pre>\n\n\n\n<p>\u56e0\u6b64\uff0c\u9664\u975e\u662f\u4f60\u81ea\u5df1\u4ece\u96f6\u5f00\u59cb\u8bad\u7ec3\u4e00\u4e2a\u6a21\u578b\uff0c\u5426\u5219\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f\u8c37\u6b4c\u5f00\u6e90\u7684\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u90a3\u4e48\u8fd9\u4e2a\u8bcd\u8868\u7684\u5927\u5c0f\u5c06\u4f1a\u88ab\u9650\u5236\u5728512\u3002 \u5f53\u7136\uff0c\u4f60\u4f9d\u65e7\u53ef\u4ee5\u7a81\u7834\u8fd9\u4e2a\u9650\u5236\uff0c\u90a3\u5c31\u662f\u81ea\u5df1\u5728\u4ece\u65b0\u521d\u59cb\u5316Positional Embedding\u4e2d\u7684\u5411\u91cf\uff0c\u7136\u540e\u5bf9\u524d512\u4e2a\u8fdb\u884c\u66ff\u6362\uff0c\u540e\u9762\u7684\u5c31\u81ea\u5df1\u5728\u5bf9\u4e8e\u8bed\u6599\u4e0a\u8bad\u7ec3\u5fae\u8c03\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u81ea \u77e5\u4e4e \u603b\u7684\u6765\u8bf4\u662f\u4e3a\u4e86\u8ba1\u7b97\u6548\u7387\uff0c\u6240\u4ee5\u628a\u957f\u5ea6\u9650\u5236\u5728\u4e86512\u3002 To speed up pretraing i &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2024\/10\/09\/bert-512\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u4e3a\u4ec0\u4e48BERT\u8f93\u5165\u7684\u6700\u5927\u957f\u5ea6\u8981\u9650\u5236\u4e3a512\uff1f<\/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,4],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/21391"}],"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=21391"}],"version-history":[{"count":5,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/21391\/revisions"}],"predecessor-version":[{"id":21396,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/21391\/revisions\/21396"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=21391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=21391"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=21391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}