{"id":325157,"date":"2021-06-19T03:00:15","date_gmt":"2021-06-19T03:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325157"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325157","title":{"rendered":"Log-Sum-Exp Trick: \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u0435\u043b\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8u\/4d\/il\/8u4dilzspyikx2_zknhocukvczq.png\"><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439. \u0417\u0430\u0442\u0435\u043c, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0432\u0448\u0438\u0441\u044c \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u0442\u043e\u043f\u0438\u043a\u0443 \u043f\u043e\u0441\u0442\u0430 \u2014 \u043a Log-Sum-Exp Trick. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h4>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"http:\/\/www.machinelearning.ru\/wiki\/index.php?title=%D0%9B%D0%BE%D0%B3%D0%B8%D1%81%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D1%80%D0%B5%D0%B3%D1%80%D0%B5%D1%81%D1%81%D0%B8%D1%8F\">\u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/a>. \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438\u0437\u0432\u0430\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.9, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c: 90% \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u0438\u0441\u044c\u043c\u043e \u0441\u043f\u0430\u043c, \u0438 10% \u2014 \u043d\u0435 \u0441\u043f\u0430\u043c. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0443\u043c\u043c\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0430\u0451\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f \u0432\u044b\u0434\u0430\u0451\u0442 \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 <a href=\"http:\/\/www.machinelearning.ru\/wiki\/index.php?title=%D0%9B%D0%BE%D0%B3%D0%B8%D1%81%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F\">\u0441\u0438\u0433\u043c\u043e\u0438\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a>. <\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430? \u041a\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0445\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0442\u0440\u0430\u043a\u0442\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438?<\/p>\n<h4>\u041c\u0443\u043b\u044c\u0442\u0438\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438<\/h4>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430, \u0432\u044b\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c. \u0422\u0430\u043a\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Softmax\">\u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441<\/a>.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1fa\/9ef\/df8\/1fa9efdf8c7cff4f9aebb54952d497ad.svg\" alt=\"\\frac{e^{x_i}}{\\sum_{j=0}^N{e^{x_j}}} = p_i, \\, i \\in [0, N].\"><\/div>\n<p>  <\/p>\n<p>\u0412 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0432\u044b\u0448\u0435 <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/609\/017\/513\/6090175136e6d5539dd886ab80eff715.svg\" alt=\"x_j\"> \u2014 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/79a\/716\/f07\/79a716f07e784255f21b6cc85f4b7cf7.svg\" alt=\"p_i\"> \u2014 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<blockquote><p>\u0421\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 \u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0432\u0443\u0445.<\/p><\/blockquote>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b3f\/218\/db6\/b3f218db65f5d201bdb0dc0e56259d45.svg\" alt=\"image\"><br \/>  \u0442\u0430\u043a \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441\u0430 \u043a \u0432\u044b\u0445\u043e\u0434\u0430\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438,<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b6f\/34c\/ce6\/b6f34cce617d7127cab6296a980d6990.png\" alt=\"image\"><br \/>  \u0430 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u043e\u043d\u0438 \u0432 \u0441\u0443\u043c\u043c\u0435 \u0434\u0430\u044e\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 (<a href=\"https:\/\/developers.google.com\/machine-learning\/crash-course\/multi-class-neural-networks\/softmax\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a>).<\/p>\n<h4>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 Softmax<\/h4>\n<p>  \u041b\u043e\u0433\u0438\u0442\u044b, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0438\u0437 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 \u0432 Python \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u0434\u043b\u044f \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\">import numpy as np x = np.array([-100, 1000, -100, 5, 10, 0.001]) exp_x = np.exp(x) print(&quot;\u0412\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0435\u043f\u0435\u043d\u044c X: &quot;, &quot;\\n&quot;, exp_x) print(&quot;\u0421\u0443\u043c\u043c\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442: &quot;, &quot;\\n&quot;, np.sum(exp_x)) print(&quot;\u0422\u0440\u0435\u0442\u044c\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c: &quot;, np.exp(x[3]) \/ np.sum(exp_x)) <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"plaintext\">\u0412\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u0435\u043f\u0435\u043d\u044c X:    [3.72007598e-44            inf 3.72007598e-44 1.48413159e+02  2.20264658e+04 1.00100050e+00] \u0421\u0443\u043c\u043c\u0430 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442:  inf \u0422\u0440\u0435\u0442\u044c\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c:  0.0 <\/code><\/pre>\n<p>  \u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 1000 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0438 \u044d\u0442\u043e \u0433\u0443\u0431\u0438\u0442 \u0432\u0441\u044e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0443\u044e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. <\/p>\n<h4>Log-Sum-Exp<\/h4>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/523\/17d\/d7c\/52317dd7c9ee59b06b4a6aaf182ce03c.svg\" alt=\"LSE(X) = \\log\\left(\\sum_{j=0}^N e^{x_j}\\right)\"> \u2014 Log-Sum-Exp \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>  \u0415\u0451 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a \u0432\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0443: \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0434\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430 \u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0414\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u2014 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u044d\u043a\u0441\u0442\u0440\u0435\u043c\u0443\u043c\u043e\u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f93\/b1b\/6dc\/f93b1b6dce6bf5a783e2698e771ee22b.jpg\" alt=\"image\"> (<a href=\"https:\/\/nhigham.com\/2021\/01\/05\/what-is-the-log-sum-exp-function\/\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a>)<br \/>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435, lse(x) \u0432\u0441\u044e\u0434\u0443 \u0433\u043b\u0430\u0434\u043a\u0430\u044f, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 max(x) \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 Log-Sum-Exp \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e LSE \u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 x, \u0442\u043e \u043c\u044b \u0442\u0430\u043a \u0436\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u043c\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0441\u0443\u043c\u043c\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0439, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0441\u0442\u0435\u043f\u0435\u043d\u0438. \u041f\u0443\u0442\u0451\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/155\/f80\/9f4\/155f809f438c4e2b05635acacb834bad.svg\" alt=\"LSE(x)\"> \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/51c\/7a6\/45c\/51c7a645c78a35a4875b3cf546812547.svg\" alt=\"y\">, \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9dd\/ff3\/a41\/9ddff3a418894d140dd6d7bb71cdbd6c.svg\" alt=\"y = LSE(x) = \\log{\\sum_{j=0}^N{e^{x_j}}}.\"><\/div>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u043a \u043e\u0431\u043e\u0438\u043c \u0447\u0430\u0441\u0442\u044f \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ded\/a9a\/5f8\/deda9a5f8c30a11d6bc13ee8ec768a42.svg\" alt=\"e^y = \\sum_{j=0}^N{e^{x_j}}.\"><\/div>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0442\u0440\u044e\u043a\u0430. \u041f\u0443\u0441\u0442\u044c <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1de\/36a\/303\/1de36a3039c908fcfa506f2beeb3d612.svg\" alt=\"c = \\max_{j}(x_j),\"> \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d3e\/38e\/8f7\/d3e38e8f7e92dfb892761f110a1c700f.svg\" alt=\"e^c\">:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/12a\/ef1\/0e7\/12aef10e71ed4a6ee16ebf38e9e9e9c4.svg\" alt=\"e^y = e^c \\sum_{j=0}^N{e^{x_j- c}}, \\, \\, | \\,\\, \\log(\\cdot)\"><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bb4\/1a3\/c71\/bb41a3c71ee42ce3636d7418c96b6398.svg\" alt=\"y = c + \\log\\left(\\sum_{j=0}^N{e^{x_j- c}} \\right) = LSE(x).\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u043e\u0432\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443:<\/p>\n<pre><code class=\"python\">import numpy as np  x = np.array([11, 12, -1000, 5, 10, 0.001]) y = np.array([-1000, 1000, -1000, 5, 10, 0.001])  def LSE_initial(x):   return np.log(np.sum(np.exp(x)))  def LSE_modified(x):   c = np.max(x)   return c + np.log(np.sum(np.exp(x - c)))  # \u0441 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u043a \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e print('\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f LSE(x): ', LSE_initial(x))  print('\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f LSE(x): ', LSE_modified(x))  # \u0441 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0439 \u0432 1000\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 print('\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f LSE(y): ', LSE_initial(y)) print('\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f LSE(y): ', LSE_modified(y))<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434: <\/p>\n<pre><code class=\"plaintext\">\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f LSE(x):  12.408216490736713 \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f LSE(x):  12.408216490736713 \u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f LSE(y):  inf \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f LSE(y):  1000.0<\/code><\/pre>\n<p>  \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 float inf, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 lse(x) \u0434\u0430\u0451\u0442 \u0432\u0435\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<h4>Log-Sum-Exp Trick<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0442\u0440\u044e\u043a\u0443. \u041d\u0430\u0448\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u0434\u043b\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u0437-\u0437\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u043a \u0432\u0438\u0434\u0443, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0435\u043c\u0443 \u043e\u0442 <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d5b\/168\/6c2\/d5b1686c2716b141c4c1695907c7491e.svg\" alt=\"LSE\">.<\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/79a\/716\/f07\/79a716f07e784255f21b6cc85f4b7cf7.svg\" alt=\"p_i\"> \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441 \u0440\u0430\u0432\u043d\u043e <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c0d\/19f\/f35\/c0d19ff352c83e25f4688082b3f861ed.svg\" alt=\"1\">, \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4aa\/449\/b6c\/4aa449b6cc69ea63d6340b5dc1730376.svg\" alt=\"\\frac{e^{x_i}}{\\sum_{j=0}^N{e^{x_j}}} = 1.\"><\/div>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0440\u044f\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/7c2\/bf3\/42c\/7c2bf342c23df36f21af40711bb9da6d.svg\" alt=\"\\frac{e^{x_i}}{\\sum_{j=0}^N{e^{x_j}}} = 1, \\,\\, | \\,\\, * \\sum_{j=0}^N{e^{x_j}}\"><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/85d\/022\/b4f\/85d022b4f84e6dfbe7a3ab0ba2570efa.svg\" alt=\"e^{x_i} = \\sum_{j=0}^N{e^{x_j}}, \\,\\, | \\,\\, \\log(\\cdot)\"><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/672\/52c\/416\/67252c41610cc73561b80d6640535b69.svg\" alt=\"0 = x_i - \\log{\\sum_{j=0}^N{e^{x_j}}}, \\,\\, | \\,\\, \\exp(\\cdot)\"><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a41\/57d\/8ca\/a4157d8cabf13ced3c016687a3f6755a.svg\" alt=\"1 = \\exp\\left( x_i - \\log{\\sum_{j=0}^N{e^{x_j}}} \\right).\"><\/div>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/793\/d5d\/d4d\/793d5dd4d177a0efc226d0109829d7ff.svg\" alt=\"\\frac{e^{x_i}}{\\sum_{j=0}^N{e^{x_j}}} = \\exp\\left( x_i - LSE(x) \\right).\"><\/div>\n<p>  \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441\u0430:<\/p>\n<pre><code class=\"python\">import numpy as np  x = np.array([11, 12, -1000, 5, 10, 0.001]) y = np.array([-1000, 1000, -1000, 5, 10, 0.001])  def softmax_initial(x):   return np.exp(x) \/ np.sum(np.exp(x))  def LSE(x):   c = np.max(x)   return c + np.log(np.sum(np.exp(x - c)))  def softmax_modified(x):   return np.exp(x - LSE(x))   # \u0441 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u043a \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e print('\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 Softmax(x): ', softmax_initial(x))  print('\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Softmax(x): ', softmax_modified(x)) print('\u0421\u0443\u043c\u043c\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439: {} {}\\n'.format(np.sum(softmax_initial(x)), np.sum(softmax_modified(x))))  # \u0441 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0439 \u0432 1000\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 print('\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 Softmax(y): ', softmax_initial(y)) print('\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Softmax(y): ', softmax_modified(y)) print('\u0421\u0443\u043c\u043c\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439: {} {}'.format(np.sum(softmax_initial(y)), np.sum(softmax_modified(y))))<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"plaintext\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 Softmax(x):  [2.44579103e-01 6.64834933e-01 0.00000000e+00 6.06250985e-04  8.99756239e-02 4.08897394e-06] \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Softmax(x):  [2.44579103e-01 6.64834933e-01 0.00000000e+00 6.06250985e-04  8.99756239e-02 4.08897394e-06] \u0421\u0443\u043c\u043c\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439: 0.9999999999999999 1.0000000000000004  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 Softmax(y):  [ 0. nan  0.  0.  0.  0.] \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Softmax(y):  [0. 1. 0. 0. 0. 0.] \u0421\u0443\u043c\u043c\u044b \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439: nan 1.0<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c lse(x), \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441\u0430 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0435\u0435, \u0438 \u043d\u0435 \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u043e\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438. \u0421\u0443\u043c\u043c\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441, \u0434\u0430\u0451\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0422\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438. \u041e\u0431\u0441\u0443\u0434\u0438\u043b\u0438 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438. \u0418 \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u043a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443, \u0443 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438.<\/p>\n<blockquote><p>\u0421\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/AfWs\/\">\u00ab\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0434\u043b\u044f Data Science\u00bb<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0441\u0435\u043c \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0433\u043e \u0434\u0435\u043c\u043e\u0443\u0440\u043e\u043a\u0430 \u043f\u0440\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>   \u2014 <a href=\"https:\/\/otus.pw\/AfWs\/\">\u0421\u041c\u041e\u0422\u0420\u0415\u0422\u042c \u0414\u0415\u041c\u041e\u0423\u0420\u041e\u041a<\/a><\/p><\/blockquote>\n<\/div>\n<p> \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\/company\/otus\/blog\/562918\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/562918\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8u\/4d\/il\/8u4dilzspyikx2_zknhocukvczq.png\"><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439. \u0417\u0430\u0442\u0435\u043c, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0432\u0448\u0438\u0441\u044c \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u0442\u043e\u043f\u0438\u043a\u0443 \u043f\u043e\u0441\u0442\u0430 \u2014 \u043a Log-Sum-Exp Trick. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u0442\u0440\u044e\u043a \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439.  <\/p>\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-325157","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325157","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=325157"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325157\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}