{"id":464967,"date":"2025-06-28T15:00:30","date_gmt":"2025-06-28T15:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464967"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464967","title":{"rendered":"<span>\u0427\u0430\u0441\u0442\u044c 2: Vision Transformer (ViT) \u2014 \u041a\u043e\u0433\u0434\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0432\u0438\u0434\u0435\u0442\u044c<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h4>\u041e\u0431\u043e \u043c\u043d\u0435<\/h4>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u0422\u0435\u0445\u0438\u043d, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 6 \u043b\u0435\u0442 \u044f \u0436\u0438\u0432\u0443 \u0432 \u043c\u0438\u0440\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u2014 \u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439 \u0434\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 VLm.<br \/> \u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b, \u043c\u043d\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432, \u0433\u0434\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b\u0438\u0441\u044c \u0431\u044b <em>\u0431\u0435\u0437<\/em> \u0444\u043e\u0440\u043c\u0443\u043b \u043d\u0430 \u0442\u0440\u0435\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e PhD \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435. \u042f \u0432\u0435\u0440\u0438\u043b (\u0438 \u0432\u0435\u0440\u044e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440), \u0447\u0442\u043e \u043b\u044e\u0431\u0443\u044e \u0438\u0434\u0435\u044e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043a\u0438\u0440\u043f\u0438\u0447\u0438\u043a\u0438 \u2014 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0443 \u0432\u0430\u0441 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u0430\u0441\u044c <em>\u0446\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/em>, \u0430 \u043d\u0435 \u0440\u043e\u0441\u0441\u044b\u043f\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432.  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0430\u043b \u044d\u0442\u0443 \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u0446\u0435\u043b\u044c\u044e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c &#171;\u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445&#187;, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0441\u044b\u0433\u0440\u0430\u0432\u0448\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/921608\/\" rel=\"noopener noreferrer nofollow\"><strong>\u0427\u0430\u0441\u0442\u044c 1: ResNet-18 \u2014 \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u043f\u043e\u043a\u043e\u0440\u0438\u0432\u0448\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0443<\/strong><\/a><\/p>\n<h3>\u041f\u0440\u043e\u043b\u043e\u0433: \u0420\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u043c \u0437\u0440\u0435\u043d\u0438\u0438<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0441\u0442\u0430\u043b \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u043c \u043f\u043e \u0436\u0438\u0432\u043e\u043f\u0438\u0441\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 2020 \u0433\u043e\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u2014 \u043d\u0430\u0443\u0447\u0438\u043b\u0430\u0441\u044c &#171;\u0432\u0438\u0434\u0435\u0442\u044c&#187; \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/arxiv.org\/abs\/2010.11929\" rel=\"noopener noreferrer nofollow\">An Image is Worth 16&#215;16 Words<\/a>). <strong>Vision Transformer (ViT)<\/strong> \u0434\u043e\u043a\u0430\u0437\u0430\u043b: \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0441\u0432\u0451\u0440\u0442\u043a\u0438!<\/p>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f<\/strong>: \u0420\u0430\u0437\u0440\u0435\u0436\u044c\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u0443\u0441\u043e\u0447\u043a\u0438-\u043f\u0430\u0442\u0447\u0438, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0439\u0442\u0435 \u0438\u0445 \u043a\u0430\u043a \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u2014 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440. \u0413\u0435\u043d\u0438\u0430\u043b\u044c\u043d\u043e? \u0414\u0430! \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e? \u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<hr\/>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/cec\/997\/f7a\/cec997f7a9787d74c696f00e0f530091.png\" alt=\"Vit \u0438\u0437 \u043e\u0440\u0438\u043d\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/cec\/997\/f7a\/cec997f7a9787d74c696f00e0f530091.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/cec\/997\/f7a\/cec997f7a9787d74c696f00e0f530091.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>Vit \u0438\u0437 \u043e\u0440\u0438\u043d\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/figcaption><\/div>\n<\/figure>\n<h4>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/h4>\n<p><em>\u041a\u0430\u043a ViT \u0438\u0437 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435?<\/em><br \/> \u0412\u043e\u0437\u044c\u043c\u0451\u043c \u0437\u0430\u0434\u0430\u0447\u0443: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c &#171;\u0447\u0435\u043b\u043e\u0432\u0435\u043a&#187; (\u043a\u043b\u0430\u0441\u0441 0) \u0438\u043b\u0438 &#171;\u043c\u0430\u0448\u0438\u043d\u0430&#187; (\u043a\u043b\u0430\u0441\u0441 1) \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 4\u00d74 \u043f\u0438\u043a\u0441\u0435\u043b\u044f.<br \/> \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043a\u0440\u043e\u0448\u0435\u0447\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 4\u00d74, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e Resnet:<\/p>\n<h3>1. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0442\u0447\u0438: &#171;\u041f\u0430\u0437\u043b \u0438\u0437 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439&#187;<\/h3>\n<pre><code class=\"python\">\u041a\u0430\u043d\u0430\u043b R:      \u041a\u0430\u043d\u0430\u043b G:      \u041a\u0430\u043d\u0430\u043b B: [[2, 4, 1, 3]  [[2, 4, 1, 3]  [[2, 4, 1, 3]  [0, 5, 8, 2]   [0, 5, 8, 2]   [0, 5, 8, 2]  [4, 2, 7, 1]   [4, 2, 7, 1]   [4, 2, 7, 1]  [3, 6, 0, 4]]  [3, 6, 0, 4]]  [3, 6, 0, 4]] <\/code><\/pre>\n<p>\u0420\u0430\u0437\u0440\u0435\u0436\u0435\u043c \u043d\u0430 4 \u043f\u0430\u0442\u0447\u0430 2\u00d72:<\/p>\n<pre><code>\u041f\u0430\u0442\u0447 1 (\u0432\u0435\u0440\u0445-\u043b\u0435\u0432\u043e): R[[2,4],[0,5]] G[[2,4],[0,5]] B[[2,4],[0,5]] \u2192 \u0412\u0435\u043a\u0442\u043e\u0440 [2,4,0,5,2,4,0,5,2,4,0,5] \u041f\u0430\u0442\u0447 2 (\u0432\u0435\u0440\u0445-\u043f\u0440\u0430\u0432\u043e): R[[1,3],[8,2]] G[[1,3],[8,2]] B[[1,3],[8,2]] \u2192 [1,3,8,2,1,3,8,2,1,3,8,2] \u041f\u0430\u0442\u0447 3 (\u043d\u0438\u0437-\u043b\u0435\u0432\u043e): R[[4,2],[3,6]] G[[4,2],[3,6]] B[[4,2],[3,6]] \u2192 [4,2,3,6,4,2,3,6,4,2,3,6] \u041f\u0430\u0442\u0447 4 (\u043d\u0438\u0437-\u043f\u0440\u0430\u0432\u043e): R[[7,1],[0,4]] G[[7,1],[0,4]] B[[7,1],[0,4]] \u2192 [7,1,0,4,7,1,0,4,7,1,0,4] <\/code><\/pre>\n<p><em>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f<\/em>: \u041a\u0430\u043a \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441\u043c\u044b\u0441\u043b, \u0442\u0430\u043a \u043f\u0430\u0442\u0447\u0438 \u043d\u0435\u0441\u0443\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u041f\u0430\u0442\u0447 1 = \u043d\u0435\u0431\u043e, \u041f\u0430\u0442\u0447 4 = \u043a\u043e\u043b\u0435\u0441\u043e.<\/p>\n<h3>2. \u041b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435: &#171;\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043d\u0430 \u044f\u0437\u044b\u043a \u043c\u043e\u0434\u0435\u043b\u0438&#187;<\/h3>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 12-\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0430\u0442\u0447\u0430 \u0441\u0436\u0438\u043c\u0430\u0435\u043c \u0434\u043e 4-\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"python\"># \u0412\u0435\u0441\u0430 W (12\u00d74): W = [[0.1, 0.2, -0.3, 0.4],      [0.5, -0.6, 0.7, 0.8],      ...       [0.9, -1.0, 0.2, 0.3]]  # \u0414\u043b\u044f \u041f\u0430\u0442\u0447\u0430 1: z1 = [2*0.1 + 4*0.5 + 0*0.2 + ... + 5*0.9] = [3.8, -2.1, 1.4, 0.7] <\/code><\/pre>\n<p><em>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/em>: \u041a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u044f\u0437\u044b\u043a\u0430\u043c\u0438, \u0442\u0430\u043a <code>W<\/code> \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0432 &#171;\u044f\u0437\u044b\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430&#187;.<\/p>\n<h3>3. \u041f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438: &#171;\u0413\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0430\u0442\u0447&#187;<\/h3>\n<p>\u0411\u0435\u0437 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0442 \u043d\u0435\u0431\u043e (\u0432\u0435\u0440\u0445) \u043e\u0442 \u043a\u043e\u043b\u0435\u0441\u0430 (\u043d\u0438\u0437). <strong>2 \u043f\u043e\u0434\u0445\u043e\u0434\u0430<\/strong>:<\/p>\n<p><strong>\ud83d\udd22 \u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/strong> (\u043a\u0430\u043a \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u0445):<\/p>\n<pre><code class=\"python\"># \u0424\u043e\u0440\u043c\u0443\u043b\u0430: PE(pos, 2i)   = sin(pos \/ 10000^(2i\/d_model)) PE(pos, 2i+1) = cos(pos \/ 10000^(2i\/d_model))  # \u0414\u043b\u044f \u041f\u0430\u0442\u0447\u0430 1 (pos=0) \u043f\u0440\u0438 d_model=4: z1 = [3.8, -2.1, 1.4, 0.7] + [sin(0), cos(0), sin(0), cos(0)]      = [3.8 + 0, -2.1 + 1, 1.4 + 0, 0.7 + 1]      = [3.8, -1.1, 1.4, 1.7] <\/code><\/pre>\n<p><em>\u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0438\u043d\u0443\u0441\u044b\/\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u044b?<\/em> \u041e\u043d\u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432\u043e\u043b\u043d\u0430\u043c\u0438 \u0440\u0430\u0437\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 &#171;\u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435&#187; \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p><strong>\ud83c\udf93 \u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/strong> (\u043a\u0430\u043a \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c ViT):<\/p>\n<pre><code class=\"python\">pos_embeddings = nn.Parameter(torch.randn(4, 4))  # 4 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u00d7 4 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 z1 = [3.8, -2.1, 1.4, 0.7] + [0.1, 0.3, -0.2, 0.5] = [3.9, -1.8, 1.2, 1.2] <\/code><\/pre>\n<p><strong>\u041f\u043b\u044e\u0441\u044b\/\u043c\u0438\u043d\u0443\u0441\u044b<\/strong>:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0422\u0438\u043f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0434\u043b\u0438\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041c\u0435\u043d\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0443\u0447\u0448\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0431\u0443\u044e\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/em>:<\/p>\n<ul>\n<li>\n<p><strong>ALBERT<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>DeBERTa<\/strong>: \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Swin Transformer<\/strong>: \u0412\u0432\u043e\u0434\u0438\u0442 &#171;\u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u044b\u0435 \u043e\u043a\u043d\u0430&#187; \u0434\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0443\u0447\u0451\u0442\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>4. [\u041a\u041b\u0410\u0421\u0421]-\u0442\u043e\u043a\u0435\u043d: &#171;\u0423\u0447\u0438\u043c\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0430\u0442\u044c&#187;<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u043f\u0430\u0442\u0447\u0430\u0445:<\/p>\n<pre><code class=\"python\">z0 = [0.9, -0.3, 1.1, 0.4]  # \u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440! \u0412\u0445\u043e\u0434 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430: [z0, z1, z2, z3, z4]  # z0 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 <\/code><\/pre>\n<p><em>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f<\/em>: \u042d\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d \u2014 \u043a\u0430\u043a \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440 \u043d\u0430 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u0438: \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u0434\u043e\u043a\u043b\u0430\u0434\u044b \u043e\u0442\u0434\u0435\u043b\u043e\u0432 (\u043f\u0430\u0442\u0447\u0435\u0439) \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443.<\/p>\n<hr\/>\n<h4>\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0439 \u0431\u043b\u043e\u043a: &#171;\u041c\u043e\u0437\u0433 ViT&#187;<\/h4>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/921\/bd7\/dbe\/921bd7dbebaa4d5f82e7cc383358436c.png\" alt=\"\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/921\/bd7\/dbe\/921bd7dbebaa4d5f82e7cc383358436c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/921\/bd7\/dbe\/921bd7dbebaa4d5f82e7cc383358436c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b<\/figcaption><\/div>\n<\/figure>\n<h3>\u0428\u0430\u0433 1: Self-Attention \u2014 &#171;\u041f\u043e\u0438\u0441\u043a \u0441\u0432\u044f\u0437\u0435\u0439&#187;<\/h3>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p><strong>Query (Q)<\/strong>: &#171;\u0412\u043e\u043f\u0440\u043e\u0441&#187; \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 (&#171;\u0427\u0442\u043e \u0432\u043e\u043a\u0440\u0443\u0433 \u043c\u0435\u043d\u044f?&#187;)<\/p>\n<\/li>\n<li>\n<p><strong>Key (K)<\/strong>: &#171;\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435&#187; \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (&#171;\u042f \u2014 \u043d\u0435\u0431\u043e&#187;)<\/p>\n<\/li>\n<li>\n<p><strong>Value (V)<\/strong>: \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f z1 (\u043d\u0435\u0431\u043e)<\/strong>:<\/p>\n<pre><code class=\"python\"># 1. \u0421\u043e\u0437\u0434\u0430\u0451\u043c Q, K, V \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432: Q_z1 = z1 * W_Q = [3.9*0.4, -1.8*(-0.1), ...] = [1.56, 0.18, ...] K_z3 = z3 * W_K = [0.2, -1.1, 0.5, 0.7]  # \u0414\u043b\u044f z3 (\u0434\u0435\u0440\u0435\u0432\u043e)  # 2. \u0421\u0447\u0438\u0442\u0430\u0435\u043c \"\u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\" \u043c\u0435\u0436\u0434\u0443 z1 \u0438 z3: score = Q_z1 \u2022 K_z3 \/ sqrt(4) = (1.56*0.2 + 0.18*(-1.1) + ...) \/ 2 = 0.85  # 3. \u0412\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 Values: attention_z1 = 0.85*V_z3 + 0.1*V_z0 + ...  # V_z3 = [0.4, 0.1, -0.2, 0.3] <\/code><\/pre>\n<p><em>\u0418\u0442\u043e\u0433<\/em>: \u041f\u0430\u0442\u0447 &#171;\u043d\u0435\u0431\u043e&#187; (z1) \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 &#171;\u0434\u0435\u0440\u0435\u0432\u043e\u043c&#187; (z3), \u0441\u043b\u0430\u0431\u0435\u0435 \u2014 \u0441 &#171;\u043a\u043e\u043b\u0435\u0441\u043e\u043c&#187; (z4).<\/p>\n<h3>\u0428\u0430\u0433 2: Multi-Head Attention \u2014 &#171;\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432&#187;<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e &#171;\u0432\u0437\u0433\u043b\u044f\u0434\u0430&#187; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 attention-\u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f 2 heads: head1 = attention(Q1, K1, V1)  # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0446\u0432\u0435\u0442\u0430\u0445 head2 = attention(Q2, K2, V2)  # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0430\u0445 combined = concat(head1, head2) * W_out  # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <\/code><\/pre>\n<p><em>\u0417\u0430\u0447\u0435\u043c?<\/em> \u0422\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u0428\u0430\u0433 3: MLP \u2014 &#171;\u0423\u0433\u043b\u0443\u0431\u043b\u044f\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435&#187;<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 &#171;\u043c\u0438\u043d\u0438-\u043c\u043e\u0437\u0433&#187;:<\/p>\n<pre><code class=\"python\">h1 = [1.2, -0.3, 0.8, 1.1] \u2192  GeLU(h1 * W1 + b1) \u2192   # W1: \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c 4\u21928 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0435\u0439 h1 * W2 + b2 \u2192          # W2: \u0441\u0436\u0438\u043c\u0430\u0435\u043c 8\u21924 \u2192 [0.9, -0.2, 1.4, 0.3] <\/code><\/pre>\n<p><em>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/em>: \u041a\u0430\u043a \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u044f: \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0448\u0443\u043c.<\/p>\n<hr\/>\n<h4>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435: \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 12 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 [\u041a\u041b\u0410\u0421\u0421]-\u0442\u043e\u043a\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0436\u0430\u0442\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">z0_final = [0.2, 1.8, -0.4, 0.9]  # \u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0441\u043b\u043e\u0451\u0432  # \u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440: \u0412\u0435\u0441\u0430_\u043a\u043b\u0430\u0441\u0441\u04300 = [1.1, 0.3, -0.7, 0.5]   \u0412\u0435\u0441\u0430_\u043a\u043b\u0430\u0441\u0441\u04301 = [0.4, -0.9, 0.2, 1.3]    \u041b\u043e\u0433\u0438\u0442\u044b = [   0.2*1.1 + 1.8*0.3 + (-0.4)*(-0.7) + 0.9*0.5 = 1.43,  # \"\u043c\u0430\u0448\u0438\u043d\u0430\"    0.2*0.4 + 1.8*(-0.9) + (-0.4)*0.2 + 0.9*1.3 = -0.25   # \"\u0447\u0435\u043b\u043e\u0432\u0435\u043a\" ]  Softmax: [e\u00b9.\u2074\u00b3, e\u207b\u2070.\u00b2\u2075] \/ \u0441\u0443\u043c\u043c\u0430 = [0.84, 0.16] \u2192 84% \"\u043c\u0430\u0448\u0438\u043d\u0430\" <\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>:<br \/> <code>\u041f\u0438\u043a\u0441\u0435\u043b\u0438 \u2192 \u041f\u0430\u0442\u0447\u0438 \u2192 \u042d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u2192 12\u00d7[Attention+MLP] \u2192 [CLS]-\u0442\u043e\u043a\u0435\u043d \u2192 \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/code><\/p>\n<hr\/>\n<h4>ViT \u0432 \u043a\u043e\u0434\u0435: \u0413\u043b\u0430\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/h4>\n<h3>1. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0442\u0447\u0438<\/h3>\n<pre><code class=\"python\">class PatchEmbed(nn.Module):     def __init__(self, img_size=224, patch_size=16, embed_dim=768):         super().__init__()         self.proj = nn.Conv2d(3, embed_dim, kernel_size=patch_size, stride=patch_size)      def forward(self, x):         # (B, 3, 224, 224) \u2192 (B, 768, 14, 14) \u2192 (B, 196, 768)          x = self.proj(x).flatten(2).transpose(1, 2)           return x <\/code><\/pre>\n<h3>2. \u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 + [CLS]<\/h3>\n<pre><code class=\"python\">class ViT(nn.Module):     def __init__(self, num_patches, embed_dim):         super().__init__()         # [CLS]-\u0442\u043e\u043a\u0435\u043d         self.cls_token = nn.Parameter(torch.randn(1, 1, embed_dim))                  # \u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438         position = torch.arange(0, num_patches+1).unsqueeze(1)         div_term = torch.exp(torch.arange(0, embed_dim, 2) * (-math.log(10000.0) \/ embed_dim))         pe = torch.zeros(num_patches+1, embed_dim)         pe[:, 0::2] = torch.sin(position * div_term)         pe[:, 1::2] = torch.cos(position * div_term)         self.register_buffer('pe', pe.unsqueeze(0))  # (1, num_patches+1, embed_dim)      def forward(self, x):         # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c [CLS]-\u0442\u043e\u043a\u0435\u043d         cls_tokens = self.cls_token.expand(x.shape[0], -1, -1)         x = torch.cat([cls_tokens, x], dim=1)  # (B, num_patches+1, embed_dim)                  # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438         x = x + self.pe         return x <\/code><\/pre>\n<h3>3. \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0439 \u0431\u043b\u043e\u043a<\/h3>\n<pre><code class=\"python\">class TransformerBlock(nn.Module):     def __init__(self, dim, num_heads=4):         super().__init__()         # Multi-head Attention         self.norm1 = nn.LayerNorm(dim)         self.attn = nn.MultiheadAttention(dim, num_heads)                  # MLP         self.norm2 = nn.LayerNorm(dim)         self.mlp = nn.Sequential(             nn.Linear(dim, 4*dim),               nn.GELU(),             nn.Linear(4*dim, dim)         )      def forward(self, x):         # 1. Self-Attention + skip-connection         residual = x         x = self.norm1(x)         attn_out, _ = self.attn(x, x, x)           x = residual + attn_out                  # 2. MLP + skip-connection         residual = x         x = self.norm2(x)         x = residual + self.mlp(x)           return x <\/code><\/pre>\n<hr\/>\n<h4>\u041a\u0430\u043a ViT \u0443\u0447\u0438\u0442\u0441\u044f?<\/h4>\n<p><strong>4 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u0430<\/strong>:<\/p>\n<ol>\n<li>\n<p><strong>\u041f\u0440\u044f\u043c\u043e\u0439 \u043f\u0440\u043e\u0445\u043e\u0434<\/strong>:<\/p>\n<ul>\n<li>\n<p>5 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (4 \u043f\u0430\u0442\u0447\u0430 + [CLS]) \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 12 \u0431\u043b\u043e\u043a\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435: Attention \u2192 MLP \u2192 LayerNorm<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e [CLS]-\u0442\u043e\u043a\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043b\u043e\u044f \u2192 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0438 \u043c\u0435\u0442\u043a\u043e\u0439:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">loss = -log(0.84)  # \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043a\u0430 \"\u043c\u0430\u0448\u0438\u043d\u0430\" <\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442: <\/p>\n<ul>\n<li>\n<p>\u0412\u0435\u0441\u0430 \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0442\u0447\u0435\u0439 (<code>W<\/code> \u0438\u0437 \u0448\u0430\u0433\u0430 2)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b Q\/K\/V \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0441\u0430 MLP<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 (\u0435\u0441\u043b\u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr\/>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 ViT \u2014 \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 ResNet?<\/h4>\n<h3>\u2705 \u0421\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b ViT:<\/h3>\n<ol>\n<li>\n<p><strong>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/strong>: \u0412\u0438\u0434\u0438\u0442 \u0432\u0441\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441\u0440\u0430\u0437\u0443 (\u0441\u0432\u0451\u0440\u0442\u043a\u0438 \u0432\u0438\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c<\/strong>: \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e (JFT-300M: 89.3% accuracy).<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>: \u041e\u0434\u043d\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u0430\u0443\u0434\u0438\u043e \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<h3>\u274c \u0421\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b ViT:<\/h3>\n<ol>\n<li>\n<p><strong>\u0414\u0430\u043d\u043d\u044b\u0435<\/strong>: \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 10-100 \u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0447\u0435\u043c ResNet.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u043d\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/strong>: \u041f\u043b\u043e\u0445\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0432\u0451\u0440\u0442\u043e\u043a).<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong>: \u041a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u043b\u0430 \u043f\u0430\u0442\u0447\u0435\u0439.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c<\/strong>:<\/p>\n<ul>\n<li>\n<p>\ud83e\udd16 <strong>ViT<\/strong>: \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 &gt;1 \u043c\u043b\u043d \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u043d\u0443\u0436\u043d\u0430 state-of-the-art \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\ud83d\ude80 <strong>ResNet<\/strong>: \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u043b\u043e (&lt;100K) \u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c (\u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h4>\u0424\u0438\u043b\u043e\u0441\u043e\u0444\u0441\u043a\u0438\u0439 \u0438\u0442\u043e\u0433<\/h4>\n<p>ViT \u043d\u0435 &#171;\u0443\u0431\u0438\u043b&#187; \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u2014 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e <strong>\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041d\u043e \u043a\u0430\u043a \u0438 \u0432 \u0436\u0438\u0437\u043d\u0438, \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435\u0442: ResNet \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0447\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0430 ViT \u2014 \u043c\u043e\u0449\u043d\u044b\u043c, \u043d\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0440\u044b\u0432\u043e\u043c.<\/p>\n<p><strong>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438<\/strong>: <em>&#171;\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u043e\u0442\u043e\u043c \u2014 \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c. DiT \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u043a \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e.&#187;<\/em><\/p>\n<p><strong>P.S.<\/strong> \u041e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435? \u0425\u043e\u0442\u0438\u0442\u0435 \u0433\u043b\u0443\u0431\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c attention? \u041f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/p>\n<hr\/>\n<h4>\u041f\u0440\u043e\u0432\u0435\u0440\u044c \u0441\u0435\u0431\u044f<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0430\u0442\u0447 4\u00d74 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440?<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0447\u0435\u043c ViT [CLS]-\u0442\u043e\u043a\u0435\u043d, \u0435\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0442\u0447\u0438?<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/922868\/\"> https:\/\/habr.com\/ru\/articles\/922868\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h4>\u041e\u0431\u043e \u043c\u043d\u0435<\/h4>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u0422\u0435\u0445\u0438\u043d, \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 6 \u043b\u0435\u0442 \u044f \u0436\u0438\u0432\u0443 \u0432 \u043c\u0438\u0440\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u2014 \u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439 \u0434\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 VLm.<br \/> \u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b, \u043c\u043d\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432, \u0433\u0434\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b\u0438\u0441\u044c \u0431\u044b <em>\u0431\u0435\u0437<\/em> \u0444\u043e\u0440\u043c\u0443\u043b \u043d\u0430 \u0442\u0440\u0435\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e PhD \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435. \u042f \u0432\u0435\u0440\u0438\u043b (\u0438 \u0432\u0435\u0440\u044e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440), \u0447\u0442\u043e \u043b\u044e\u0431\u0443\u044e \u0438\u0434\u0435\u044e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043a\u0438\u0440\u043f\u0438\u0447\u0438\u043a\u0438 \u2014 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0443 \u0432\u0430\u0441 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u0430\u0441\u044c <em>\u0446\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/em>, \u0430 \u043d\u0435 \u0440\u043e\u0441\u0441\u044b\u043f\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432.  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0430\u043b \u044d\u0442\u0443 \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u0446\u0435\u043b\u044c\u044e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c &#171;\u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445&#187;, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0441\u044b\u0433\u0440\u0430\u0432\u0448\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/articles\/921608\/\" rel=\"noopener noreferrer nofollow\"><strong>\u0427\u0430\u0441\u0442\u044c 1: ResNet-18 \u2014 \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u043f\u043e\u043a\u043e\u0440\u0438\u0432\u0448\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0443<\/strong><\/a><\/p>\n<h3>\u041f\u0440\u043e\u043b\u043e\u0433: \u0420\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u043c \u0437\u0440\u0435\u043d\u0438\u0438<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0441\u0442\u0430\u043b \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u043c \u043f\u043e \u0436\u0438\u0432\u043e\u043f\u0438\u0441\u0438. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 2020 \u0433\u043e\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u2014 \u043d\u0430\u0443\u0447\u0438\u043b\u0430\u0441\u044c &#171;\u0432\u0438\u0434\u0435\u0442\u044c&#187; \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/arxiv.org\/abs\/2010.11929\" rel=\"noopener noreferrer nofollow\">An Image is Worth 16&#215;16 Words<\/a>). <strong>Vision Transformer (ViT)<\/strong> \u0434\u043e\u043a\u0430\u0437\u0430\u043b: \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0441\u0432\u0451\u0440\u0442\u043a\u0438!<\/p>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f<\/strong>: \u0420\u0430\u0437\u0440\u0435\u0436\u044c\u0442\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u0443\u0441\u043e\u0447\u043a\u0438-\u043f\u0430\u0442\u0447\u0438, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0439\u0442\u0435 \u0438\u0445 \u043a\u0430\u043a \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u2014 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440. \u0413\u0435\u043d\u0438\u0430\u043b\u044c\u043d\u043e? \u0414\u0430! \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e? \u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<hr\/>\n<figure class=\"\">\n<div><figcaption>Vit \u0438\u0437 \u043e\u0440\u0438\u043d\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/figcaption><\/div>\n<\/figure>\n<h4>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/h4>\n<p><em>\u041a\u0430\u043a ViT \u0438\u0437 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435?<\/em><br \/> \u0412\u043e\u0437\u044c\u043c\u0451\u043c \u0437\u0430\u0434\u0430\u0447\u0443: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c &#171;\u0447\u0435\u043b\u043e\u0432\u0435\u043a&#187; (\u043a\u043b\u0430\u0441\u0441 0) \u0438\u043b\u0438 &#171;\u043c\u0430\u0448\u0438\u043d\u0430&#187; (\u043a\u043b\u0430\u0441\u0441 1) \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 4\u00d74 \u043f\u0438\u043a\u0441\u0435\u043b\u044f.<br \/> \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043a\u0440\u043e\u0448\u0435\u0447\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 4\u00d74, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e Resnet:<\/p>\n<h3>1. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0442\u0447\u0438: &#171;\u041f\u0430\u0437\u043b \u0438\u0437 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439&#187;<\/h3>\n<pre><code class=\"python\">\u041a\u0430\u043d\u0430\u043b R:      \u041a\u0430\u043d\u0430\u043b G:      \u041a\u0430\u043d\u0430\u043b B: [[2, 4, 1, 3]  [[2, 4, 1, 3]  [[2, 4, 1, 3]  [0, 5, 8, 2]   [0, 5, 8, 2]   [0, 5, 8, 2]  [4, 2, 7, 1]   [4, 2, 7, 1]   [4, 2, 7, 1]  [3, 6, 0, 4]]  [3, 6, 0, 4]]  [3, 6, 0, 4]] <\/code><\/pre>\n<p>\u0420\u0430\u0437\u0440\u0435\u0436\u0435\u043c \u043d\u0430 4 \u043f\u0430\u0442\u0447\u0430 2\u00d72:<\/p>\n<pre><code>\u041f\u0430\u0442\u0447 1 (\u0432\u0435\u0440\u0445-\u043b\u0435\u0432\u043e): R[[2,4],[0,5]] G[[2,4],[0,5]] B[[2,4],[0,5]] \u2192 \u0412\u0435\u043a\u0442\u043e\u0440 [2,4,0,5,2,4,0,5,2,4,0,5] \u041f\u0430\u0442\u0447 2 (\u0432\u0435\u0440\u0445-\u043f\u0440\u0430\u0432\u043e): R[[1,3],[8,2]] G[[1,3],[8,2]] B[[1,3],[8,2]] \u2192 [1,3,8,2,1,3,8,2,1,3,8,2] \u041f\u0430\u0442\u0447 3 (\u043d\u0438\u0437-\u043b\u0435\u0432\u043e): R[[4,2],[3,6]] G[[4,2],[3,6]] B[[4,2],[3,6]] \u2192 [4,2,3,6,4,2,3,6,4,2,3,6] \u041f\u0430\u0442\u0447 4 (\u043d\u0438\u0437-\u043f\u0440\u0430\u0432\u043e): R[[7,1],[0,4]] G[[7,1],[0,4]] B[[7,1],[0,4]] \u2192 [7,1,0,4,7,1,0,4,7,1,0,4] <\/code><\/pre>\n<p><em>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f<\/em>: \u041a\u0430\u043a \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441\u043c\u044b\u0441\u043b, \u0442\u0430\u043a \u043f\u0430\u0442\u0447\u0438 \u043d\u0435\u0441\u0443\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u041f\u0430\u0442\u0447 1 = \u043d\u0435\u0431\u043e, \u041f\u0430\u0442\u0447 4 = \u043a\u043e\u043b\u0435\u0441\u043e.<\/p>\n<h3>2. \u041b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435: &#171;\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043d\u0430 \u044f\u0437\u044b\u043a \u043c\u043e\u0434\u0435\u043b\u0438&#187;<\/h3>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 12-\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0430\u0442\u0447\u0430 \u0441\u0436\u0438\u043c\u0430\u0435\u043c \u0434\u043e 4-\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"python\"># \u0412\u0435\u0441\u0430 W (12\u00d74): W = [[0.1, 0.2, -0.3, 0.4],      [0.5, -0.6, 0.7, 0.8],      ...       [0.9, -1.0, 0.2, 0.3]]  # \u0414\u043b\u044f \u041f\u0430\u0442\u0447\u0430 1: z1 = [2*0.1 + 4*0.5 + 0*0.2 + ... + 5*0.9] = [3.8, -2.1, 1.4, 0.7] <\/code><\/pre>\n<p><em>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/em>: \u041a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u044f\u0437\u044b\u043a\u0430\u043c\u0438, \u0442\u0430\u043a <code>W<\/code> \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0432 &#171;\u044f\u0437\u044b\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430&#187;.<\/p>\n<h3>3. \u041f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438: &#171;\u0413\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0430\u0442\u0447&#187;<\/h3>\n<p>\u0411\u0435\u0437 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0442 \u043d\u0435\u0431\u043e (\u0432\u0435\u0440\u0445) \u043e\u0442 \u043a\u043e\u043b\u0435\u0441\u0430 (\u043d\u0438\u0437). <strong>2 \u043f\u043e\u0434\u0445\u043e\u0434\u0430<\/strong>:<\/p>\n<p><strong>\ud83d\udd22 \u0424\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/strong> (\u043a\u0430\u043a \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u0445):<\/p>\n<pre><code class=\"python\"># \u0424\u043e\u0440\u043c\u0443\u043b\u0430: PE(pos, 2i)   = sin(pos \/ 10000^(2i\/d_model)) PE(pos, 2i+1) = cos(pos \/ 10000^(2i\/d_model))  # \u0414\u043b\u044f \u041f\u0430\u0442\u0447\u0430 1 (pos=0) \u043f\u0440\u0438 d_model=4: z1 = [3.8, -2.1, 1.4, 0.7] + [sin(0), cos(0), sin(0), cos(0)]      = [3.8 + 0, -2.1 + 1, 1.4 + 0, 0.7 + 1]      = [3.8, -1.1, 1.4, 1.7] <\/code><\/pre>\n<p><em>\u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0438\u043d\u0443\u0441\u044b\/\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u044b?<\/em> \u041e\u043d\u0438 \u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432\u043e\u043b\u043d\u0430\u043c\u0438 \u0440\u0430\u0437\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 &#171;\u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435&#187; \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p><strong>\ud83c\udf93 \u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/strong> (\u043a\u0430\u043a \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c ViT):<\/p>\n<pre><code class=\"python\">pos_embeddings = nn.Parameter(torch.randn(4, 4))  # 4 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u00d7 4 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 z1 = [3.8, -2.1, 1.4, 0.7] + [0.1, 0.3, -0.2, 0.5] = [3.9, -1.8, 1.2, 1.2] <\/code><\/pre>\n<p><strong>\u041f\u043b\u044e\u0441\u044b\/\u043c\u0438\u043d\u0443\u0441\u044b<\/strong>:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0422\u0438\u043f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0434\u043b\u0438\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041c\u0435\u043d\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041b\u0443\u0447\u0448\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0440\u0435\u0431\u0443\u044e\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/em>:<\/p>\n<ul>\n<li>\n<p><strong>ALBERT<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>DeBERTa<\/strong>: \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Swin Transformer<\/strong>: \u0412\u0432\u043e\u0434\u0438\u0442 &#171;\u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c\u044b\u0435 \u043e\u043a\u043d\u0430&#187; \u0434\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0443\u0447\u0451\u0442\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>4. [\u041a\u041b\u0410\u0421\u0421]-\u0442\u043e\u043a\u0435\u043d: &#171;\u0423\u0447\u0438\u043c\u0441\u044f \u043e\u0431\u043e\u0431\u0449\u0430\u0442\u044c&#187;<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u043f\u0430\u0442\u0447\u0430\u0445:<\/p>\n<pre><code class=\"python\">z0 = [0.9, -0.3, 1.1, 0.4]  # \u041e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440! \u0412\u0445\u043e\u0434 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430: [z0, z1, z2, z3, z4]  # z0 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 <\/code><\/pre>\n<p><em>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f<\/em>: \u042d\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d \u2014 \u043a\u0430\u043a \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440 \u043d\u0430 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u0438: \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u0434\u043e\u043a\u043b\u0430\u0434\u044b \u043e\u0442\u0434\u0435\u043b\u043e\u0432 (\u043f\u0430\u0442\u0447\u0435\u0439) \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443.<\/p>\n<hr\/>\n<h4>\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0439 \u0431\u043b\u043e\u043a: &#171;\u041c\u043e\u0437\u0433 ViT&#187;<\/h4>\n<figure class=\"\">\n<div><figcaption>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b<\/figcaption><\/div>\n<\/figure>\n<h3>\u0428\u0430\u0433 1: Self-Attention \u2014 &#171;\u041f\u043e\u0438\u0441\u043a \u0441\u0432\u044f\u0437\u0435\u0439&#187;<\/h3>\n<p><strong>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/strong>:<\/p>\n<ul>\n<li>\n<p><strong>Query (Q)<\/strong>: &#171;\u0412\u043e\u043f\u0440\u043e\u0441&#187; \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 (&#171;\u0427\u0442\u043e \u0432\u043e\u043a\u0440\u0443\u0433 \u043c\u0435\u043d\u044f?&#187;)<\/p>\n<\/li>\n<li>\n<p><strong>Key (K)<\/strong>: &#171;\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435&#187; \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (&#171;\u042f \u2014 \u043d\u0435\u0431\u043e&#187;)<\/p>\n<\/li>\n<li>\n<p><strong>Value (V)<\/strong>: \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f z1 (\u043d\u0435\u0431\u043e)<\/strong>:<\/p>\n<pre><code class=\"python\"># 1. \u0421\u043e\u0437\u0434\u0430\u0451\u043c Q, K, V \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432: Q_z1 = z1 * W_Q = [3.9*0.4, -1.8*(-0.1), ...] = [1.56, 0.18, ...] K_z3 = z3 * W_K = [0.2, -1.1, 0.5, 0.7]  # \u0414\u043b\u044f z3 (\u0434\u0435\u0440\u0435\u0432\u043e)  # 2. \u0421\u0447\u0438\u0442\u0430\u0435\u043c \"\u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\" \u043c\u0435\u0436\u0434\u0443 z1 \u0438 z3: score = Q_z1 \u2022 K_z3 \/ sqrt(4) = (1.56*0.2 + 0.18*(-1.1) + ...) \/ 2 = 0.85  # 3. \u0412\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 Values: attention_z1 = 0.85*V_z3 + 0.1*V_z0 + ...  # V_z3 = [0.4, 0.1, -0.2, 0.3] <\/code><\/pre>\n<p><em>\u0418\u0442\u043e\u0433<\/em>: \u041f\u0430\u0442\u0447 &#171;\u043d\u0435\u0431\u043e&#187; (z1) \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 &#171;\u0434\u0435\u0440\u0435\u0432\u043e\u043c&#187; (z3), \u0441\u043b\u0430\u0431\u0435\u0435 \u2014 \u0441 &#171;\u043a\u043e\u043b\u0435\u0441\u043e\u043c&#187; (z4).<\/p>\n<h3>\u0428\u0430\u0433 2: Multi-Head Attention \u2014 &#171;\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432&#187;<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e &#171;\u0432\u0437\u0433\u043b\u044f\u0434\u0430&#187; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 attention-\u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f 2 heads: head1 = attention(Q1, K1, V1)  # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0446\u0432\u0435\u0442\u0430\u0445 head2 = attention(Q2, K2, V2)  # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0430\u0445 combined = concat(head1, head2) * W_out  # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <\/code><\/pre>\n<p><em>\u0417\u0430\u0447\u0435\u043c?<\/em> \u0422\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u0428\u0430\u0433 3: MLP \u2014 &#171;\u0423\u0433\u043b\u0443\u0431\u043b\u044f\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435&#187;<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 &#171;\u043c\u0438\u043d\u0438-\u043c\u043e\u0437\u0433&#187;:<\/p>\n<pre><code class=\"python\">h1 = [1.2, -0.3, 0.8, 1.1] \u2192  GeLU(h1 * W1 + b1) \u2192   # W1: \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c 4\u21928 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0435\u0439 h1 * W2 + b2 \u2192          # W2: \u0441\u0436\u0438\u043c\u0430\u0435\u043c 8\u21924 \u2192 [0.9, -0.2, 1.4, 0.3] <\/code><\/pre>\n<p><em>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/em>: \u041a\u0430\u043a \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0432\u0435\u0449\u0430\u043d\u0438\u044f: \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0448\u0443\u043c.<\/p>\n<hr\/>\n<h4>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435: \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 12 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 [\u041a\u041b\u0410\u0421\u0421]-\u0442\u043e\u043a\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0436\u0430\u0442\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">z0_final = [0.2, 1.8, -0.4, 0.9]  # \u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0441\u043b\u043e\u0451\u0432  # \u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440: \u0412\u0435\u0441\u0430_\u043a\u043b\u0430\u0441\u0441\u04300 = [1.1, 0.3, -0.7, 0.5]   \u0412\u0435\u0441\u0430_\u043a\u043b\u0430\u0441\u0441\u04301 = [0.4, -0.9, 0.2, 1.3]    \u041b\u043e\u0433\u0438\u0442\u044b = [   0.2*1.1 + 1.8*0.3 + (-0.4)*(-0.7) + 0.9*0.5 = 1.43,  # \"\u043c\u0430\u0448\u0438\u043d\u0430\"    0.2*0.4 + 1.8*(-0.9) + (-0.4)*0.2 + 0.9*1.3 = -0.25   # \"\u0447\u0435\u043b\u043e\u0432\u0435\u043a\" ]  Softmax: [e\u00b9.\u2074\u00b3, e\u207b\u2070.\u00b2\u2075] \/ \u0441\u0443\u043c\u043c\u0430 = [0.84, 0.16] \u2192 84% \"\u043c\u0430\u0448\u0438\u043d\u0430\" <\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>:<br \/> <code>\u041f\u0438\u043a\u0441\u0435\u043b\u0438 \u2192 \u041f\u0430\u0442\u0447\u0438 \u2192 \u042d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u2192 12\u00d7[Attention+MLP] \u2192 [CLS]-\u0442\u043e\u043a\u0435\u043d \u2192 \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/code><\/p>\n<hr\/>\n<h4>ViT \u0432 \u043a\u043e\u0434\u0435: \u0413\u043b\u0430\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/h4>\n<h3>1. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0442\u0447\u0438<\/h3>\n<pre><code class=\"python\">class PatchEmbed(nn.Module):     def __init__(self, img_size=224, patch_size=16, embed_dim=768):         super().__init__()         self.proj = nn.Conv2d(3, embed_dim, kernel_size=patch_size, stride=patch_size)      def forward(self, x):         # (B, 3, 224, 224) \u2192 (B, 768, 14, 14) \u2192 (B, 196, 768)          x = self.proj(x).flatten(2).transpose(1, 2)           return x <\/code><\/pre>\n<h3>2. \u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 + [CLS]<\/h3>\n<pre><code class=\"python\">class ViT(nn.Module):     def __init__(self, num_patches, embed_dim):         super().__init__()         # [CLS]-\u0442\u043e\u043a\u0435\u043d         self.cls_token = nn.Parameter(torch.randn(1, 1, embed_dim))                  # \u0421\u0438\u043d\u0443\u0441\u043e\u0438\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438         position = torch.arange(0, num_patches+1).unsqueeze(1)         div_term = torch.exp(torch.arange(0, embed_dim, 2) * (-math.log(10000.0) \/ embed_dim))         pe = torch.zeros(num_patches+1, embed_dim)         pe[:, 0::2] = torch.sin(position * div_term)         pe[:, 1::2] = torch.cos(position * div_term)         self.register_buffer('pe', pe.unsqueeze(0))  # (1, num_patches+1, embed_dim)      def forward(self, x):         # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c [CLS]-\u0442\u043e\u043a\u0435\u043d         cls_tokens = self.cls_token.expand(x.shape[0], -1, -1)         x = torch.cat([cls_tokens, x], dim=1)  # (B, num_patches+1, embed_dim)                  # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438         x = x + self.pe         return x <\/code><\/pre>\n<h3>3. \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u043d\u044b\u0439 \u0431\u043b\u043e\u043a<\/h3>\n<pre><code class=\"python\">class TransformerBlock(nn.Module):     def __init__(self, dim, num_heads=4):         super().__init__()         # Multi-head Attention         self.norm1 = nn.LayerNorm(dim)         self.attn = nn.MultiheadAttention(dim, num_heads)                  # MLP         self.norm2 = nn.LayerNorm(dim)         self.mlp = nn.Sequential(             nn.Linear(dim, 4*dim),               nn.GELU(),             nn.Linear(4*dim, dim)         )      def forward(self, x):         # 1. Self-Attention + skip-connection         residual = x         x = self.norm1(x)         attn_out, _ = self.attn(x, x, x)           x = residual + attn_out                  # 2. MLP + skip-connection         residual = x         x = self.norm2(x)         x = residual + self.mlp(x)           return x <\/code><\/pre>\n<hr\/>\n<h4>\u041a\u0430\u043a ViT \u0443\u0447\u0438\u0442\u0441\u044f?<\/h4>\n<p><strong>4 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u0430<\/strong>:<\/p>\n<ol>\n<li>\n<p><strong>\u041f\u0440\u044f\u043c\u043e\u0439 \u043f\u0440\u043e\u0445\u043e\u0434<\/strong>:<\/p>\n<ul>\n<li>\n<p>5 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (4 \u043f\u0430\u0442\u0447\u0430 + [CLS]) \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 12 \u0431\u043b\u043e\u043a\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435: Attention \u2192 MLP \u2192 LayerNorm<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e [CLS]-\u0442\u043e\u043a\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043b\u043e\u044f \u2192 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0438 \u043c\u0435\u0442\u043a\u043e\u0439:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">loss = -log(0.84)  # \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043a\u0430 \"\u043c\u0430\u0448\u0438\u043d\u0430\" <\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442: <\/p>\n<ul>\n<li>\n<p>\u0412\u0435\u0441\u0430 \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0442\u0447\u0435\u0439 (<code>W<\/code> \u0438\u0437 \u0448\u0430\u0433\u0430 2)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b Q\/K\/V \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0441\u0430 MLP<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 (\u0435\u0441\u043b\u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr\/>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 ViT \u2014 \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 ResNet?<\/h4>\n<h3>\u2705 \u0421\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b ViT:<\/h3>\n<ol>\n<li>\n<p><strong>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/strong>: \u0412\u0438\u0434\u0438\u0442 \u0432\u0441\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0441\u0440\u0430\u0437\u0443 (\u0441\u0432\u0451\u0440\u0442\u043a\u0438 \u0432\u0438\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c<\/strong>: \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e (JFT-300M: 89.3% accuracy).<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u043d\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>: \u041e\u0434\u043d\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u0430\u0443\u0434\u0438\u043e \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<h3>\u274c \u0421\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b ViT:<\/h3>\n<ol>\n<li>\n<p><strong>\u0414\u0430\u043d\u043d\u044b\u0435<\/strong>: \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 10-100 \u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0447\u0435\u043c ResNet.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u043d\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/strong>: \u041f\u043b\u043e\u0445\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0432\u0451\u0440\u0442\u043e\u043a).<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/strong>: \u041a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0441\u043b\u0430 \u043f\u0430\u0442\u0447\u0435\u0439.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c<\/strong>:<\/p>\n<ul>\n<li>\n<p>\ud83e\udd16 <strong>ViT<\/strong>: \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 &gt;1 \u043c\u043b\u043d \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u043d\u0443\u0436\u043d\u0430 state-of-the-art \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\ud83d\ude80 <strong>ResNet<\/strong>: \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u043b\u043e (&lt;100K) \u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c (\u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h4>\u0424\u0438\u043b\u043e\u0441\u043e\u0444\u0441\u043a\u0438\u0439 \u0438\u0442\u043e\u0433<\/h4>\n<p>ViT \u043d\u0435 &#171;\u0443\u0431\u0438\u043b&#187; \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u2014 \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e <strong>\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041d\u043e \u043a\u0430\u043a \u0438 \u0432 \u0436\u0438\u0437\u043d\u0438, \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-464967","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464967"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464967\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}