{"id":367560,"date":"2024-05-21T03:23:31","date_gmt":"2024-05-21T03:23:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=367560"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T03:23:31","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=367560","title":{"rendered":"<span>\u041a\u0430\u043a \u044f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d (\u0447\u0430\u0441\u0442\u044c 1)<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fd2\/c1a\/0c6\/fd2c1a0c6fe0ccce6d2dec3bda6670d9.png\" width=\"854\" height=\"480\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd2\/c1a\/0c6\/fd2c1a0c6fe0ccce6d2dec3bda6670d9.png\"\/><\/figure>\n<p>\u042f \u043e\u0431\u0443\u0447\u0438\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u043f\u043e\u0440\u044f\u0434\u043a\u0430 10 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432) <a href=\"https:\/\/en.wikipedia.org\/wiki\/Transformer_%28machine_learning_model%29\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440<\/u><\/a> \u043f\u043e \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0443 <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>Let\u2019s build GPT: from scratch, in code, spelled out<\/u><\/a> <a href=\"https:\/\/karpathy.ai\/\" rel=\"noopener noreferrer nofollow\"><u>\u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0438 \u0438 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0412 <a href=\"https:\/\/arxiv.org\/abs\/1706.03762\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043d\u0430\u0443\u0447\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>, \u043a\u0430\u043a \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430\u0445 \u043f\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u043c \u0443\u043f\u043e\u0440 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/machinelearningmastery.com\/the-transformer-attention-mechanism\/\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u043c \u0441\u0430\u043c\u043e\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0438<\/u><\/a>, \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044f\u043c \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0441\u0432\u0451\u0440\u0442\u043a\u0443. \u041d\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u043b\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u044f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <em>\u043f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/em>: <strong>\u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430?<\/strong><\/p>\n<p>\u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043c\u043e\u0433\u0443 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440, \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0445. \u0422\u043e, \u0447\u0442\u043e \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u043e\u0432\u044b\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c, \u043d\u043e \u0434\u0430\u043b\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0430\u044f, \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b, \u0438 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0437\u043d\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0442\u043e \u043e\u043d \u0442\u0430\u043a\u043e\u0432: \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 (\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u043b\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e) \u0438\u0437\u0443\u0447\u0430\u0435\u0442 \u0432\u0435\u0441\u0430, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0442 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0441\u0442\u0440\u043e\u043a, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435. <strong>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u044d\u0442\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0431\u043b\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430.<\/strong> \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u043c\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0441\u0442\u0440\u043e\u043a \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430\u043c. \u041e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<\/p>\n<p>\u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u043e, \u0447\u0442\u043e, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440. \u041e\u043d \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430, \u043e \u0447\u0451\u043c \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043d\u0438\u0436\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u044e \u0432\u0430\u0441 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u043d\u043e\u0439 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0432 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0432 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0435\u0439 \u0442\u0435\u043e\u0440\u0438\u0438. \u042f \u0441\u0442\u0440\u0435\u043c\u0438\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u0436\u0430\u0442\u044b\u043c, \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430\u0445 <a href=\"https:\/\/shyam.blog\/posts\/beyond-self-attention\/%28https:\/github.com\/spather\/transformer-experiments%29\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/u><\/a>.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u2014 \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043a\u0441\u043a\u0443\u0440\u0441 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u042f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u043e\u0448\u0438\u0431\u043a\u0438 \u0438\u043b\u0438 \u0443\u043f\u0443\u0441\u0442\u0438\u043b \u0447\u0442\u043e-\u0442\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041b\u044e\u0431\u044b\u0435 \u043e\u0442\u0437\u044b\u0432\u044b \u043f\u043e \u043c\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 shyam.pather at gmail dot com.<\/p>\n<h3>\u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u00a0<\/h3>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h4>\n<p>\u042f \u0445\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u044f\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0434 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0435 \u043c\u043d\u043e\u0439. \u041e\u043d \u0432\u0437\u044f\u0442 \u0438\u0437 \u0432\u0438\u0434\u0435\u043e <a href=\"https:\/\/karpathy.ai\/\" rel=\"noopener noreferrer nofollow\"><u>\u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438<\/u><\/a> <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>Let\u2019s build GPT: from scratch, in code, spelled out<\/u><\/a> (\u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0435\u0433\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c).<\/p>\n<p>\u042f \u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434, \u043a\u043e\u043f\u0438\u0440\u0443\u044f \u0432\u0441\u0451, \u0447\u0442\u043e \u0432\u0438\u0434\u0435\u043b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0432\u0438\u0434\u0435\u043e. \u0422\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435, \u044f \u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0432 <a href=\"https:\/\/github.com\/karpathy\/ng-video-lecture\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 GitHub \u044d\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e<\/u><\/a> \u0438 \u0432 <a href=\"https:\/\/github.com\/karpathy\/nanoGPT\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 nanoGPT<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043a\u043e\u0434 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u044f \u0432\u043d\u0451\u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043c\u043e\u0433 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439\/\u043a\u043e\u0434\u043e\u043c <a href=\"https:\/\/github.com\/spather\/transformer-experiments\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043e\u0435\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/u><\/a>, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/models\/transformer.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/u><\/a>. \u0418\u0442\u043e\u0433\u043e: \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u044f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438, \u043d\u0435 \u043c\u043e\u044f. \u0410\u043d\u0430\u043b\u0438\u0437 \u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u2014 \u043c\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u0432\u043a\u043b\u0430\u0434. \u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043f\u043e\u0441\u0442\u0430 \u044f \u0431\u0443\u0434\u0443\u0442 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0438 \u0446\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u0441\u0442\u044b, \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<h4>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0<\/h4>\n<p>\u041c\u043e\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e <a href=\"https:\/\/en.wikipedia.org\/wiki\/Transformer_%28machine_learning_model%29\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440<\/u><\/a> \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u043c, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7a0\/a77\/d36\/7a0a77d360cd51a807484d5c6b950cda.png\" width=\"854\" height=\"480\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7a0\/a77\/d36\/7a0a77d360cd51a807484d5c6b950cda.png\"\/><\/figure>\n<p>\u041e\u043d \u043e\u0431\u0443\u0447\u0430\u043b\u0441\u044f \u043d\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 <a href=\"https:\/\/raw.githubusercontent.com\/karpathy\/char-rnn\/master\/data\/tinyshakespeare\/input.txt\" rel=\"noopener noreferrer nofollow\"><u>TinyShakespeare<\/u><\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u043c 40 \u0442\u044b\u0441\u044f\u0447 \u0441\u0442\u0440\u043e\u043a \u043f\u044c\u0435\u0441 \u0428\u0435\u043a\u0441\u043f\u0438\u0440\u0430. \u0421\u043f\u0443\u0441\u0442\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0447\u0430\u0441 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 GPU RTX 4000 \u043e\u043d \u043c\u043e\u0433 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0435\u043a\u0441\u043f\u0438\u0440\u043e\u0432\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043f\u043e \u0435\u0451 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440: \u043d\u0430\u0447\u0430\u0432 \u0441 \u043f\u0440\u043e\u043c\u0442\u0430 ROMEO \u0438 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u0432 500 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438\u0437 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e \u043f\u0440\u043e\u043c\u0442\u0443 ROMEO:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">device = 'cuda' if torch.cuda.is_available() else 'cpu' ts = TinyShakespeareDataSet(cache_file=environment.code_root \/ 'nbs\/artifacts\/input.txt') m, tokenizer = create_model_and_tokenizer(     saved_model_filename=environment.code_root \/ 'nbs\/artifacts\/shakespeare-20231112.pt',     dataset=ts,     device=device, ) encoding_helpers = EncodingHelpers(tokenizer, device) accessors = TransformerAccessors(m, device)  torch.manual_seed(2321) # \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0440\u043e\u0433\u043e\u043d\u0435 prompt = 'ROMEO:' tokens = encoding_helpers.tokenize_string(prompt) print(tokenizer.decode(m.generate(tokens, max_new_tokens=500)[0].tolist()))<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<pre><code>ROMEO: If thou wilt triumphant be virtue, and since from any bold virtue that is made a bawd of earth, then the duke desires of patience and perish: take up the other husband, dislike his tent back.  First Citizen: Ourself goes, go back: you have no consul, but the disguised gods.  Second Citizen: We choose him in the world, he did runk itself.  First Citizen: Sir, I am I a man changed him and thriving, I have heard the king.  CORIOLANUS: Consider him!  AUFIDIUS: Most gracious irice, and you must danc<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043d\u0435 \u0428\u0435\u043a\u0441\u043f\u0438\u0440, \u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e. \u0422\u0435\u043a\u0441\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u044c\u0435\u0441\u044b, \u044f\u0437\u044b\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0430\u0440\u0445\u0430\u0438\u0447\u043d\u044b\u043c, \u0438\u043c\u0435\u043d\u0430\/\u0442\u0438\u0442\u0443\u043b\u044b \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0435\u0439 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u044c\u0435\u0441 \u0428\u0435\u043a\u0441\u043f\u0438\u0440\u0430. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u2014 \u0438\u0437 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e. \u041f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u044f \u0438 \u043a\u0430\u043f\u0438\u0442\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u044b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u0447\u0430\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u0422\u043e\u043a\u0435\u043d\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b<\/strong>, \u0430 \u043d\u0435 \u0441\u043b\u043e\u0432\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442 \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 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442 <code>my most gr<\/code>, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>'a' 0.819 'e' 0.081 'i' 0.059 'o' 0.036 'u' 0.004 'y' 0.001 'w' 0.000 'r' 0.000 'g' 0.000 's' 0.000<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u0440\u043e\u043c\u0442\u0430 my most gr<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">prompt = 'my most gr' tokens = encoding_helpers.tokenize_string(prompt) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) for token, prob in logits.topk_tokens(k=10)[0][-1]:     print(f'{repr(token)} {prob:.3f}')<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 <a href=\"https:\/\/shyam.blog\/posts\/beyond-self-attention\/#i-model-details\" rel=\"noopener noreferrer nofollow\"><u>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 I<\/u><\/a> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e \u043c\u043e\u0434\u0435\u043b\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/models\/transformer.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u043a\u043e\u0434<\/u><\/a> \u0438 <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>\u0432\u0438\u0434\u0435\u043e \u0410\u043d\u0434\u0440\u0435\u044f<\/u><\/a>.<\/p>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u043b\u043e\u043a\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u00a0<\/h4>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0432 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u043e\u0434\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430: \u0441\u043b\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u0441\u043e\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u044f\u043c\u044b\u0445 \u0438 \u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0445 \u0441\u0432\u044f\u0437\u0435\u0439, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/271\/1f5\/0e8\/2711f50e896e47299400bc9392ad4c25.png\" width=\"854\" height=\"480\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/271\/1f5\/0e8\/2711f50e896e47299400bc9392ad4c25.png\"\/><\/figure>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <code>Block<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 PyTorch:<\/p>\n<pre><code class=\"python\">class Block(nn.Module):     \"\"\"One transformer block\"\"\"      def __init__(self, n_embed, n_head):         super().__init__()         head_size = n_embed \/\/ n_head         self.sa = MultiHeadAttention(n_head, head_size)         self.ffwd = FeedForward(n_embed)         self.ln1  = nn.LayerNorm(n_embed)         self.ln2 = nn.LayerNorm(n_embed)       def forward(self, x):         x = x + self.sa(self.ln1(x)) # \u0447\u0430\u0441\u0442\u044c \u0441 `x +` - \u044d\u0442\u043e skip connection         x = x + self.ffwd(self.ln2(x)) # \u0447\u0430\u0441\u0442\u044c \u0441 `x +` - \u044d\u0442\u043e skip connection          return x<\/code><\/pre>\n<p>\u041e \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043c\u043d\u043e\u0433\u043e\u0435, \u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u043e \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043e \u043d\u0435\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8ac\/46c\/882\/8ac46c882d9f63df0d9f44df38f5e3ab.png\" alt=\"\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 https:\/\/stats.stackexchange.com\/q\/485910\" title=\"\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 https:\/\/stats.stackexchange.com\/q\/485910\" width=\"748\" height=\"315\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ac\/46c\/882\/8ac46c882d9f63df0d9f44df38f5e3ab.png\"\/><\/p>\n<div><figcaption>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 <a href=\"https:\/\/stats.stackexchange.com\/q\/485910\" rel=\"noopener noreferrer nofollow\"><em><u>https:\/\/stats.stackexchange.com\/q\/485910<\/u><\/em><\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u042f \u043d\u0430\u0447\u0430\u043b \u0441\u0432\u043e\u0451 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u0438\u0434\u0451\u0442 \u043f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e \u0432 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0438\u0434\u0451\u0442 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e. \u0412 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u0441\u0435\u0445 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 65% \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0433\u0440\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c.<\/p>\n<p>\u041a\u0430\u043a \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u043e\u0437\u0436\u0435, \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0430\u043a\u0442\u043e\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0442\u043e, \u043a\u0430\u043a \u0431\u043b\u043e\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435.<\/p>\n<h3>\u0414\u0435\u043c\u043e: \u043c\u043e\u0451 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438\u00a0<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u044e \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u043c\u0442 <code>And only l<\/code> \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u0440\u043f\u0443\u0441\u0443, \u043d\u0430\u0448\u043b\u0438 \u0432\u0441\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u043e\u0439 \u0436\u0435 \u0434\u043b\u0438\u043d\u044b, \u0447\u0442\u043e \u0438 \u043d\u0430\u0448 \u043f\u0440\u043e\u043c\u0442 (10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432), \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0438\u0445 \u0432\u0441\u0435 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0440\u0430\u0432\u0435\u043d \u0438\u043b\u0438 \u0432\u044b\u0448\u0435 0.95 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u043e\u043c\u0442\u043e\u043c <code>And only l<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code>'hat only l'    's sickly l'    ' as\\nthey l'   'r kingly l'    're; they l' 'eby they l'    'ar, they l'    'im, only l'    'ling any l'    'life may l' 'nobility l'    'e\\nBy any l'   ' as they l'    ', if any l'    ' hastily l' 'tly they l'    ' ghastly l'    '\\nMy only l'   'For many l'    'r in any l' ' till my l'    'all they l'    'hen they l'    'at Henry l'    'oolishly l' 'er:\\nThey l'   'may they l'    'or stony l'    'ur Henry l'    'l gladly l' 'yet they l'    'y;\\nDelay l'   'e, on my l'    'or Henry l'    'I dearly l' ' if they l'    ' she may l'    't\\nfairly l'   'ould say l'    'd all my l' 'her they l'    ' Stanley l'    ' and may l'    'uld they l'    'u all my l' 'friendly l'    'h gently l'    'e deadly l'    'f all my l'    'n all my l' 'Ere they l'    'steel my l'    ' tell my l'    'e kingly l'    'learn my l' 'd he say l'    't basely l'    'Thursday l'    'iciously l'    \" 'if any l\" ' as many l'    'hy glory l'    'not very l'    'a goodly l'    'e surely l' 'quiously l'    ', fairly l'    'lord! my l'    'entle my l'    ', he may l' 'our holy l'    ' worldly l'    ' my only l'    ' all, my l' 'ul, they l'    'o lately l'    's in any l'    ' no lady l' 'ter many l'    'Our holy l'    't vainly l'    'e\\nA lady l' ' you may l'    'y greedy l'    'untimely l'    'directly l' 'er on my l'    'e wistly l'    'ng Henry l'    'And only l' 's kindly l'    'KE:\\nThey l'   ' of many l'    'o, on my l'<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def text_table(     headers: Iterable[str], data_columns: Sequence[Sequence[str]], col_widths: Sequence[int] ):     assert len(headers) == 0 or len(headers) == len(         data_columns     ), \"Must have either zero headers or the same number as data columns\"      assert len(data_columns) == len(col_widths), \"Must have same number of column widths as data columns\"      if len(headers) > 0:         output = \"\".join([f\"{header:{col_widths[i]}}\" for i, header in enumerate(headers)]) + \"\\n\"         header_underlines = [\"-\" * len(header) for header in headers]         output += (             \"\".join(                 [                     f\"{header_underline:{col_widths[i]}}\"                     for i, header_underline in enumerate(header_underlines)                 ]             )             + \"\\n\"         )     else:         output = \"\"      max_len = max([len(col) for col in data_columns])     for i in range(max_len):         items = [             data_column[i] if i &lt; len(data_column) else \" \"             for data_column in data_columns         ]         output += \"\".join([f\"{item:{col_widths[i]}}\" for i, item in enumerate(items)]) + \"\\n\"      return output<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a (\u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0451\u043d \u043f\u043e\u0437\u0436\u0435)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 strings10 = all_unique_substrings(text=ts.text, substring_length=10)  # \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 prefiltered_threshold=0.7 prefiltered_results_folder = environment.data_root \/ 'cosine_sim_results\/large_files\/slen10' \/ f'prefiltered_{prefiltered_threshold}'  def prefiltered_filename(block_idx: int, q_idx: int) -> Path:     return prefiltered_results_folder \/ f'cosine_sim_ffwd_out_{q_idx:05d}_{block_idx:02d}.pt'  def load_prefiltered_data(block_idx: int, q_idx: int):     return torch.load(prefiltered_filename(block_idx, q_idx))  block_idx = 0 similarity_threshold=0.95 q_idx = 57 # \u0418\u043d\u0434\u0435\u043a\u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f `And only l` similar_indices = filter_on_prefiltered_results(     load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),     q_idx_start=q_idx,     q_idx_end=q_idx+1,     filter_fn=lambda values: values > similarity_threshold ) similar_strings = [     [strings10[i] for i in indices]     for indices in similar_indices ]  data_columns=[     [repr(s) for s in similar_strings[0][i : i + 20]] for i in range(0, len(similar_strings[0]), 20) ]  print(text_table(     headers=[],     data_columns=data_columns,     col_widths=[16 for _ in data_columns] ))<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0438\u0434\u0435\u043d \u0447\u0451\u0442\u043a\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d: \u0432\u0441\u0435 \u043e\u043d\u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <code>y l<\/code> \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <code>ly l<\/code>. \u0421\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u043f\u043e\u0445\u043e\u0436\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u0440\u043f\u0443\u0441\u0443, \u043d\u0430\u0448\u043b\u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445. \u041c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0447\u0442\u043e \u0437\u0430 <code>hat only l<\/code> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>i<\/code> (That only l<strong>i<\/strong>ke a gulf it did remain)<\/p>\n<\/li>\n<li>\n<p>\u0447\u0442\u043e \u0437\u0430 <code>l gladly l<\/code> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 e (I\u2019ll gladly l<strong>e<\/strong>arn)<\/p>\n<\/li>\n<li>\n<p>\u0447\u0442\u043e \u0437\u0430 <code>n all my l<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0442 <code>a<\/code> \u0438 <code>i<\/code> (In all my l<strong>a<\/strong>nds and leases whatsoever \u0438 never saw you before in all my l<strong>i<\/strong>fe)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0434\u0435\u043b\u0430\u0432 \u044d\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u0437 94 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b8e\/4b3\/e2f\/b8e4b3e2f5270dd5ee0a5034d4da1aeb.png\" width=\"981\" height=\"373\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b8e\/4b3\/e2f\/b8e4b3e2f5270dd5ee0a5034d4da1aeb.png\"\/><\/figure>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def plot_prob_distribution_for_tokens(     prob_distribution: torch.Tensor,     title: str = \"\",     ax: Optional[Axes] = None,     figsize=(12, 4), ):     if ax is None:         _, ax = plt.subplots(figsize=figsize)      x_indices = np.arange(tokenizer.vocab_size)     x_labels = [repr(c)[1:-1] for c in tokenizer.chars]      ax.bar(x_indices, prob_distribution)     ax.set_xticks(x_indices, x_labels, rotation=\"vertical\")     ax.set_title(title)     ax.set_ylim(0.0, 1.0)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430 \u0441\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">next_token_map10 = build_next_token_map(     text=ts.text,     prefix_len=10,     vocab_size=tokenizer.vocab_size,     stoi=tokenizer.stoi ) total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum() plot_prob_distribution_for_tokens(prob_distribution, title='Normalized frequency distribution from block 0 similar strings')<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u043e\u043a\u0435\u043d\u044b \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e \u043e\u0441\u0438 X, \u0430 \u0438\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u043f\u043e \u043e\u0441\u0438 Y. \u042d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u2014 \u044d\u0442\u043e <code>i<\/code>, \u0437\u0430 \u043d\u0438\u043c \u0438\u0434\u0451\u0442 <code>o<\/code>, \u043f\u043e\u0442\u043e\u043c <code>a<\/code> \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, <code>e<\/code>.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u043a\u0430\u043a \u043d\u0430 \u0446\u0435\u043b\u043e\u0435 \u0441 \u043f\u0440\u043e\u043c\u0442\u043e\u043c <code>And only l<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f13\/017\/9b9\/f130179b981c205747ce2880cdcdb37a.png\" width=\"981\" height=\"373\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f13\/017\/9b9\/f130179b981c205747ce2880cdcdb37a.png\"\/><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">prompt = 'And only l' tokens = encoding_helpers.tokenize_string(prompt) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) logits.plot_probs(title='Probability distribution from model')<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e \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\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0435!<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0438\u0445 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hellinger_distance\" rel=\"noopener noreferrer nofollow\"><u>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430<\/u><\/a> \u2014 \u044d\u0442\u043e \u043c\u0435\u0440\u0430 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439. \u0415\u0441\u043b\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u0430 <em>P<\/em> \u0438 <em>Q<\/em>, \u0442\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fcd\/5fe\/4fb\/fcd5fe4fbf0e10607f6d90e2291bd9d6.png\" width=\"306\" height=\"78\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fcd\/5fe\/4fb\/fcd5fe4fbf0e10607f6d90e2291bd9d6.png\"\/><\/figure>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def hellinger_distance(     p: torch.Tensor,     q: torch.Tensor, ):     return ((p.sqrt() - q.sqrt())**2).sum(dim=-1).sqrt() \/ math.sqrt(2)<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430, \u0440\u0430\u0432\u043d\u043e\u0435 0, \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0432\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b, \u0430 1 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0443 \u043d\u0438\u0445 \u043d\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0448\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 (\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c, \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0438\u0437 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0441\u043e \u0441\u0445\u043e\u0436\u0438\u043c\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u044e) \u0440\u0430\u0432\u043d\u043e 0.07: \u043e\u043d\u0438 \u043f\u043e\u0447\u0442\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u043c\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u043c, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0434\u043d\u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u043e \u0441\u0445\u043e\u0436\u0435\u0433\u043e \u0441 \u0433\u043e\u0442\u043e\u0432\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 (\u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u0441\u0445\u043e\u0436\u0438\u0435 \u0441 \u043f\u0440\u043e\u043c\u0442\u043e\u043c \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0438\u0445 \u0438\u0445) \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435. \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0438 \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <strong>\u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438\u0437 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 0.17<\/strong>.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u043c\u0430\u043b\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f\u00bb, \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f: \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u044e\u0442 \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e.<\/p>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u043c\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u043d\u0430 \u043f\u0440\u043e\u043c\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0438\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0451 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u044d\u0442\u0430\u043f\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\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.<\/p>\n<\/li>\n<\/ol>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b\u00a0<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b (\u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043c\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430) \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0445\u0443\u043a\u0430\u043c\u0438 PyTorch. \u041d\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430 (\u043f\u043e\u0438\u0441\u043a \u0441\u0442\u0440\u043e\u043a \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e) \u0434\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b \u0432\u0435\u0441\u044c \u0430\u043d\u0430\u043b\u0438\u0437  \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 10 (\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0434\u0438\u043b\u0441\u044f, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435 \u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445, \u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a). \u041e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0440\u043f\u0443\u0441 \u0434\u043b\u0438\u043d\u043e\u0439 1115394\u00a0\u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 858\u00a0923\u00a0\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 10. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441\u00a0\u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e\u00a0\u2014 \u044d\u0442\u043e 384-\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 float32; \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0448\u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (\u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430). \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0448\u0435\u0441\u0442\u0438 384-\u043c\u0435\u0440\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0442\u0430 \u0441 6 * 858923 = 5153538 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0427\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u044d\u0442\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043d\u0443\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0431\u0440\u0430\u043b \u0438\u0437 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430 20000 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u0438\u043d\u043e\u0439 10, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u043d\u0430 \u043d\u043e\u0447\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0434\u043b\u044f 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432, \u0438 \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043b\u0430 \u0434\u043b\u044f 858923 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a \u0434\u043b\u0438\u043d\u043e\u0439 10 \u0438\u0437 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430. \u042f \u0434\u0435\u043b\u0430\u043b \u044d\u0442\u043e \u043f\u0430\u043a\u0435\u0442\u043d\u043e \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u0434\u0438\u0441\u043a.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u0438\u0441\u043a \u0441\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u0432\u0441\u0435\u0445 \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0441 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u043c\u0435\u043b\u0438 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043d\u0438\u0436\u0435 0.7, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u044d\u0442\u0430\u043f \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 >= 0.7. \u042d\u0442\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u043b\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u0434 \u044d\u0442\u0438\u0445 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u043e\u0441\u0442, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/experiments\/cosine-sims.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 <\/u>cosine-sims<\/a>.<\/p>\n<h4>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b\u00a0<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u0434 \u0438 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u043c\u0442\u0443 \u0437\u0430 \u0440\u0430\u0437 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u0412\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u0435\u0433\u043e \u0434\u043e\u00a0\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432, \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0438 \u0438\u0437\u0443\u0447\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0438\u0437\u00a0\u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430 20\u00a0000\u00a0\u0441\u0442\u0440\u043e\u043a \u0434\u043b\u0438\u043d\u043e\u0439 10, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u00a0\u043f\u0440\u043e\u043c\u0442\u044b:<\/p>\n<pre><code class=\"python\"># \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 strings10 = all_unique_substrings(text=ts.text, substring_length=10)  n_prompts = 20000  torch.manual_seed(1337) indices = torch.randperm(len(strings10))[:n_prompts] prompts = [strings10[i.item()] for i in indices]<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b\u00bb, \u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0432\u0441\u0435 \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c, \u0432\u0437\u044f\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043b \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0435 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a \u0434\u043b\u0438\u043d\u043e\u0439 10 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435. \u0410 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0448\u0438\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438, \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 >= 0.7.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u0451 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/experiments\/cosine-sims.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u043e\u0443\u0442\u0431\u0443\u043a <\/u>cosine-sims<\/a> \u0442\u0430\u043a\u0436\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>filter_on_prefiltered_results()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0442\u0430 \u043f\u0443\u0442\u0451\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a. \u041e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0430 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>filter_on_prefiltered_results()<\/code>, \u043d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u0435\u0439, \u043a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<pre><code class=\"python\">prefiltered_threshold=0.7 prefiltered_results_folder = environment.data_root \/ 'cosine_sim_results\/large_files\/slen10' \/ f'prefiltered_{prefiltered_threshold}'  def prefiltered_filename(block_idx: int, q_idx: int) -> Path:     return prefiltered_results_folder \/ f'cosine_sim_ffwd_out_{q_idx:05d}_{block_idx:02d}.pt'  def load_prefiltered_data(block_idx: int, q_idx: int):     return torch.load(prefiltered_filename(block_idx, q_idx))<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>q_idx<\/code> \u0437\u0434\u0435\u0441\u044c \u0438 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430: q_idx \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 query index (\u00ab\u0438\u043d\u0434\u0435\u043a\u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u00bb). \u0417\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0435 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u00ab\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\u00bb \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u2014 \u044d\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u0442\u043e\u0432. \u041c\u0435\u0436\u0434\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0438 \u043f\u0440\u043e\u043c\u0442\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 1:1, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u0434\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u043f\u0440\u043e\u043c\u0442\u043e\u043c <code>And only l<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0440\u0430\u043b\u0438 \u0434\u043b\u044f \u0434\u0435\u043c\u043e. \u041e\u043d \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043c\u0442\u043e\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 57:<\/p>\n<p><code>prompts[57]<\/code><\/p>\n<p>&#8216;And only l&#8217;<\/p>\n<p>\u041c\u044b \u043d\u0430\u0439\u0434\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0438, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0431\u043b\u043e\u043a\u0435 0 \u0438\u043c\u0435\u044e\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 0.95 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u043f\u0440\u043e\u043c\u0442\u0430 \u0432 \u0431\u043b\u043e\u043a\u0435 0.<\/p>\n<pre><code class=\"python\">block_idx = 0 similarity_threshold=0.95 q_idx = 57 similar_indices = filter_on_prefiltered_results(     load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),     q_idx_start=q_idx,     q_idx_end=q_idx+1,     filter_fn=lambda values: values > similarity_threshold ) similar_strings = [     [strings10[i] for i in indices]     for indices in similar_indices ] len(similar_strings[0])<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c 94 \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 \u0434\u0435\u043c\u043e. \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"python\">print(f\"Original string: {repr(prompts[q_idx])}\") print(\"Similar strings: \\n\")  data_columns=[     [repr(s) for s in similar_strings[0][i : i + 20]] for i in range(0, len(similar_strings[0]), 20) ]  print(text_table(     headers=[],     data_columns=data_columns,     col_widths=[18 for _ in data_columns] ))<\/code><\/pre>\n<pre><code>Original string: 'And only l' Similar strings:  'hat only l'      's sickly l'      ' as\\nthey l'     'r kingly l'      're; they l' 'eby they l'      'ar, they l'      'im, only l'      'ling any l'      'life may l' 'nobility l'      'e\\nBy any l'     ' as they l'      ', if any l'      ' hastily l' 'tly they l'      ' ghastly l'      '\\nMy only l'     'For many l'      'r in any l' ' till my l'      'all they l'      'hen they l'      'at Henry l'      'oolishly l' 'er:\\nThey l'     'may they l'      'or stony l'      'ur Henry l'      'l gladly l' 'yet they l'      'y;\\nDelay l'     'e, on my l'      'or Henry l'      'I dearly l' ' if they l'      ' she may l'      't\\nfairly l'     'ould say l'      'd all my l' 'her they l'      ' Stanley l'      ' and may l'      'uld they l'      'u all my l' 'friendly l'      'h gently l'      'e deadly l'      'f all my l'      'n all my l' 'Ere they l'      'steel my l'      ' tell my l'      'e kingly l'      'learn my l' 'd he say l'      't basely l'      'Thursday l'      'iciously l'      \" 'if any l\" ' as many l'      'hy glory l'      'not very l'      'a goodly l'      'e surely l' 'quiously l'      ', fairly l'      'lord! my l'      'entle my l'      ', he may l' 'our holy l'      ' worldly l'      ' my only l'      ' all, my l' 'ul, they l'      'o lately l'      's in any l'      ' no lady l' 'ter many l'      'Our holy l'      't vainly l'      'e\\nA lady l' ' you may l'      'y greedy l'      'untimely l'      'directly l' 'er on my l'      'e wistly l'      'ng Henry l'      'And only l' 's kindly l'      'KE:\\nThey l'     ' of many l'      'o, on my l'<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0434\u0443\u0442 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0435\u043a\u0441\u0442\u0435. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e (\u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437), \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a \u0434\u043b\u0438\u043d\u043e\u0439 10 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430. \u042d\u0442\u0438\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>build_next_token_map()<\/code>, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/common\/text-analysis.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043e\u0434\u0443\u043b\u0435 text-analysis<\/u><\/a>.)<\/p>\n<pre><code class=\"python\">next_token_map10 = build_next_token_map(     text=ts.text,     prefix_len=10,     vocab_size=tokenizer.vocab_size,     stoi=tokenizer.stoi )<\/code><\/pre>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0435 \u0432 <code>next_token_map10<\/code> \u2014 \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u0430\u0436\u0434\u044b\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 10 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u0441 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0447\u0430\u0441\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0438\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445. \u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">{     'the common': {         ' ': 12, \"'\": 1, ',': 1, '?': 1, 'a': 1, 's': 5, 'w': 3     },     ' the gods ': {         'b': 1, 'c': 1, 'd': 2, 'f': 1, 'g': 1, 'h': 2, 'k': 2, 's': 2, 't': 1, 'w': 2     },     ' authority': {         '\\n': 1, ' ': 5, ',': 5, ':': 2, ';': 1     },     ... }<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0432\u0438\u0434\u0430 (vocab_size,) \u0433\u0434\u0435 vocab_size \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 65). \u042d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 i \u0432 \u0442\u0435\u043d\u0437\u043e\u0440\u0435 \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 i-\u0442\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u043e\u0441\u043b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043a\u043b\u044e\u0447\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438. \u042d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u0442 \u0432\u043e\u0442 \u043d\u0430 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"python\">{       'the common': torch.tensor([             0, 12,  0,  0,  0,  1,  1,  0,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,             0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,             0,  0,  0,  5,  0,  0,  0,  3,  0,  0,  0       ]),       ' the gods ': torch.tensor([             0, 12,  0,  0,  0,  1,  1,  0,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,             0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,             0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,             0,  0,  0,  5,  0,  0,  0,  3,  0,  0,  0       ]),       ' authority': torch.tensor([           0, 12,  0,  0,  0,  1,  1,  0,  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,           0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,           0,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,           0,  0,  0,  5,  0,  0,  0,  3,  0,  0,  0       ]),     ... }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0445\u043e\u0436\u0438\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043f\u0440\u043e\u043c\u0442\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e. \u0422\u0430\u043a \u043a\u0430\u043a \u0432 <code>next_token_map10<\/code> \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442, \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0435\u0433\u043a\u043e:<\/p>\n<pre><code class=\"python\">total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0)<\/code><\/pre>\n<p>\u041c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u043e\u0436\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u0432\u0441\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044d\u0442\u043e \u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430 \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439:<\/p>\n<pre><code class=\"python\">prob_distribution = total_freq_distribution \/ total_freq_distribution.sum()<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">plot_prob_distribution_for_tokens(prob_distribution, title='Probability distribution using only block 0 similar strings')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0b8\/0c0\/add\/0b80c0add43d4cdb90840176f89395b5.png\" width=\"981\" height=\"373\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0b8\/0c0\/add\/0b80c0add43d4cdb90840176f89395b5.png\"\/><\/figure>\n<p>\u042d\u0442\u043e \u0442\u043e\u0436\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 \u0434\u0435\u043c\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<pre><code class=\"python\">tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) logits.plot_probs(title='Probability distribution from model')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/18a\/40c\/da7\/18a40cda79cc39866f5ba5b8632ab0d4.png\" width=\"981\" height=\"373\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18a\/40c\/da7\/18a40cda79cc39866f5ba5b8632ab0d4.png\"\/><\/figure>\n<p>\u0414\u0432\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435, \u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0438\u0445, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def print_distribution_comparison(     approx_top_tokens: Sequence[Tuple[str, float]],     model_top_tokens: Sequence[Tuple[str, float]], ):     max_len = min(len(approx_top_tokens), len(model_top_tokens))      print(         text_table(             headers=[\"Model Predictions\", \"Approximation Predictions\"],             data_columns=[                 [                     f\"{repr(token)[1:-1]}: {prob:.3f}\"                     for i, (token, prob) in enumerate(model_top_tokens)                     if i &lt; max_len                 ],                 [                     f\"{repr(token)[1:-1]}: {prob:.3f}\"                     for i, (token, prob) in enumerate(approx_top_tokens)                     if i &lt; max_len                 ],             ],             col_widths=[20, 20],         )     )<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<pre><code class=\"python\">approx_top_tokens = top_nonzero_tokens(prob_distribution, tokenizer.itos) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- i: 0.437            i: 0.389 o: 0.204            o: 0.250 a: 0.195            a: 0.222 e: 0.160            e: 0.139<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">hellinger_distance(prob_distribution, logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor(0.0711)<\/code><\/pre>\n<p>\u0421\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043b\u0438\u0437\u043a\u043e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043e\u0448\u0451\u043b \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"python\">q_idx=40 prompts[q_idx]<\/code><\/pre>\n<pre><code>'hing tremb'<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u043e\u0439 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 57 \u0441\u0442\u0440\u043e\u043a, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0445 \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u0442\u0430 \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e:<\/p>\n<pre><code class=\"python\">block_idx = 0 similarity_threshold=0.95 similar_indices = filter_on_prefiltered_results(     load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),     q_idx_start=q_idx,     q_idx_end=q_idx+1,     filter_fn=lambda values: values > similarity_threshold ) similar_strings = [     [strings10[i] for i in indices]     for indices in similar_indices ] len(similar_strings[0])<\/code><\/pre>\n<pre><code>57<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c, \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430 \u044d\u0442\u0438\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435:<\/p>\n<pre><code class=\"python\">total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum()  approx_top_tokens = top_nonzero_tokens(prob_distribution, tokenizer.itos)  tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- l: 0.999            e: 0.543 e: 0.000            l: 0.343 r: 0.000            r: 0.114<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0412\u0435\u0440\u0445\u043d\u0438\u0435 \u0442\u0440\u0438 \u0442\u043e\u043a\u0435\u043d\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0432 \u043a\u0430\u0436\u0434\u043e\u043c, \u043d\u043e \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0430 \u0438\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u0440\u0430\u0437\u043d\u0435\u0441\u0435\u043d\u044b. \u0418\u0437-\u0437\u0430 \u044d\u0442\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c:<\/p>\n<pre><code class=\"python\">tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) hellinger_distance(prob_distribution, logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor(0.6305)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u043c\u0442\u0430 &#8216;hing tremb&#8217; \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u043b\u043e\u0445\u043e\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u0412\u0441\u043a\u043e\u0440\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 \u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439 \u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u0441\u043d\u0438\u0437\u0438\u0442\u0441\u044f \u0441 0.63 \u0434\u043e \u0432\u0441\u0435\u0433\u043e 0.02.<\/p>\n<h4>\u041f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438\u00a0<\/h4>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 0.95: \u044f \u0438\u0441\u043a\u0430\u043b \u0441\u0442\u0440\u043e\u043a\u0438, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0432 \u0431\u043b\u043e\u043a\u0435 0 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c 0.95 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0432 \u0442\u043e \u0436\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u043c\u0442\u0430 id 57 (&#8216;And only l&#8217;) \u0441 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 0.90, \u043c\u044b \u043d\u0430\u0439\u0434\u0451\u043c 612 \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a, \u0430 \u043d\u0435 94, \u043a\u0430\u043a \u0440\u0430\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"python\">block_idx = 0 similarity_threshold=0.90 q_idx = 57 similar_indices = filter_on_prefiltered_results(     load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),     q_idx_start=q_idx,     q_idx_end=q_idx+1,     filter_fn=lambda values: values > similarity_threshold ) similar_strings = [     [strings10[i] for i in indices]     for indices in similar_indices ] len(similar_strings[0])<\/code><\/pre>\n<pre><code>612<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0434\u0440\u0443\u0433\u0438\u0435 (\u043c\u0435\u043d\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"python\">total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum()  approx_top_tokens = top_nonzero_tokens(prob_distribution, tokenizer.itos)  tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- i: 0.437            o: 0.584 o: 0.204            i: 0.251 a: 0.195            a: 0.095 e: 0.160            e: 0.066 u: 0.004            u: 0.002 l: 0.000            y: 0.001<\/code><\/pre>\n<p>\u041f\u044f\u0442\u044c \u0432\u0435\u0440\u0445\u043d\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435, \u043d\u043e \u043f\u0440\u0438 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u0420\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u0442\u043e\u0436\u0435 \u0432\u044b\u0448\u0435:<\/p>\n<pre><code class=\"python\">hellinger_distance(prob_distribution, logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor(0.2856)<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0447\u0442\u043e \u0443\u0445\u0443\u0434\u0448\u0438\u043b\u043e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e. \u0415\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u044b\u0448\u0435 0.95, \u0442\u043e \u043c\u044b \u0442\u043e\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043f\u0440\u0438 0.95, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">block_idx = 0 similarity_threshold=0.97 q_idx = 57 similar_indices = filter_on_prefiltered_results(     load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),     q_idx_start=q_idx,     q_idx_end=q_idx+1,     filter_fn=lambda values: values > similarity_threshold ) similar_strings = [     [strings10[i] for i in indices]     for indices in similar_indices ] len(similar_strings[0])<\/code><\/pre>\n<pre><code>33<\/code><\/pre>\n<pre><code class=\"python\">total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum()  approx_top_tokens = top_nonzero_tokens(prob_distribution, tokenizer.itos)  tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- i: 0.437            o: 0.278 o: 0.204            i: 0.250 a: 0.195            a: 0.250 e: 0.160            e: 0.222<\/code><\/pre>\n<pre><code class=\"python\">hellinger_distance(prob_distribution, logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor(0.1498)<\/code><\/pre>\n<p>\u041f\u043e\u0445\u043e\u0436\u0435, \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 0.95 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e. \u042f \u043f\u0440\u0438\u0448\u0451\u043b \u043a \u044d\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0438: \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0442\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0430\u0451\u0442 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041f\u043e\u043b\u043d\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/analyses\/40_widening_similar_space.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441\u0445\u043e\u0436\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432<\/u><\/a>.<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0434\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p><strong>\u0411\u043b\u043e\u043a<\/strong><\/p>\n<\/th>\n<th>\n<p><strong>\u041f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438<\/strong><\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.95<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.94<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.85<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.76<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">4<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.81<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.89<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043b, \u0447\u0442\u043e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u044f \u0441\u043c\u043e\u0433\u0443 \u043d\u0430\u0439\u0442\u0438. \u042f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0445\u043d\u0438\u043a, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 \u044d\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u044b\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430, \u043f\u043e\u0438\u0441\u043a \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0440\u0430\u0437\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0443\u0434\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0441\u0445\u043e\u0436\u0438\u043c\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438, \u0442\u0435\u043c \u0445\u0443\u0436\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u042f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <em>\u043c\u0435\u043d\u0435\u0435<\/em> \u0441\u0445\u043e\u0436\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044d\u0442\u0438 \u0431\u043b\u043e\u043a\u0438 \u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u043c\u0442\u044b \u0441 \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u0438\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435.<\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430\u00a0<\/h4>\n<p>\u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u043a\u043b\u0430\u0434 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0439\u0434\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0438, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0435 \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0431\u043b\u043e\u043a\u043e\u0432, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0448\u0435 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438. \u041f\u043e\u043a\u0430 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0438\u043d\u0434\u0435\u043a\u0441 57, &#8216;And only l&#8217;):<\/p>\n<pre><code class=\"python\">similarity_thresholds=[0.95, 0.94, 0.85, 0.76, 0.81, 0.89] q_idx = 57  similar_strings_per_block = []  for block_idx in range(n_layer):     similar_indices = filter_on_prefiltered_results(         load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),         q_idx_start=q_idx,         q_idx_end=q_idx+1,         filter_fn=lambda values: values > similarity_thresholds[block_idx]     )     similar_strings = [         [strings10[i] for i in indices]         for indices in similar_indices     ]     similar_strings_per_block.append(similar_strings)<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"python\">print(text_table(     headers=[\"Block Index\", \"Similarity Threshold\", \"# of Similar Strings\"],     data_columns=[         [f\"{block_idx:>10}\" for block_idx in range(n_layer)],         [f\"{threshold:>19}\" for threshold in similarity_thresholds],         [f\"{len(similar_strings[0]):>19}\" for similar_strings in similar_strings_per_block],     ],     col_widths=[14, 23, 23] ))<\/code><\/pre>\n<pre><code>Block Index   Similarity Threshold   # of Similar Strings -----------   --------------------   --------------------          0                   0.95                     94          1                   0.94                     47          2                   0.85                     70          3                   0.76                    108          4                   0.81                    175          5                   0.89                   2237<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430 \u044d\u0442\u0438\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u0438 \u0438\u0445 \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def frequency_distribution_from_similar_strings(     similar_strings_per_block: Sequence[Sequence[Sequence[str]]],     next_token_map: Dict[str, torch.Tensor], ) -> torch.Tensor:     # freqs_per_block_per_query - \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043f\u0438\u0441\u043a\u0430 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432. \u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442     # \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043d\u0430 \u0431\u043b\u043e\u043a. \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441.     # \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440 - \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e     # \u0431\u043b\u043e\u043a\u0430 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.     freqs_per_block_per_query: List[List[torch.Tensor]] = [[] for _ in range(n_layer)]      for block_idx in range(n_layer):         for similar_strings in similar_strings_per_block[block_idx]:             freqs_per_block_per_query[block_idx].append(                 torch.stack([next_token_map[string] for string in similar_strings]).sum(                     dim=0                 )             )      # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0447\u0430\u0441\u0442\u043e\u0442 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u0442\u0435\u043d\u0437\u043e\u0440 \u0432\u0438\u0434\u0430     # (n_layer, n_queries, vocab_size)     freqs = torch.stack(         [             torch.stack(freqs_per_block_per_query[block_idx])             for block_idx in range(n_layer)         ]     )      return freqs<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>frequency_distribution_from_similar_strings()<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0442\u043e\u0433\u043e \u043a\u043e\u0433\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0432\u044b\u0448\u0435:<\/p>\n<pre><code class=\"python\">total_freq_distribution = torch.stack([     next_token_map10[string] for string in similar_strings[0] ]).sum(dim=0)<\/code><\/pre>\n<p>\u041d\u043e \u0441 \u0434\u0432\u0443\u043c\u044f \u0432\u0430\u0436\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u041e\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u0447\u0451\u0442\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0445\u043e\u0436\u0438\u0445 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0432\u044b\u0448\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u043c \u043d\u0430\u043c\u0438 \u043a\u043e\u0434\u0435 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u043b\u0438 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0442\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0451 \u0434\u043b\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u043c\u0442\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u0447\u0442\u043e\u0431\u044b <code>similar_strings_per_block<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0434\u0438\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u0431\u043b\u043e\u043a, \u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e: \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 <code>similar_strings_per_block<\/code>:<\/p>\n<pre><code class=\"python\">freq_distribution = frequency_distribution_from_similar_strings(     similar_strings_per_block,     next_token_map10, ) freq_distribution.shape<\/code><\/pre>\n<pre><code>torch.Size([6, 1, 65])<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0435\u043d\u0437\u043e\u0440 \u0432\u0438\u0434\u0430 (6, 1, 65): 6 \u0431\u043b\u043e\u043a\u043e\u0432, 1 \u0437\u0430\u043f\u0440\u043e\u0441, 65 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u0431\u00f3\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u043e \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u0431\u044b \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438. \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u044d\u0442\u043e \u0432 \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.<\/p>\n<p>\u0412\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0435\u0433\u043e. \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0447\u0430\u0441\u0442\u043e\u0442 (\u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u0431\u043b\u043e\u043a) \u0438 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412 \u0441\u0432\u043e\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445 \u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u0430\u0451\u0442 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u044d\u0442\u0438\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438, \u044f \u0441\u043c\u043e\u0433 \u043f\u0443\u0442\u0451\u043c \u043f\u0440\u043e\u0431 \u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430\u0439\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u0432\u0435\u0441\u043e\u0432. \u042f \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0443 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0435\u0441\u043e\u0432, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043d\u0435 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u0434\u0431\u043e\u0440\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/analyses\/40_widening_similar_space.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 \u0441\u0445\u043e\u0436\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432<\/u><\/a>, \u0433\u0434\u0435 \u043c\u044b \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u043b\u0438 \u0438 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0441\u0430:<\/p>\n<pre><code class=\"python\">weights = torch.tensor([0.01, 0.01, 0.1, 1.5, 6, 0.01]).unsqueeze(dim=1).unsqueeze(dim=2) # (n_layer, 1, 1) total_freq_distribution = (freq_distribution * weights).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum(dim=-1, keepdim=True)<\/code><\/pre>\n<p>\u041c\u044b \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u043d\u0430 \u0432\u0435\u0441\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e \u0432\u0441\u0435\u043c \u0431\u043b\u043e\u043a\u0430\u043c, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \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. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c\u043e \u0441 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432 \u043a\u043e\u0434\u0435 \u043d\u0438\u0436\u0435 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u0435\u043d\u0437\u043e\u0440\u0430 prob_distribution \u0438\u043d\u0434\u0435\u043a\u0441 [0], \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0434\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<pre><code class=\"python\">approx_top_tokens = top_nonzero_tokens(prob_distribution[0], tokenizer.itos)  tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- i: 0.437            i: 0.363 o: 0.204            o: 0.265 a: 0.195            a: 0.213 e: 0.160            e: 0.147 u: 0.004            u: 0.011 l: 0.000            y: 0.000<\/code><\/pre>\n<pre><code class=\"python\">hellinger_distance(prob_distribution[0], logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor(0.0731)<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u043e\u0451\u0432 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043c\u0435\u043d\u044f\u0435\u0442 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e (\u0441\u0443\u0434\u044f \u043f\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430, \u043e\u043d\u0430 \u043b\u0438\u0448\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0445\u0443\u0436\u0435). \u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u043b\u043e\u0439: \u043f\u0440\u043e\u043c\u0442 \u0441 id 40 (&#8216;hing tremb&#8217;).<\/p>\n<pre><code class=\"python\">similarity_thresholds=[0.95, 0.94, 0.85, 0.76, 0.81, 0.89] q_idx = 40  similar_strings_per_block = []  for block_idx in range(n_layer):     similar_indices = filter_on_prefiltered_results(         load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),         q_idx_start=q_idx,         q_idx_end=q_idx+1,         filter_fn=lambda values: values > similarity_thresholds[block_idx]     )     similar_strings = [         [strings10[i] for i in indices]         for indices in similar_indices     ]     similar_strings_per_block.append(similar_strings)  freq_distribution = frequency_distribution_from_similar_strings(     similar_strings_per_block,     next_token_map10, ) weights = torch.tensor([0.01, 0.01, 0.1, 1.5, 6, 0.01]).unsqueeze(dim=1).unsqueeze(dim=2) # (n_layer, 1, 1) total_freq_distribution = (freq_distribution * weights).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum(dim=-1, keepdim=True) tokens = encoding_helpers.tokenize_string(prompts[q_idx]) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer)  approx_top_tokens = top_nonzero_tokens(prob_distribution[0], tokenizer.itos) model_top_tokens = logits.topk_tokens(k=10)[0][-1]  print_distribution_comparison(approx_top_tokens, model_top_tokens)<\/code><\/pre>\n<pre><code>Model Predictions   Approximation Predictions -----------------   ------------------------- l: 0.999            l: 0.997 e: 0.000            e: 0.002 r: 0.000            r: 0.000<\/code><\/pre>\n<pre><code class=\"python\">hellinger_distance(prob_distribution, logits.probs()[0][-1])<\/code><\/pre>\n<pre><code>tensor([0.0233])<\/code><\/pre>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0445\u043e\u0436\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0430\u0441\u044c \u043e\u0442 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0438\u043c\u0435\u043b\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 >0.63. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0430 \u043f\u043e\u0447\u0442\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u0430 \u0438 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 0.02. \u0422\u043e \u0435\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0451\u0432 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u043b \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u0437 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432.<\/p>\n<h4>\u041e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432\u00a0<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0439\u0434\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e \u0441\u0445\u043e\u0436\u0438\u043c\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0438 \u0432\u0441\u0435\u0445 \u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u0435\u043c\u044c \u043c\u0438\u043d\u0443\u0442  similarity_thresholds=[0.95, 0.94, 0.85, 0.76, 0.81, 0.89]  similar_strings_per_block = []  for block_idx in range(n_layer):     similar_indices = filter_on_prefiltered_results(         load_prefiltered=lambda q_idx: load_prefiltered_data(block_idx, q_idx),         q_idx_start=0,         q_idx_end=n_prompts,         filter_fn=lambda values: values > similarity_thresholds[block_idx]     )     similar_strings = [         [strings10[i] for i in indices]         for indices in similar_indices     ]     similar_strings_per_block.append(similar_strings)<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043d\u0430\u043c\u0438 \u0441\u0442\u0440\u043e\u043a, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"python\">freq_distribution = frequency_distribution_from_similar_strings(     similar_strings_per_block,     next_token_map10, ) weights = torch.tensor([0.01, 0.01, 0.1, 1.5, 6, 0.01]).unsqueeze(dim=1).unsqueeze(dim=2) # (n_layer, 1, 1) total_freq_distribution = (freq_distribution * weights).sum(dim=0) prob_distribution = total_freq_distribution \/ total_freq_distribution.sum(dim=-1, keepdim=True) prob_distribution.shape<\/code><\/pre>\n<pre><code>torch.Size([20000, 65])<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u0435\u043d\u0437\u043e\u0440 \u0432\u0438\u0434\u0430 (20000, 65): \u043e\u0434\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 65 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 20000 \u043f\u0440\u043e\u043c\u0442\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u043c\u0442\u044b \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u044e:<\/p>\n<pre><code class=\"python\">tokens = encoding_helpers.tokenize_strings(prompts) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) model_probs = logits.probs() model_probs = model_probs[:, -1, :] # \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u043c\u0442\u043e\u0432. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0425\u0435\u043b\u043b\u0438\u043d\u0433\u0435\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0438 \u043e\u0446\u0435\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<\/p>\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\/792020\/\"> https:\/\/habr.com\/ru\/articles\/792020\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u042f \u043e\u0431\u0443\u0447\u0438\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u043f\u043e\u0440\u044f\u0434\u043a\u0430 10 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432) <a href=\"https:\/\/en.wikipedia.org\/wiki\/Transformer_%28machine_learning_model%29\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440<\/u><\/a> \u043f\u043e \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0443 <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>Let\u2019s build GPT: from scratch, in code, spelled out<\/u><\/a> <a href=\"https:\/\/karpathy.ai\/\" rel=\"noopener noreferrer nofollow\"><u>\u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0438 \u0438 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0412 <a href=\"https:\/\/arxiv.org\/abs\/1706.03762\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043d\u0430\u0443\u0447\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/u><\/a>, \u043a\u0430\u043a \u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430\u0445 \u043f\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u043c \u0443\u043f\u043e\u0440 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/machinelearningmastery.com\/the-transformer-attention-mechanism\/\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u043c \u0441\u0430\u043c\u043e\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0438<\/u><\/a>, \u2014 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u044b \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044f\u043c \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0441\u0432\u0451\u0440\u0442\u043a\u0443. \u041d\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438\u043b\u0438 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u044f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <em>\u043f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/em>: <strong>\u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430?<\/strong><\/p>\n<p>\u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u043c\u043e\u0433\u0443 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u043e\u043c\u0442\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440, \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0445. \u0422\u043e, \u0447\u0442\u043e \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0433\u043e\u0434\u043e\u0432\u044b\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c, \u043d\u043e \u0434\u0430\u043b\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0442\u0435\u043e\u0440\u0438\u044f, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0430\u044f, \u043a\u0430\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b, \u0438 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0437\u043d\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0442\u043e \u043e\u043d \u0442\u0430\u043a\u043e\u0432: \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 (\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u043b\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e) \u0438\u0437\u0443\u0447\u0430\u0435\u0442 \u0432\u0435\u0441\u0430, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0442 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0441\u0442\u0440\u043e\u043a, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435. <strong>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u044d\u0442\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0431\u043b\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430.<\/strong> \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u043b\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u043c\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0441\u0442\u0440\u043e\u043a \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430\u043c. \u041e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<\/p>\n<p>\u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u043e, \u0447\u0442\u043e, \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440. \u041e\u043d \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430, \u043e \u0447\u0451\u043c \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043d\u0438\u0436\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u044e \u0432\u0430\u0441 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u043d\u043e\u0439 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0432 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u0432 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0435\u0439 \u0442\u0435\u043e\u0440\u0438\u0438. \u042f \u0441\u0442\u0440\u0435\u043c\u0438\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u0436\u0430\u0442\u044b\u043c, \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430\u0445 <a href=\"https:\/\/shyam.blog\/posts\/beyond-self-attention\/%28https:\/github.com\/spather\/transformer-experiments%29\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/u><\/a>.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u2014 \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043a\u0441\u043a\u0443\u0440\u0441 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u042f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u043e\u0448\u0438\u0431\u043a\u0438 \u0438\u043b\u0438 \u0443\u043f\u0443\u0441\u0442\u0438\u043b \u0447\u0442\u043e-\u0442\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041b\u044e\u0431\u044b\u0435 \u043e\u0442\u0437\u044b\u0432\u044b \u043f\u043e \u043c\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 shyam.pather at gmail dot com.<\/p>\n<h3>\u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u00a0<\/h3>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h4>\n<p>\u042f \u0445\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u044f\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0434 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0435 \u043c\u043d\u043e\u0439. \u041e\u043d \u0432\u0437\u044f\u0442 \u0438\u0437 \u0432\u0438\u0434\u0435\u043e <a href=\"https:\/\/karpathy.ai\/\" rel=\"noopener noreferrer nofollow\"><u>\u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438<\/u><\/a> <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>Let\u2019s build GPT: from scratch, in code, spelled out<\/u><\/a> (\u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0435\u0433\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c).<\/p>\n<p>\u042f \u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434, \u043a\u043e\u043f\u0438\u0440\u0443\u044f \u0432\u0441\u0451, \u0447\u0442\u043e \u0432\u0438\u0434\u0435\u043b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0432\u0438\u0434\u0435\u043e. \u0422\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435, \u044f \u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0432 <a href=\"https:\/\/github.com\/karpathy\/ng-video-lecture\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 GitHub \u044d\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e<\/u><\/a> \u0438 \u0432 <a href=\"https:\/\/github.com\/karpathy\/nanoGPT\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 nanoGPT<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043a\u043e\u0434 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u044f \u0432\u043d\u0451\u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043c\u043e\u0433 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439\/\u043a\u043e\u0434\u043e\u043c <a href=\"https:\/\/github.com\/spather\/transformer-experiments\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043e\u0435\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/u><\/a>, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/models\/transformer.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/u><\/a>. \u0418\u0442\u043e\u0433\u043e: \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u044f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0410\u043d\u0434\u0440\u0435\u044f \u041a\u0430\u0440\u043f\u0430\u0442\u0438, \u043d\u0435 \u043c\u043e\u044f. \u0410\u043d\u0430\u043b\u0438\u0437 \u0438 \u0432\u0435\u0441\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u2014 \u043c\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u0432\u043a\u043b\u0430\u0434. \u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043f\u043e\u0441\u0442\u0430 \u044f \u0431\u0443\u0434\u0443\u0442 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0438 \u0446\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u0441\u0442\u044b, \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<h4>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0<\/h4>\n<p>\u041c\u043e\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e <a href=\"https:\/\/en.wikipedia.org\/wiki\/Transformer_%28machine_learning_model%29\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440<\/u><\/a> \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u043c, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041e\u043d \u043e\u0431\u0443\u0447\u0430\u043b\u0441\u044f \u043d\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 <a href=\"https:\/\/raw.githubusercontent.com\/karpathy\/char-rnn\/master\/data\/tinyshakespeare\/input.txt\" rel=\"noopener noreferrer nofollow\"><u>TinyShakespeare<\/u><\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u043c 40 \u0442\u044b\u0441\u044f\u0447 \u0441\u0442\u0440\u043e\u043a \u043f\u044c\u0435\u0441 \u0428\u0435\u043a\u0441\u043f\u0438\u0440\u0430. \u0421\u043f\u0443\u0441\u0442\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0447\u0430\u0441 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 GPU RTX 4000 \u043e\u043d \u043c\u043e\u0433 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0435\u043a\u0441\u043f\u0438\u0440\u043e\u0432\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043f\u043e \u0435\u0451 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440: \u043d\u0430\u0447\u0430\u0432 \u0441 \u043f\u0440\u043e\u043c\u0442\u0430 ROMEO \u0438 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u0432 500 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438\u0437 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e \u043f\u0440\u043e\u043c\u0442\u0443 ROMEO:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">device = 'cuda' if torch.cuda.is_available() else 'cpu' ts = TinyShakespeareDataSet(cache_file=environment.code_root \/ 'nbs\/artifacts\/input.txt') m, tokenizer = create_model_and_tokenizer(     saved_model_filename=environment.code_root \/ 'nbs\/artifacts\/shakespeare-20231112.pt',     dataset=ts,     device=device, ) encoding_helpers = EncodingHelpers(tokenizer, device) accessors = TransformerAccessors(m, device)  torch.manual_seed(2321) # \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0440\u043e\u0433\u043e\u043d\u0435 prompt = 'ROMEO:' tokens = encoding_helpers.tokenize_string(prompt) print(tokenizer.decode(m.generate(tokens, max_new_tokens=500)[0].tolist()))<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<pre><code>ROMEO: If thou wilt triumphant be virtue, and since from any bold virtue that is made a bawd of earth, then the duke desires of patience and perish: take up the other husband, dislike his tent back.  First Citizen: Ourself goes, go back: you have no consul, but the disguised gods.  Second Citizen: We choose him in the world, he did runk itself.  First Citizen: Sir, I am I a man changed him and thriving, I have heard the king.  CORIOLANUS: Consider him!  AUFIDIUS: Most gracious irice, and you must danc<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043d\u0435 \u0428\u0435\u043a\u0441\u043f\u0438\u0440, \u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e. \u0422\u0435\u043a\u0441\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043f\u044c\u0435\u0441\u044b, \u044f\u0437\u044b\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0430\u0440\u0445\u0430\u0438\u0447\u043d\u044b\u043c, \u0438\u043c\u0435\u043d\u0430\/\u0442\u0438\u0442\u0443\u043b\u044b \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0435\u0439 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u044c\u0435\u0441 \u0428\u0435\u043a\u0441\u043f\u0438\u0440\u0430. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u2014 \u0438\u0437 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e. \u041f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u044f \u0438 \u043a\u0430\u043f\u0438\u0442\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u044b. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u0447\u0430\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>\u0422\u043e\u043a\u0435\u043d\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b<\/strong>, \u0430 \u043d\u0435 \u0441\u043b\u043e\u0432\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442 \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 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043f\u0440\u043e\u043c\u0442 <code>my most gr<\/code>, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u0442 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>'a' 0.819 'e' 0.081 'i' 0.059 'o' 0.036 'u' 0.004 'y' 0.001 'w' 0.000 'r' 0.000 'g' 0.000 's' 0.000<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u0440\u043e\u043c\u0442\u0430 my most gr<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">prompt = 'my most gr' tokens = encoding_helpers.tokenize_string(prompt) logits, _ = m(tokens) logits = LogitsWrapper(logits.detach(), tokenizer) for token, prob in logits.topk_tokens(k=10)[0][-1]:     print(f'{repr(token)} {prob:.3f}')<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 <a href=\"https:\/\/shyam.blog\/posts\/beyond-self-attention\/#i-model-details\" rel=\"noopener noreferrer nofollow\"><u>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 I<\/u><\/a> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e \u043c\u043e\u0434\u0435\u043b\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/spather\/transformer-experiments\/blob\/master\/nbs\/models\/transformer.ipynb\" rel=\"noopener noreferrer nofollow\"><u>\u043a\u043e\u0434<\/u><\/a> \u0438 <a href=\"https:\/\/www.youtube.com\/watch?v=kCc8FmEb1nY\" rel=\"noopener noreferrer nofollow\"><u>\u0432\u0438\u0434\u0435\u043e \u0410\u043d\u0434\u0440\u0435\u044f<\/u><\/a>.<\/p>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u043b\u043e\u043a\u0430 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430\u00a0<\/h4>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0432 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u043f\u043e\u0434\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430: \u0441\u043b\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u0441\u043e\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u044f\u043c\u044b\u0445 \u0438 \u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0445 \u0441\u0432\u044f\u0437\u0435\u0439, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <code>Block<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 PyTorch:<\/p>\n<pre><code class=\"python\">class Block(nn.Module):     \"\"\"One transformer block\"\"\"      def __init__(self, n_embed, n_head):         super().__init__()         head_size = n_embed \/\/ n_head         self.sa = MultiHeadAttention(n_head, head_size)         self.ffwd = FeedForward(n_embed)         self.ln1  = nn.LayerNorm(n_embed)         self.ln2 = nn.LayerNorm(n_embed)       def forward(self, x):         x = x + self.sa(self.ln1(x)) # \u0447\u0430\u0441\u0442\u044c \u0441 `x +` - \u044d\u0442\u043e skip connection         x = x + self.ffwd(self.ln2(x)) # \u0447\u0430\u0441\u0442\u044c \u0441 `x +` - \u044d\u0442\u043e skip connection          return x<\/code><\/pre>\n<p>\u041e \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u043b\u043e\u0432\u043e\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043c\u043d\u043e\u0433\u043e\u0435, \u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u043e \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043e \u043d\u0435\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 <a href=\"https:\/\/stats.stackexchange.com\/q\/485910\" rel=\"noopener noreferrer nofollow\"><em><u>https:\/\/stats.stackexchange.com\/q\/485910<\/u><\/em><\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u042f \u043d\u0430\u0447\u0430\u043b \u0441\u0432\u043e\u0451 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u0438\u0434\u0451\u0442 \u043f\u043e\u0441\u043b\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e \u0432 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0438\u0434\u0451\u0442 \u0441\u0435\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e. \u0412 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u0441\u0435\u0445 \u0448\u0435\u0441\u0442\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 65% \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0433\u0440\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c.<\/p>\n<p>\u041a\u0430\u043a \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u043e\u0437\u0436\u0435, \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0430\u043a\u0442\u043e\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0442\u043e, \u043a\u0430\u043a \u0431\u043b\u043e\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435.<\/p>\n<h3>\u0414\u0435\u043c\u043e: \u043c\u043e\u0451 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438\u00a0<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u044e \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u043c\u0442 <code>And only l<\/code> \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u0440\u043f\u0443\u0441\u0443, \u043d\u0430\u0448\u043b\u0438 \u0432\u0441\u0435 \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u043e\u0439 \u0436\u0435 \u0434\u043b\u0438\u043d\u044b, \u0447\u0442\u043e \u0438 \u043d\u0430\u0448 \u043f\u0440\u043e\u043c\u0442 (10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432), \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0438\u0445 \u0432\u0441\u0435 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0435\u0442\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0440\u0430\u0432\u0435\u043d \u0438\u043b\u0438 \u0432\u044b\u0448\u0435 0.95 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u043e\u043c\u0442\u043e\u043c <code>And only l<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code>'hat only l'    's sickly l'    ' as\\nthey l'   'r kingly l'    're; they l' 'eby they l'    'ar, they l'    'im, only l'    'ling any l'    'life may l' 'nobility l'    'e\\nBy any l'   ' as they l'    ', if any l'    ' hastily l' 'tly they l'    ' ghastly l'    '\\nMy only l'   'For many l'    'r in any l' ' till my l'    'all they l'    'hen they l'    'at Henry l'    'oolishly l' 'er:\\nThey l'   'may they l'    'or stony l'    'ur Henry l'    'l gladly l' 'yet they l'    'y;\\nDelay l'   'e, on my l'    'or Henry l'    'I dearly l' ' if they l'    ' she may l'    't\\nfairly l'   'ould say l'    'd all my l' 'her they l'    ' Stanley l'    ' and may l'    'uld they l'    'u all my l' 'friendly l'    'h gently l'    'e deadly l'    'f all my l'    'n all my l' 'Ere they l'    'steel my l'    ' tell my l'    'e kingly l'    'learn my l' 'd he say l'    't basely l'    'Thursday l'    'iciously l'    \" 'if any l\" ' as many l'    'hy glory l'    'not very l'    'a goodly l'    'e surely l' 'quiously l'    ', fairly l'    'lord! my l'    'entle my l'    ', he may l' 'our holy l'    ' worldly l'    ' my only l'    ' all, my l' 'ul, they l'    'o lately l'    's in any l'    ' no lady l' 'ter many l'    'Our holy l'    't vainly l'    'e\\nA lady l' ' you may l'    'y greedy l'    'untimely l'    'directly l' 'er on my l'    'e wistly l'    'ng Henry l'    'And only l' 's kindly l'    'KE:\\nThey <\/code><\/pre>\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-367560","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367560","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=367560"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/367560\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}