{"id":326288,"date":"2021-07-11T21:00:28","date_gmt":"2021-07-11T21:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=326288"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=326288","title":{"rendered":"\u041c\u043e\u0434\u0435\u043b\u0438 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 sequence-to-sequence \u043d\u0430 PyTorch (\u0427\u0430\u0441\u0442\u044c 1)"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 sequence-to-sequence (seq2seq) \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/pytorch\/pytorch\" rel=\"noopener noreferrer nofollow\">PyTorch<\/a> 1.8, <a href=\"https:\/\/github.com\/pytorch\/text\" rel=\"noopener noreferrer nofollow\">torchtext<\/a> 0.9 \u0438 <a href=\"https:\/\/spacy.io\/\" rel=\"noopener noreferrer nofollow\">spaCy<\/a> 3.0, \u043f\u043e\u0434 Python 3.8. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435: \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e. <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u0444\u0440\u0435\u0439\u043c\u0432\u0451\u0440\u043a PyTorch, \u0442.\u043a. \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0441\u043c\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 TensorFlow. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f PyTorch \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u0443\u044e \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e TensorFlow (\u0441\u043c. \u043d\u0435\u0434\u0430\u0432\u043d\u0438\u0439 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/company\/ru_mts\/blog\/565456\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u0442<\/a>).<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b\u044b<\/h3>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c 4-\u0433\u043e, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u0440\u043e\u0434\u0438\u0432\u0448\u0435\u0439 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u043e\u0441\u0442\u043e\u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432 \u0432\u0430\u043c \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u0431\u0443\u0434\u0435\u0442 \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0443\u044e \u0438 \u0440\u0443\u0441\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u0438 jupyter notebook.<\/p>\n<ul>\n<li>\n<p>1 &#8212; Sequence to Sequence Learning with Neural Networks<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043c\u043e\u0434\u0435\u043b\u044c\u044e seq2seq \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyTorch \u0438 torchtext. \u041c\u044b \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u0441\u043d\u043e\u0432 \u0441\u0435\u0442\u0435\u0439 seq2seq \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u0432\u0449\u0438\u043a (\u043a\u043e\u0434\u0435\u0440-\u0434\u0435\u043a\u043e\u0434\u0435\u0440), \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 PyTorch \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c torchtext \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0442\u044f\u0436\u0435\u043b\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u0430. \u0421\u0430\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.3215\" rel=\"noopener noreferrer nofollow\">Sequence to Sequence Learning with Neural Networks<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u044b\u0435 LSTM \u0441\u0435\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>2 &#8212; Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u0438 seq2seq, \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043d\u0430\u0448\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u044f\u0445 \u043e PyTorch \u0438 torchtext, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0435\u0448\u0435\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0436\u0430\u0442\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0430\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434\u0435\u0440\u0430-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430. \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438  <a href=\"https:\/\/arxiv.org\/abs\/1406.1078\" rel=\"noopener noreferrer nofollow\">Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 GRU \u0441\u0435\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>3 &#8212; Neural Machine Translation by Jointly Learning to Align and Translate<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435\u043c \u043a\u0430\u043a \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.0473\" rel=\"noopener noreferrer nofollow\">Neural Machine Translation by Jointly Learning to Align and Translate<\/a>. \u042d\u0442\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u0436\u0430\u0442\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0443 \u00ab\u043e\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f\u00bb \u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043a\u043e\u0434\u0435\u0440\u0430. \u0412\u0435\u0441\u0430 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u043c\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041a\u0430\u043a \u0438\u0442\u043e\u0433, \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0443\u0447\u0438\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>4 &#8212; \u0423\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u041c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 BLEU<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043c\u043e\u0434\u0435\u043b\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 <em>\u0443\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> \u0438 <em>\u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0443<\/em>. \u042d\u0442\u0438 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 (NLP). \u0423\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e. \u041c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435\\\u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u043c\u0443, \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u0432 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0443 BLEU \u043f\u043e \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>5 &#8212; Convolutional Sequence to Sequence Learning<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043e\u0442\u043e\u0439\u0434\u0451\u043c \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 seq2seq \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438. \u0422\u043e \u0435\u0441\u0442\u044c, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e, \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0451. \u0421\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c <a href=\"https:\/\/arxiv.org\/abs\/1705.03122\" rel=\"noopener noreferrer nofollow\">Convolutional Sequence to Sequence<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0435\u0432 \u043a\u0430\u043a \u0432 \u043a\u043e\u0434\u0435\u0440\u0435, \u0442\u0430\u043a \u0438 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u0441 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. <\/p>\n<\/li>\n<li>\n<p>6 &#8212; Attention Is All You Need<\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0435 \u0431\u0430\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c Transformer \u0438\u0437 <a href=\"https:\/\/arxiv.org\/abs\/1706.03762\" rel=\"noopener noreferrer nofollow\">Attention Is All You Need<\/a>. \u042d\u0442\u0430 \u0441\u0435\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0441 \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 &#171;\u043c\u043d\u043e\u0433\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f&#187;. \u041a\u043e\u0434\u0435\u0440 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u0434\u0441\u043b\u043e\u0435\u0432 &#171;\u043c\u043d\u043e\u0433\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f&#187; \u0438 Positionwise Feedforward. \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0437\u043d\u0430\u043d\u0438\u0439. <\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u043f\u0438\u0441\u043e\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u0443\u0447\u0435\u0431\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c\u0438.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/spro\/practical-pytorch\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/spro\/practical-pytorch<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/keon\/seq2seq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/keon\/seq2seq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pengshuang\/CNN-Seq2Seq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/pengshuang\/CNN-Seq2Seq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pytorch\/fairseq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/pytorch\/fairseq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/jadore801120\/attention-is-all-you-need-pytorch\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/jadore801120\/attention-is-all-you-need-pytorch<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/nlp.seas.harvard.edu\/2018\/04\/03\/attention.html\" rel=\"noopener noreferrer nofollow\">http:\/\/nlp.seas.harvard.edu\/2018\/04\/03\/attention.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2019\/06\/understanding-transformers-nlp-state-of-the-art-models\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.analyticsvidhya.com\/blog\/2019\/06\/understanding-transformers-nlp-state-of-the-art-models\/<\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0438\u043a\u043e\u043b\u0435\u043d\u043a\u043e \u0421.\u0418., \u041a\u0430\u0434\u0443\u0440\u0438\u043d \u0410., \u0410\u0440\u0445\u0430\u043d\u0433\u0435\u043b\u044c\u0441\u043a\u0430\u044f \u0415.\u0412. \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0432 \u043c\u0438\u0440 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439. \u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433: \u041f\u0438\u0442\u0435\u0440. 2020. 481 \u0441.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0443\u0434\u0444\u0435\u043b\u043b\u043e\u0443 \u042f., \u0411\u0435\u043d\u0434\u0436\u0438\u043e \u0418., \u041a\u0443\u0440\u0432\u0438\u043b\u043b\u044c \u0410. \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u041c\u043e\u0441\u043a\u0432\u0430: \u0414\u041c\u041a-\u041f\u0440\u0435\u0441\u0441. 2018. 652 \u0441.<\/p>\n<\/li>\n<\/ul>\n<h2>1 &#8212; Sequence to Sequence Learning with Neural Networks<\/h2>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432 Google Colab):<\/p>\n<p> <a href=\"https:\/\/github.com\/bentrevett\/pytorch-seq2seq\/blob\/master\/1%20-%20Sequence%20to%20Sequence%20Learning%20with%20Neural%20Networks.ipynb\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f jupyter notebook<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/vasiliyeskin\/bentrevett-pytorch-seq2seq_ru\/blob\/master\/1%20-%20Sequence%20to%20Sequence%20Learning%20with%20Neural%20Networks.ipynb\" rel=\"noopener noreferrer nofollow\">\u0420\u0443\u0441\u0441\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f jupyter notebook<\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0438\u0437 \u0441\u0435\u0440\u0438\u0438 \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f PyTorch \u0438 torchtext. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u0432 \u0441 \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u0433\u043e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u043a \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u044f\u0437\u044b\u043a\u0435, \u0438\u043b\u0438 \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0442\u0440\u0435\u0442\u0438\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0435\u043b\u043a\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u043a\u043b\u0435\u043e\u0442\u0438\u0434\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043c\u0420\u041d\u041a (<a href=\"https:\/\/deepmind.com\/blog\/article\/alphafold-a-solution-to-a-50-year-old-grand-challenge-in-biology\" rel=\"noopener noreferrer nofollow\">AlphaFold<\/a>).<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 seq2seq \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.3215\" rel=\"noopener noreferrer nofollow\">Sequence to Sequence Learning with Neural Networks<\/a>.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 sequence-to-sequence (seq2seq) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <em>\u043a\u043e\u0434\u0435\u0440\u0430-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <em>\u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c<\/em> (RNN) \u0434\u043b\u044f <em>\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/em> \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e (\u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e) \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440. \u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u0435\u0440\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <em>\u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/em>. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u0430\u043a \u043e\u0431 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u043d\u0438\u0442\u0438\u0432\u0438\u0441\u0442\u043e\u0432, \u044d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u043d\u0430\u0431\u043e\u0440 \u043e\u0431\u0440\u0430\u0437\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0441 \u043e\u0431\u0440\u0430\u0437\u0430\u043c\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <em>\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/em> \u0432\u0442\u043e\u0440\u043e\u0439 RNN, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0447\u0438\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0435 (\u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435) \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u0435\u0433\u043e \u0441\u043b\u043e\u0432\u043e \u0437\u0430 \u0441\u043b\u043e\u0432\u043e\u043c, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043b\u0438\u043a\u0441\u0435\u043c\u0435 \u0437\u0430 \u0440\u0430\u0437.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed5\/d04\/751\/ed5d04751a75f3ad3bae170d46faaf86.png\" width=\"695\" height=\"421\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0448\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0432\u043e\u0434\u0430\/\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u00abguten morgen\u00bb, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 (\u0436\u0435\u043b\u0442\u044b\u0439, \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0435\u0447\u0438 (\u0441\u043b\u043e\u0432\u0430, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f,&#8230;) \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443), \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a (\u0437\u0435\u043b\u0435\u043d\u044b\u0439). \u0412\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043a\u0435\u043d\u044b <em>\u043d\u0430\u0447\u0430\u043b\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> (<code>&lt;sos&gt;<\/code> \u2014 <em>start of sequence<\/em>) \u0438 <em>\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> (<code>&lt;eos&gt;<\/code> \u2014 <em>end of sequence<\/em>) \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0432 RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433-\u0432\u0435\u0440\u0441\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"e (x_t)\" alt=\"e (x_t)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f2\/f33\/c6e\/8f2f33c6e4e39a0ebdc9f2b022347b67.svg\">\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u0430 \u0441\u043b\u043e\u0435\u043c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 e, \u0442\u0430\u043a \u0438 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430, <img decoding=\"async\" class=\"formula inline\" source=\"h_{t-1}\" alt=\"h_{t-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed4\/3e0\/143\/ed43e0143e8c3bead2cec2049d13b327.svg\">\u041d\u0430 \u0432\u044b\u0445\u043e\u0434 RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"h_t\" alt=\"h_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bba\/f41\/2a2\/bbaf412a284866e6afbd6d1f3f2dd9e3.svg\">\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u0430\u043a \u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f (EncoderRNN) \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <img decoding=\"async\" class=\"formula inline\" source=\"e(x_t)\" alt=\"e(x_t)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e1\/012\/e7c\/5e1012e7c0fe00f04fa6da73f775da09.svg\">\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"h_ {t-1}\" alt=\"h_ {t-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/215\/24d\/813\/21524d81305b3f7eac53f75109bad522.svg\"><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"h_t = \\text{EncoderRNN}(e(x_t), h_{t-1})\" alt=\"h_t = \\text{EncoderRNN}(e(x_t), h_{t-1})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/351\/019\/332\/351019332f75c238b055759cbd11240e.svg\" width=\"257\" height=\"22\"><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u0431\u0431\u0440\u0435\u0432\u0438\u0430\u0442\u0443\u0440\u0443 RNN, \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u043c \u043f\u043e\u0434 \u043d\u0435\u0439 \u0441\u0435\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>LSTM<\/em> (Long Short-Term Memory) \u0438\u043b\u0438 <em>GRU<\/em> (Gated Recurrent Unit).<\/p>\n<p>\u041c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"X = {x_1, x_2, ..., x_T }\" alt=\"X = {x_1, x_2, ..., x_T }\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a45\/42c\/7c4\/a4542c7c44fba93e57367ac3f55dc3ce.svg\">\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"x_1 = \\text{}, x_{2} = \\text{guten}\" alt=\"x_1 = \\text{}, x_{2} = \\text{guten}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e19\/695\/cc8\/e19695cc8d1dcf0c1a085c50ec0f5dc2.svg\">\u0438 \u0442.\u0434. \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, <img decoding=\"async\" class=\"formula inline\" source=\"h_0\" alt=\"h_0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7d3\/a13\/387\/7d3a133872c669f8d732a1827eab2392.svg\">\u043e\u0431\u044b\u0447\u043d\u043e \u043b\u0438\u0431\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u044f\u043c\u0438, \u043b\u0438\u0431\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0441\u043b\u043e\u0432\u043e <img decoding=\"async\" class=\"formula inline\" source=\"x_T\" alt=\"x_T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47c\/930\/f22\/47c930f22ca0a105898aedf9f706ec6b.svg\">\u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 RNN \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"h_T\" alt=\"h_T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/216\/573\/fc0\/216573fc0979928901821aee55555345.svg\">\u043a\u0430\u043a \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0442\u043e \u0435\u0441\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\" z = h_T\" alt=\" z = h_T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92f\/1cd\/55a\/92f1cd55a2266f038dd031f8b3408f90.svg\">. \u042d\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 z, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435\/\u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u00abgood morning\u00bb. \u041a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u0432\u0445\u043e\u0434\u043e\u043c \u0432 RNN \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 (\u0441\u0438\u043d\u0438\u0439) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"d (y_t)\" alt=\"d (y_t)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd1\/0d7\/d30\/cd10d7d304b1481ab6f9f51af85e4dca.svg\">, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"s_ { t-1}\" alt=\"s_ { t-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c4\/918\/a04\/4c4918a04acd286566696b460bea95af.svg\">, \u0433\u0434\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"s_0\" alt=\"s_0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/786\/413\/fd1\/786413fd1f2d9e20646d3d58b83c5813.svg\">, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, <img decoding=\"async\" class=\"formula inline\" source=\"s_0 = z\" alt=\"s_0 = z\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f39\/6aa\/e9f\/f396aae9fc11e4663f08b88e11387a15.svg\">. \u0422.\u0435. \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0435\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043a\u043e\u0434\u0435\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <img decoding=\"async\" class=\"formula inline\" source=\"d (y_t)\" alt=\"d (y_t)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a31\/211\/03b\/a3121103b085426cec5c75c3f0f181f5.svg\">\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"s_ { t-1}\" alt=\"s_ { t-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/14c\/bde\/4fc\/14cbde4fc7d00c9aa914d12deab6d058.svg\">:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"s_t = \\text{DecoderRNN}(d(y_t), s_{t-1})\" alt=\"s_t = \\text{DecoderRNN}(d(y_t), s_{t-1})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f4e\/f7e\/08c\/f4ef7e08cabca5f986f4f1a0bb3acb96.svg\" width=\"251\" height=\"22\"><\/p>\n<p>\u0425\u043e\u0442\u044f \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0432\u0445\u043e\u0434\u0430\/\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 e \u0438 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0432\u044b\u0445\u043e\u0434\u0430 d \u043e\u0431\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0436\u0451\u043b\u0442\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435, \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u043e\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0412 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"s_t\" alt=\"s_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/306\/bf4\/68d\/306bf468dae64bae99c02720b315d86c.svg\">\u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f (\u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u044d\u0442\u0443 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 <code>Linear<\/code>, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043e\u043b\u0435\u0442\u043e\u0432\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c) \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y} _t\" alt=\"\\hat{y} _t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed9\/9c7\/e49\/ed99c7e4920c8d1fc89ecaa232b6c723.svg\">.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\hat{y}_t = f ( s_t ) \" alt=\"\\hat{y}_t = f ( s_t ) \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/780\/961\/750\/78096175054b06fb885e8ba9ee587cd8.svg\" width=\"85\" height=\"22\"><\/p>\n<p>\u0421\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c, \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u0430\u0433. \u041c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>&lt;sos&gt;<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"y_1\" alt=\"y_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/39c\/74b\/077\/39c74b07765200226158d80426ca2af4.svg\">\u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 y<sub>t&gt; 1<\/sub>, \u043c\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435, \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435\/\u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"y_t\" alt=\"y_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8df\/bda\/8f6\/8dfbda8f6cd5be706de1693fe76c148f.svg\">, \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0448\u0438\u043c \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u043c <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y} _ {t-1}\" alt=\"\\hat{y} _ {t-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18c\/d7a\/37f\/18cd7a37fc01ee3ef31e4ce585ee45ec.svg\">. \u0422\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <em>\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0441 \u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c<\/em>, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c <a href=\"https:\/\/machinelearningmastery.com\/teacher-forcing-for-recurrent-neural-networks\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438\/\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u043d\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0432 \u043d\u0430\u0448\u0435\u043c \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0431\u044b\u0447\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0441\u043b\u043e\u0432\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0435 \u0432\u044b\u0434\u0430\u0441\u0442 \u0442\u043e\u043a\u0435\u043d \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438  \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{Y} = { \\hat{y}_1, \\hat{y}_2, ..., \\hat{y}_T }\" alt=\"\\hat{Y} = { \\hat{y}_1, \\hat{y}_2, ..., \\hat{y}_T }\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d72\/c79\/059\/d72c79059fba8c5928fa2efb9bac120c.svg\">, \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0441 \u043d\u0430\u0448\u0438\u043c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, <img decoding=\"async\" class=\"formula inline\" source=\"Y = { y_1, y_2, ..., y_T }\" alt=\"Y = { y_1, y_2, ..., y_T }\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/86f\/7d2\/690\/86f7d2690e41c9ed00590eca09fb7977.svg\">, \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043f\u043e\u0442\u0435\u0440\u044c\/\u043e\u0448\u0438\u0431\u043e\u043a. \u0417\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u0438 \u043f\u043e\u0442\u0435\u0440\u0438 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 PyTorch \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c torchtext \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c spaCy \u0434\u043b\u044f \u043f\u043e\u043c\u043e\u0449\u0438 \u0432 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">import torch import torch.nn as nn import torch.optim as optim  from torchtext.legacy.datasets import Multi30k from torchtext.legacy.data import Field, BucketIterator  import spacy import numpy as np  import random import math import time<\/code><\/pre>\n<p>\u041c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">SEED = 1234  random.seed(SEED) np.random.seed(SEED) torch.manual_seed(SEED) torch.cuda.manual_seed(SEED) torch.backends.cudnn.deterministic = True<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u044b. \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &#171;\u0434\u043e\u0431\u0440\u043e\u0435 \u0443\u0442\u0440\u043e!&#187; \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f [&#171;\u0434\u043e\u0431\u0440\u043e\u0435&#187;, &#171;\u0443\u0442\u0440\u043e&#187;, &#171;!&#187;]. \u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043b\u043e\u0432. \u041a\u0430\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430? \u0427\u0442\u043e \u0436, \u00ab\u0434\u043e\u0431\u0440\u043e\u00bb \u0438 \u00ab\u0443\u0442\u0440\u043e\u00bb &#8212; \u044d\u0442\u043e \u0438 \u0441\u043b\u043e\u0432\u0430, \u0438 \u0437\u043d\u0430\u043a\u0438, \u043d\u043e \u00ab!\u00bb \u044d\u0442\u043e \u0437\u043d\u0430\u043a, \u0430 \u043d\u0435 \u0441\u043b\u043e\u0432\u043e.<\/p>\n<p>\u0412 spaCy \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 (de_core_news_sm \u0434\u043b\u044f \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u0433\u043e \u0438 en_core_web_sm \u0434\u043b\u044f \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e), \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code>python -m spacy download en_core_web_sm python -m spacy download de_core_news_sm<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 Google Colab \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 colab runtime! \u041d\u0430\u0438\u0431\u044b\u0441\u0442\u0440\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u043a\u043e\u043c\u0430\u0434\u0443\uff1a <strong>Ctrl + M + .<\/strong>):<\/p>\n<pre><code>!pip install -U spacy==3.0 !python -m spacy download en_core_web_sm !python -m spacy download de_core_news_sm<\/code><\/pre>\n<p>\u041c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>spacy_de = spacy.load('de_core_news_sm') spacy_en = spacy.load('en_core_web_sm')<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0432 torchtext \u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430\u0432\u0442\u043e\u0440\u044b \u0441\u0447\u0438\u0442\u0430\u044e\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u0432\u043e\u0434\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0438\u0445 \u043c\u043d\u0435\u043d\u0438\u044e, \u00ab\u0432\u0432\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0435, \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438\u00bb. \u041c\u044b \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u0435\u0440\u0435\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044f \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<pre><code class=\"python\">def tokenize_de(text):     \"\"\"     Tokenizes German text from a string into a list of strings (tokens) and reverses it     \"\"\"     return [tok.text for tok in spacy_de.tokenizer(text)][::-1]  def tokenize_en(text):     \"\"\"     Tokenizes English text from a string into a list of strings (tokens)     \"\"\"     return [tok.text for tok in spacy_en.tokenizer(text)]<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 <code>Field<\/code> \u0432 torchtext \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b. \u0412\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u044b <a href=\"https:\/\/github.com\/pytorch\/text\/blob\/master\/torchtext\/data\/field.py#L61\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u041c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>tokenize<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043f\u0440\u0438\u0447\u0435\u043c \u043d\u0435\u043c\u0435\u0446\u043a\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u043c<code> SRC<\/code> (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a), \u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u2014 \u043f\u043e\u043b\u0435\u043c <code>TRG<\/code> (\u0446\u0435\u043b\u044c). \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 <code>Field<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0442\u043e\u043a\u0435\u043d\u044b \u00ab\u043d\u0430\u0447\u0430\u043b\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00bb \u0438 \u00ab\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00bb \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u00abinit_token\u00bb \u0438 \u00abeos_token\u00bb. \u0412\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443.<\/p>\n<pre><code class=\"python\">SRC = Field(tokenize = tokenize_de,              init_token = '&lt;sos&gt;',              eos_token = '&lt;eos&gt;',              lower = True)  TRG = Field(tokenize = tokenize_en,              init_token = '&lt;sos&gt;',              eos_token = '&lt;eos&gt;',              lower = True)<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, &#8212; \u044d\u0442\u043e <a href=\"https:\/\/github.com\/multi30k\/dataset\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0440\u043f\u0443\u0441 Multi30k<\/a>. \u042d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 ~ 30 000 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u043c \u0438 \u0444\u0440\u0430\u043d\u0446\u0443\u0437\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0430\u0445, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 12-\u0442\u0438 \u0441\u043b\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p><code>exts<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u044f\u0437\u044b\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0438 \u0446\u0435\u043b\u0438 (\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c), \u0430 <code>fields<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0438 \u0446\u0435\u043b\u0438.<\/p>\n<pre><code>train_data, valid_data, test_data = Multi30k.splits(exts = ('.de', '.en'),                                                      fields = (SRC, TRG))<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432:<\/p>\n<pre><code>print(f\"Number of training examples: {len(train_data.examples)}\") print(f\"Number of validation examples: {len(valid_data.examples)}\") print(f\"Number of testing examples: {len(test_data.examples)}\")<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u043e:<\/p>\n<pre><code>print(vars(train_data.examples[0]))<\/code><\/pre>\n<p>\u0422\u043e\u0447\u043a\u0430 \u0441\u0442\u043e\u0438\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 (src), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u043e.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <em>\u0441\u043b\u043e\u0432\u0430\u0440\u044c<\/em> \u0434\u043b\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u043e\u0432. \u0421\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c (\u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c). \u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u043e\u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>min_freq<\/code>, \u043c\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u043a\u0435\u043d\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c 2 \u0440\u0430\u0437\u0430, \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0422\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043a\u0435\u043d <code>&lt;unk&gt;<\/code> (\u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e).<\/p>\n<pre><code>SRC.build_vocab(train_data, min_freq = 2) TRG.build_vocab(train_data, min_freq = 2)<\/code><\/pre>\n<pre><code>print(f\"Unique tokens in source (de) vocabulary: {len(SRC.vocab)}\") print(f\"Unique tokens in target (en) vocabulary: {len(TRG.vocab)}\")<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0421 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>src<\/code> (\u0442\u0435\u043d\u0437\u043e\u0440\u044b PyTorch, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043d\u0430\u0431\u043e\u0440 \u043e\u0446\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439) \u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>trg<\/code> (\u0442\u0435\u043d\u0437\u043e\u0440\u044b PyTorch, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043d\u0430\u0431\u043e\u0440 \u043e\u0446\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439). \u041e\u0446\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0447\u0443\u0434\u043b\u0438\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<p>\u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>torch.device<\/code>. \u042d\u0442\u0430 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c torchText, \u043a\u0443\u0434\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439: \u043d\u0430 GPU \u0438\u043b\u0438 \u043d\u0435\u0442? \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>torch.cuda.is_available()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0440\u043d\u0435\u0442 <code>True<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440. \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u0430\u0442\u0447 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0434\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u043a\u0430\u043a \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b torchText \u0441\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u0437\u0430 \u043d\u0430\u0441!<\/p>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>BucketIterator<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e <code>Iterator<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442\u044b \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432 \u043a\u0430\u043a \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c, \u0442\u0430\u043a \u0438 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<pre><code>device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')<\/code><\/pre>\n<pre><code>BATCH_SIZE = 128  train_iterator, valid_iterator, test_iterator = BucketIterator.splits(     (train_data, valid_data, test_data),      batch_size = BATCH_SIZE,      device = device)<\/code><\/pre>\n<h3>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Seq2Seq<\/h3>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u0442\u0440\u0435\u0445 \u0447\u0430\u0441\u0442\u0435\u0439. \u041a\u043e\u0434\u0435\u0440, \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c seq2seq, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434\u0435\u0440 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440, \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<h4>\u041a\u043e\u0434\u0435\u0440<\/h4>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u043e\u0434\u0435\u0440 \u2014 \u044d\u0442\u043e \u0434\u0432\u0443\u0445\u0441\u043b\u043e\u0439\u043d\u0430\u044f LSTM \u0441\u0435\u0442\u044c. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u043f\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f 4-\u0441\u043b\u043e\u0439\u043d\u0430\u044f LSTM \u0441\u0435\u0442\u044c, \u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0451\u0432 \u0434\u043e 2-\u0445. \u041c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u0443\u044e RNN \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0441 2 \u0434\u043e 4 \u0443\u0440\u043e\u0432\u043d\u0435\u0439.<\/p>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u043e\u0439 RNN \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"X\" alt=\"X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/774\/7c2\/d19\/7747c2d19f6990b22d5e6a6cca5be243.svg\">\u043f\u043e\u0441\u043b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 (\u043d\u0438\u0436\u043d\u0438\u0439) \u0441\u043b\u043e\u0439 RNN \u0438 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <img decoding=\"async\" class=\"formula inline\" source=\"H={h_1, h_2, ..., h_T}\" alt=\"H={h_1, h_2, ..., h_T}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cbb\/c74\/4f4\/cbbc744f4b1587a36474fc60f8b207e9.svg\">. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f RNN \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u044b\u0448\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c, \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u043e\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"h_t^{(1)} = \\text{EncoderRNN}^{(1)}(e(x_t), h_{t-1}^{(1)})\" alt=\"h_t^{(1)} = \\text{EncoderRNN}^{(1)}(e(x_t), h_{t-1}^{(1)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/474\/974\/651\/474974651d88c92d856dd0422e182e31.svg\" width=\"289\" height=\"31\"><\/p>\n<p>\u0421\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u043e\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"h_t^{(2)} = \\text{EncoderRNN}^{(2)}(h_t^{(1)}, h_{t-1}^{(2)})\" alt=\"h_t^{(2)} = \\text{EncoderRNN}^{(2)}(h_t^{(1)}, h_{t-1}^{(2)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/671\/07a\/647\/67107a647f950cfc556d54e424c7b90a.svg\" width=\"277\" height=\"31\"><\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u043e\u0439 RNN \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f <img decoding=\"async\" class=\"formula inline\" source=\"h_0^{(l)}\" alt=\"h_0^{(l)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e7b\/cbc\/c29\/e7bcbcc29c6e63cb640d3509dba602ac.svg\">, \u0430 \u0441\u0435\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f <img decoding=\"async\" class=\"formula inline\" source=\"z^{(l)}\" alt=\"z^{(l)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/529\/2fb\/3c4\/5292fb3c47c1fe7a9aad50e14b2a9fb6.svg\">.<\/p>\n<p>\u041d\u0435 \u0432\u0434\u0430\u0432\u0430\u044f\u0441\u044c \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e LSTM \u0441\u0435\u0442\u0438 (\u0441\u043c. <a href=\"https:\/\/colah.github.io\/posts\/2015-08-Understanding-LSTMs\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435), \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u044d\u0442\u0438 \u0441\u0435\u0442\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f RNN, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 <em>\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438<\/em> <img decoding=\"async\" class=\"formula inline\" source=\"c_t\" alt=\"c_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92a\/058\/a61\/92a058a6158791feb5313857bd721a1c.svg\">, \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} h_t &amp;= \\text{RNN}(e(x_t), h_{t-1})\\\\ (h_t, c_t) &amp;= \\text{LSTM}(e(x_t), h_{t-1}, c_{t-1}) \\end{align*}\" alt=\"\\begin{align*} h_t &amp;= \\text{RNN}(e(x_t), h_{t-1})\\\\ (h_t, c_t) &amp;= \\text{LSTM}(e(x_t), h_{t-1}, c_{t-1}) \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ebf\/391\/220\/ebf391220c66c63d26a5c2140de3a5bf.svg\" width=\"285\" height=\"49\"><\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043d\u044f\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"c_t\" alt=\"c_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e43\/ceb\/f4c\/e43cebf4cced9a4c7795358421196c1b.svg\">\u043a\u0430\u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0438\u043f \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041f\u043e\u0434\u043e\u0431\u043d\u043e <img decoding=\"async\" class=\"formula inline\" source=\"h_0^{(l)}\" alt=\"h_0^{(l)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/15a\/666\/128\/15a6661281fb55f93bd7975cc4c938b0.svg\">, \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"c_0^{(l)}\" alt=\"c_0^{(l)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e93\/3aa\/eab\/e933aaeab487792459cc0823e7846840.svg\">\u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u043c, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u043c \u043d\u0443\u043b\u044f\u043c\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0448 \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u044f\u0447\u0435\u0439\u043a\u0438, \u0442\u043e \u0435\u0441\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"z^{(l)} = (h_T^{(l)}, c_T^{(l)})\" alt=\"z^{(l)} = (h_T^{(l)}, c_T^{(l)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ee1\/0eb\/a5c\/ee10eba5ce218224ef48df63e531df26.svg\">.<\/p>\n<p>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u044f \u043d\u0430\u0448\u0438 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u044b\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0430 LSTM, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} (h_t^{(1)}, c_t^{(1)}) &amp;= \\text{EncoderLSTM}^{(1)}(e(x_t), (h_{t-1}^{(1)}, c_{t-1}^{(1)}))\\\\ (h_t^{(2)}, c_t^{(2)}) &amp;= \\text{EncoderLSTM}^{(2)}(h_t^{(1)}, (h_{t-1}^{(2)}, c_{t-1}^{(2)})) \\end{align*}\" alt=\"\\begin{align*} (h_t^{(1)}, c_t^{(1)}) &amp;= \\text{EncoderLSTM}^{(1)}(e(x_t), (h_{t-1}^{(1)}, c_{t-1}^{(1)}))\\\\ (h_t^{(2)}, c_t^{(2)}) &amp;= \\text{EncoderLSTM}^{(2)}(h_t^{(1)}, (h_{t-1}^{(2)}, c_{t-1}^{(2)})) \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/57e\/e8a\/574\/57ee8a574b9497ea576d84195cf1c004.svg\" width=\"414\" height=\"64\"><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u043e\u0439, \u0430 \u043d\u0435 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/787\/d31\/05f\/787d3105fd72b894337becc2540b4ac4.png\" width=\"527\" height=\"342\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u043e \u0432 \u043a\u043e\u0434\u0435, \u0441\u043e\u0437\u0434\u0430\u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>Encoder<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u043e\u0442<code> torch.nn.Module<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>super () .__ init __ ()<\/code> \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><code>input_dim<\/code> &#8212; \u0440\u0430\u0437\u043c\u0435\u0440 \/ \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c one-hot \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a. \u041e\u043d\u0438 \u0440\u0430\u0432\u043d\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e (\u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e) \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<\/li>\n<li>\n<p><code>emb_dim<\/code> &#8212; \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430. \u042d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 one-hot \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0432 \u043f\u043b\u043e\u0442\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 <code>emb_dim<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>hid_dim<\/code> &#8212; \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>n_layers<\/code> &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432 \u0432 RNN.<\/p>\n<\/li>\n<li>\n<p><code>dropout<\/code> &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u0434\u0440\u043e\u043f\u0430\u0443\u0442\u0430. \u042d\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 <a href=\"https:\/\/www.coursera.org\/lecture\/deep-neural-network\/understanding-dropout-YaGbR\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0438\u043c \u0437\u0434\u0435\u0441\u044c<\/a> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u0439 \u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0437\u0430\u043c\u0435\u0442\u043a\u0430\u0445. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0448\u0430\u0433 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u043b\u043e\u0432\u0430 &#8212;  \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043b\u043e\u0432 &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 RNN, \u0433\u0434\u0435 \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u044b. \u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0435 \u0441\u043b\u043e\u0432, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u044d\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438: <a href=\"https:\/\/monkeylearn.com\/blog\/word-embeddings-transform-text-numbers\/\" rel=\"noopener noreferrer nofollow\">1<\/a>, <a href=\"http:\/\/p.migdal.pl\/2017\/01\/06\/king-man-woman-queen-why.html\" rel=\"noopener noreferrer nofollow\">2<\/a>, <a href=\"http:\/\/mccormickml.com\/2016\/04\/19\/word2vec-tutorial-the-skip-gram-model\/\" rel=\"noopener noreferrer nofollow\">3<\/a>, <a href=\"http:\/\/mccormickml.com\/2017\/01\/11\/word2vec-tutorial-part-2-negative-sampling\/\" rel=\"noopener noreferrer nofollow\">4<\/a>.<\/p>\n<p>\u0421\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>nn.Embedding<\/code>, LSTM \u0441 <code>nn.LSTM<\/code> \u0438 \u0441\u043b\u043e\u0439 \u0434\u0440\u043e\u043f\u0430\u0443\u0442\u0430 \u0441 <code>nn.Dropout<\/code>. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043c. \u0432 <a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>dropout<\/code> \u0434\u043b\u044f LSTM \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u044f\u0437\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u043e\u0439 RNN, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438, \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0438\u0437 \u0443\u0440\u043e\u0432\u043d\u044f <img decoding=\"async\" class=\"formula inline\" source=\"l\" alt=\"l\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/359\/3e4\/13d\/3593e413dde71e1648c3484b354add72.svg\">, \u0438 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u043b\u044f \u0432\u0432\u043e\u0434 \u0441\u043b\u043e\u044f <img decoding=\"async\" class=\"formula inline\" source=\"l + 1\" alt=\"l + 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ae\/2f7\/dd3\/0ae2f7dd312243244ca2f5a18cb1e6a4.svg\">.<\/p>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>forward<\/code> \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 X, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u043b\u043e\u0442\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u043e\u044f <code>embedding<\/code>, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u0440\u043e\u043f\u0430\u0443\u0442. \u042d\u0442\u0438 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 RNN. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0441\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 RNN, \u043e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0435 \u0440\u0430\u0441\u0447\u0451\u0442 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043f\u043e \u0432\u0441\u0435\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438! \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 RNN \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 [\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438] (<a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html#torch.nn.LSTM\" rel=\"noopener noreferrer nofollow\">https:\/\/pytorch.org\/docs\/stable\/nn.html#torch.nn.LSTM<\/a>), \u0435\u0441\u043b\u0438 \u0432 RNN \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \/ \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u043e\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \/ \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u043a\u0430\u043a \u0442\u0435\u043d\u0437\u043e\u0440 \u0441 \u043d\u0443\u043b\u044f\u043c\u0438.<\/p>\n<p>RNN \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442: <code>outputs<\/code> (\u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430), <code>hidden<\/code> (\u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f, <img decoding=\"async\" class=\"formula inline\" source=\"h_T\" alt=\"h_T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/996\/ee1\/926\/996ee1926be010f3f58116dcb17bcdb5.svg\">, \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430) \u0438 <code>cell<\/code> (\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f, <img decoding=\"async\" class=\"formula inline\" source=\"c_T\" alt=\"c_T\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ab9\/617\/2c7\/ab96172c72646bceeab3f11408f4a959.svg\">, \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430).<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 (\u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430), <code>forward<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>hidden<\/code> \u0438 <code>cell<\/code>.<\/p>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0432 \u043a\u043e\u0434\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>n_directions<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 1, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 RNN (\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 3) \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c<code> n_directions<\/code> \u0440\u0430\u0432\u043d\u043e\u0435 2.<\/p>\n<pre><code class=\"python\">class Encoder(nn.Module):     def __init__(self, input_dim, emb_dim, hid_dim, n_layers, dropout):         super().__init__()                  self.hid_dim = hid_dim         self.n_layers = n_layers                  self.embedding = nn.Embedding(input_dim, emb_dim)                  self.rnn = nn.LSTM(emb_dim, hid_dim, n_layers, dropout = dropout)                  self.dropout = nn.Dropout(dropout)              def forward(self, src):                  #src = [src len, batch size]                  embedded = self.dropout(self.embedding(src))                  #embedded = [src len, batch size, emb dim]                  outputs, (hidden, cell) = self.rnn(embedded)                  #outputs = [src len, batch size, hid dim * n directions]         #hidden = [n layers * n directions, batch size, hid dim]         #cell = [n layers * n directions, batch size, hid dim]                  #outputs are always from the top hidden layer                  return hidden, cell<\/code><\/pre>\n<h4>\u0414\u0435\u043a\u043e\u0434\u0435\u0440<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430\u0448 \u0434\u0435\u043a\u043e\u0434\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u0438 \u043a\u043e\u0434\u0435\u0440, \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0443\u0445\u0441\u043b\u043e\u0439\u043d\u043e\u0439 LSTM \u0441\u0435\u0442\u044c\u044e (4-\u0445 \u0441\u043b\u043e\u0439\u043d\u043e\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435).<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/70c\/9c5\/97b\/70c9c597bb0dd57297386860de41a234.png\" width=\"351\" height=\"502\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Decoder<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u0438\u043d \u0448\u0430\u0433 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0434\u0438\u043d \u0442\u043e\u043a\u0435\u043d \u0437\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043b\u043e\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 <img decoding=\"async\" class=\"formula inline\" source=\" (s_{t-1}^{(1)}, c_{t-1}^{(1)})\" alt=\" (s_{t-1}^{(1)}, c_{t-1}^{(1)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/12a\/5dc\/2ca\/12a5dc2cab72483e36984ccbe9893d62.svg\">\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 LSTM \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u043c <img decoding=\"async\" class=\"formula inline\" source=\"y_t\" alt=\"y_t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/971\/dbb\/08e\/971dbb08e0f6b9a50062226c5d11d4d7.svg\">, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"(s_t^{(1)}, c_t^{(1)})\" alt=\"(s_t^{(1)}, c_t^{(1)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d4a\/6e3\/27b\/d4a6e327b47421f44e5bf0ea6a35dbfd.svg\">. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043b\u043e\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u0441\u043b\u043e\u044f \u043d\u0438\u0436\u0435, <img decoding=\"async\" class=\"formula inline\" source=\"s_t^{(l-1)}\" alt=\"s_t^{(l-1)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a8b\/fa7\/d25\/a8bfa7d25ebc159d707dcfd80864df05.svg\">, \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0435\u043a \u0438\u0437 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043b\u043e\u044f, <img decoding=\"async\" class=\"formula inline\" source=\"(s_{t-1}^{(l)}, c_{t-1}^{(l)})\" alt=\"(s_{t-1}^{(l)}, c_{t-1}^{(l)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/033\/252\/066\/033252066575f29851529bac8d98fff7.svg\">. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c, \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u043d\u0430 \u0442\u0435, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} (s_t^{(1)}, c_t^{(1)}) = \\text{DecoderLSTM}^{(1)}(d(y_t), (s_{t-1}^{(1)}, c_{t-1}^{(1)}))\\\\ (s_t^{(2)}, c_t^{(2)}) = \\text{DecoderLSTM}^{(2)}(s_t^{(1)}, (s_{t-1}^{(2)}, c_{t-1}^{(2)})) \\end{align*}\" alt=\"\\begin{align*} (s_t^{(1)}, c_t^{(1)}) = \\text{DecoderLSTM}^{(1)}(d(y_t), (s_{t-1}^{(1)}, c_{t-1}^{(1)}))\\\\ (s_t^{(2)}, c_t^{(2)}) = \\text{DecoderLSTM}^{(2)}(s_t^{(1)}, (s_{t-1}^{(2)}, c_{t-1}^{(2)})) \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9dc\/3a8\/d01\/9dc3a8d01d1aa21a9d436f5047eb2d0a.svg\" width=\"408\" height=\"64\"><\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0435\u043a \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u043d\u0430\u0448\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u044f\u0447\u0435\u0435\u043a \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0443\u0440\u043e\u0432\u043d\u044f, \u0442.\u0435. <img decoding=\"async\" class=\"formula inline\" source=\"(s_0^{(l)},c_0^{(l)})=z^{(l)}=(h_T^{(l)},c_T^{(l)})\" alt=\"(s_0^{(l)},c_0^{(l)})=z^{(l)}=(h_T^{(l)},c_T^{(l)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a79\/2be\/327\/a792be32714439671d0c677c70aff0c2.svg\">.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f RNN <img decoding=\"async\" class=\"formula inline\" source=\"s_t^{(L)}\" alt=\"s_t^{(L)}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a58\/8c9\/233\/a588c9233fc8f3c7a36fd74b73853dda.svg\">, \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 f, \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 (\u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439) \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y}_{t+1}\" alt=\"\\hat{y}_{t+1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2d9\/e69\/356\/2d9e693569574f4e8aaadca7662d6a9d.svg\">.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\hat{y}_{t+1} = f(s_t^{(L)})\" alt=\"\\hat{y}_{t+1} = f(s_t^{(L)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/437\/d4d\/eea\/437d4deeaf41a12fdaab1c51df88dad2.svg\" width=\"118\" height=\"29\"><\/p>\n<p>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0443 <code>Encoder<\/code>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <code>output_dim<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439\/\u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0441\u043b\u043e\u0439 <code>Linear<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>forward<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0435\u043a. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0442\u043e\u043a\u0435\u043d \u0437\u0430 \u0440\u0430\u0437, \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041c\u044b \u00ab\u0440\u0430\u0437\u0436\u0438\u043c\u0430\u0435\u043c\u00bb \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b 1. \u0417\u0430\u0442\u0435\u043c, \u043a\u0430\u043a \u0438 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435, \u043c\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0440\u043e\u043f\u0430\u0443\u0442. \u042d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 RNN \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u044f\u0447\u0435\u0435\u043a. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u00ab\u0432\u044b\u0432\u043e\u0434\u00bb (\u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f RNN), \u043d\u043e\u0432\u043e\u0435 \u00ab\u0441\u043a\u0440\u044b\u0442\u043e\u0435\u00bb \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c\u043e\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430) \u0438 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u00ab\u044f\u0447\u0435\u0439\u043a\u0438\u00bb (\u0442\u0430\u043a\u0436\u0435 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u0441\u043b\u043e\u0439, \u0443\u043b\u043e\u0436\u0435\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430). \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u00ab\u0432\u044b\u0432\u043e\u0434\u00bb (\u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0441\u043b\u043e\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u00ab\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435\u00bb \u0441\u043b\u043e\u0432\u043e. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u00ab\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435\u00bb \u0441\u043b\u043e\u0432\u043e, \u043d\u043e\u0432\u043e\u0435 \u00ab\u0441\u043a\u0440\u044b\u0442\u043e\u0435\u00bb \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u00ab\u044f\u0447\u0435\u0439\u043a\u0438\u00bb.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0442.\u043a. \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043b\u0438\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0432\u043d\u0430 1, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>nn.LSTMCell<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>nn.LSTM<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. nn.LSTMCell &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0434\u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0430, \u0430 nn.LSTM &#8212; \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044f\u0447\u0435\u0435\u043a. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>nn.LSTMCell<\/code> \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u043b\u043e \u0431\u044b, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u00ab\u0440\u0430\u0437\u0436\u0438\u043c\u0430\u0442\u044c\u00bb \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d <code>nn.LSTMCell<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u0438, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439<code> nn .LSTMCell<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430. \u0412\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043c\u0435\u043d\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c \u2014 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e <code>nn.LSTM<\/code>.<\/p>\n<pre><code class=\"python\">class Decoder(nn.Module):     def __init__(self, output_dim, emb_dim, hid_dim, n_layers, dropout):         super().__init__()                  self.output_dim = output_dim         self.hid_dim = hid_dim         self.n_layers = n_layers                  self.embedding = nn.Embedding(output_dim, emb_dim)                  self.rnn = nn.LSTM(emb_dim, hid_dim, n_layers, dropout = dropout)                  self.fc_out = nn.Linear(hid_dim, output_dim)                  self.dropout = nn.Dropout(dropout)              def forward(self, input, hidden, cell):                  #input = [batch size]         #hidden = [n layers * n directions, batch size, hid dim]         #cell = [n layers * n directions, batch size, hid dim]                  #n directions in the decoder will both always be 1, therefore:         #hidden = [n layers, batch size, hid dim]         #context = [n layers, batch size, hid dim]                  input = input.unsqueeze(0)                  #input = [1, batch size]                  embedded = self.dropout(self.embedding(input))                  #embedded = [1, batch size, emb dim]                          output, (hidden, cell) = self.rnn(embedded, (hidden, cell))                  #output = [seq len, batch size, hid dim * n directions]         #hidden = [n layers * n directions, batch size, hid dim]         #cell = [n layers * n directions, batch size, hid dim]                  #seq len and n directions will always be 1 in the decoder, therefore:         #output = [1, batch size, hid dim]         #hidden = [n layers, batch size, hid dim]         #cell = [n layers, batch size, hid dim]                  prediction = self.fc_out(output.squeeze(0))                  #prediction = [batch size, output dim]                  return prediction, hidden, cell<\/code><\/pre>\n<h4>Seq2Seq<\/h4>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c seq2seq. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e\/\u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0448\u0430 \u043f\u043e\u043b\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2ad\/ec4\/ad4\/2adec4ad407d0554bf5a2a1277bbd204.png\" width=\"808\" height=\"502\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c <code>Seq2Seq<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u0435\u0432\u0430\u0439\u0441 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u043d\u0430 GPU, \u0435\u0441\u043b\u0438 \u043e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432 \u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 (\u0438 \u044f\u0447\u0435\u0439\u043a\u0438) \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0440\u0430\u0432\u043d\u044b \u0432 <code>Encoder<\/code> \u0438 <code>Decoder<\/code>. \u042d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0430\u043a, \u0438 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0435\u0432 \u0438\u043b\u0438 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 sequence-to-sequence. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0451\u0432 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u043c\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 2 \u0441\u043b\u043e\u044f, \u0430 \u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 1, \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c? \u0423\u0441\u0440\u0435\u0434\u043d\u044f\u0442\u044c \u043b\u0438 \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u043c? \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043b\u0438 \u043e\u0431\u0430 \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0441\u043b\u043e\u0439? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f? \u0418 \u0442.\u043f.<\/p>\n<p>\u041d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>forward<\/code> \u0431\u0435\u0440\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c<\/code>. \u041f\u0440\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u0437\u044f\u0442 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y}_{t+1}=f(s_t^{(L)})\" alt=\"\\hat{y}_{t+1}=f(s_t^{(L)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/83b\/58a\/145\/83b58a1453546484cea4b1fa4347e4d0.svg\">. \u0421 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u0440\u0430\u0432\u043d\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0443\u043c\u0443 \u0432\u044b\u0448\u0435 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0443 (<code>teacher_forcing_ratio<\/code>), \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439\/\u0446\u0435\u043b\u0435\u043e\u0432\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e <code>1 - teacher_forcing_ratio<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0442\u043e\u043a\u0435\u043d\u0443 \u0432 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>forward<\/code>, &#8212; \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0435\u043d\u0437\u043e\u0440<code> output<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{Y}\" alt=\"\\hat{Y}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/396\/883\/fe2\/396883fe2cf85534d5e302938d5e70dd.svg\">.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, <code>src<\/code>, \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0435\u043a.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0432\u0445\u043e\u0434\u043e\u043c \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043a\u0435\u043d \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (<code>&lt;sos&gt;<\/code>). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0442\u0435\u043d\u0437\u043e\u0440\u0443 <code>trg<\/code> \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043a\u0435\u043d <code>&lt;sos&gt;<\/code> (\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0438 <code>init_token<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u043e\u043b\u0435 <code>TRG<\/code>), \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"y_1\" alt=\"y_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/843\/82a\/41d\/84382a41db5758c646f9e1e206735327.svg\">, \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u044f \u0435\u0433\u043e. \u041c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043d\u0430\u0448\u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f (<code>max_len<\/code>), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0442\u043e\u043a\u0435\u043d, \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440, &#8212; \u044d\u0442\u043e \u0442\u043e\u043a\u0435\u043d \u043f\u0435\u0440\u0435\u0434 \u0442\u043e\u043a\u0435\u043d\u043e\u043c <code>&lt;eos&gt;<\/code> &#8212; \u0442\u043e\u043a\u0435\u043d <code>&lt;eos&gt;<\/code> \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440.<\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0446\u0438\u043a\u043b\u0430 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"(y_t, s_{t-1}, c_{t-1})\" alt=\"(y_t, s_{t-1}, c_{t-1})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/74a\/492\/93c\/74a49293cbe6dd7265bd39fce8e42ea6.svg\">\u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"(\\hat{y}{t+1}, s{t}, c_{t})\" alt=\"(\\hat{y}{t+1}, s{t}, c_{t})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1e5\/80b\/97f\/1e580b97fa38275a113015639b67a949.svg\">\u0438\u0437 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y}_{t+1} \" alt=\"\\hat{y}_{t+1} \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a18\/830\/0c7\/a188300c7ec16a23f0f2574a0499dfa2.svg\">\/<code>output<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0442\u0435\u043d\u0437\u043e\u0440\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{Y}\" alt=\"\\hat{Y}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0af\/47a\/dbf\/0af47adbff83b20067a045d5e6ade931.svg\">\/<code>outputs<\/code><\/p>\n<\/li>\n<li>\n<p>\u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c<\/p>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>\u0432\u0432\u043e\u0434<\/code> &#8212; \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, <img decoding=\"async\" class=\"formula inline\" source=\"y_{t+1}\" alt=\"y_{t+1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7a9\/752\/da0\/7a9752da0a04d6d8ba8854ff0c7c7a74.svg\">\/<code>trg[t]<\/code><\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0430\u0435\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u043e <code>\u0432\u0432\u043e\u0434<\/code> &#8212; \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u043a\u0435\u043d \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438,  <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y}_{t+1}\" alt=\"\\hat{y}_{t+1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/769\/932\/13c\/76993213c32c5ecde9964162e6bfbf5b.svg\">\/<code>top1<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043d\u0437\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 <code>argmax<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0448 \u0442\u0435\u043d\u0437\u043e\u0440, \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{Y}\" alt=\"\\hat{Y}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/699\/302\/acc\/699302acc3df21f3dfca1712ee8ad7b7.svg\">\/<code>outputs<\/code>.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u043d\u0430\u0448 \u0446\u0438\u043a\u043b \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 1, \u043d\u0435 \u0441 0. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043d\u0443\u043b\u0435\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430 &#171;\u0432\u044b\u0445\u043e\u0434\u043e\u0432&#187; \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043d\u0443\u043b\u0438. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u0448\u0438 <code>trg<\/code> \u0438<code> output<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} \\text{trg} = [&lt;sos&gt;, &amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [0, &amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" alt=\"\\begin{align*} \\text{trg} = [&lt;sos&gt;, &amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [0, &amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/367\/e08\/d99\/367e08d9979bd455e7daf2cbd43c363a.svg\" width=\"294\" height=\"50\"><\/p>\n<p>\u041f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u0438, \u043c\u044b \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} \\text{trg} = [&amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [&amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" alt=\"\\begin{align*} \\text{trg} = [&amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [&amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/83e\/2c3\/b83\/83e2c3b83ce5d55f6e99b77d4c7210e1.svg\" width=\"254\" height=\"50\"><\/p>\n<pre><code class=\"python\">class Seq2Seq(nn.Module):     def __init__(self, encoder, decoder, device):         super().__init__()                  self.encoder = encoder         self.decoder = decoder         self.device = device                  assert encoder.hid_dim == decoder.hid_dim, \\             \"Hidden dimensions of encoder and decoder must be equal!\"         assert encoder.n_layers == decoder.n_layers, \\             \"Encoder and decoder must have equal number of layers!\"              def forward(self, src, trg, teacher_forcing_ratio = 0.5):                  #src = [src len, batch size]         #trg = [trg len, batch size]         #teacher_forcing_ratio is probability to use teacher forcing         #e.g. if teacher_forcing_ratio is 0.75 we use ground-truth inputs 75% of the time                  batch_size = trg.shape[1]         trg_len = trg.shape[0]         trg_vocab_size = self.decoder.output_dim                  #tensor to store decoder outputs         outputs = torch.zeros(trg_len, batch_size, trg_vocab_size).to(self.device)                  #last hidden state of the encoder is used as the initial hidden state of the decoder         hidden, cell = self.encoder(src)                  #first input to the decoder is the &lt;sos&gt; tokens         input = trg[0,:]                  for t in range(1, trg_len):                          #insert input token embedding, previous hidden and previous cell states             #receive output tensor (predictions) and new hidden and cell states             output, hidden, cell = self.decoder(input, hidden, cell)                          #place predictions in a tensor holding predictions for each token             outputs[t] = output                          #decide if we are going to use teacher forcing or not             teacher_force = random.random() &lt; teacher_forcing_ratio                          #get the highest predicted token from our predictions             top1 = output.argmax(1)                           #if teacher forcing, use actual next token as next input             #if not, use predicted token             input = trg[t] if teacher_force else top1                  return outputs<\/code><\/pre>\n<h2>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Seq2Seq<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0433\u043e\u0442\u043e\u0432\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0435\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u041a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0432\u043e\u0434\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u0420\u0430\u0437\u043c\u0435\u0440\u044b \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0438 \u0434\u0440\u043e\u043f\u0430\u0443\u0442\u0430 \u0434\u043b\u044f \u043a\u043e\u0434\u0435\u0440\u0430 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438, \u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0451\u0432 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u0434\u0435\u0440, \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0438 \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c Seq2Seq, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432 <code>device<\/code>.<\/p>\n<pre><code class=\"python\">INPUT_DIM = len(SRC.vocab) OUTPUT_DIM = len(TRG.vocab) ENC_EMB_DIM = 256 DEC_EMB_DIM = 256 HID_DIM = 512 N_LAYERS = 2 ENC_DROPOUT = 0.5 DEC_DROPOUT = 0.5  enc = Encoder(INPUT_DIM, ENC_EMB_DIM, HID_DIM, N_LAYERS, ENC_DROPOUT) dec = Decoder(OUTPUT_DIM, DEC_EMB_DIM, HID_DIM, N_LAYERS, DEC_DROPOUT)  model = Seq2Seq(enc, dec, device).to(device)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u0441\u0430 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u0432\u0441\u0435 \u0432\u0435\u0441\u0430 \u0438\u0437 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 -0.08 \u0438 +0.08, \u0442.\u0435. <img decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{U}(-0.08, 0.08)\" alt=\"\\mathcal{U}(-0.08, 0.08)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fa7\/caa\/7aa\/fa7caa7aa13ea637c58e16ee9e0670de.svg\">.<\/p>\n<p>\u041c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u0441\u0430 \u0432 PyTorch, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>apply<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043a \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>apply<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0441\u043e\u0432 <code>init_weights<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u044b \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0445 \u0438\u0437 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>nn.init.uniform_<\/code>.<\/p>\n<pre><code class=\"python\">def init_weights(m):     for name, param in m.named_parameters():         nn.init.uniform_(param.data, -0.08, 0.08)          model.apply(init_weights)<\/code><\/pre>\n<p>\u041c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<pre><code class=\"python\">def count_parameters(model):     return sum(p.numel() for p in model.parameters() if p.requires_grad)  print(f'The model has {count_parameters(model):,} trainable parameters')<\/code><\/pre>\n<p>\u041c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"http:\/\/ruder.io\/optimizing-gradient-descent\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u0445. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 <code>Adam<\/code>.<\/p>\n<pre><code class=\"python\">optimizer = optim.Adam(model.parameters())<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0442\u0435\u0440\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>CrossEntropyLoss<\/code> \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u0430\u043a log softmax, \u0442\u0430\u043a \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d, \u043e\u0434\u043d\u0430\u043a\u043e, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u043e\u043a\u0435\u043d\u0430 <code>&lt;pad&gt;<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>ignore_index<\/code>, \u043c\u044b \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u044e \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u043e\u043a\u0435\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0440\u043a\u0435\u0440\u043e\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <code>&lt;pad&gt;<\/code>.<\/p>\n<pre><code class=\"python\">TRG_PAD_IDX = TRG.vocab.stoi[TRG.pad_token]  criterion = nn.CrossEntropyLoss(ignore_index = TRG_PAD_IDX)<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0448 \u0446\u0438\u043a\u043b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u00ab\u0440\u0435\u0436\u0438\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f\u00bb \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>model.train ()<\/code>. \u042d\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442 \u0434\u0440\u043e\u043f\u0430\u0443\u0442 (\u0438 \u043f\u0430\u043a\u0435\u0442\u043d\u0443\u044e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c), \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0448 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041a\u0430\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u043d\u0430\u0448 \u0446\u0438\u043a\u043b \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 1, \u0430 \u043d\u0435 \u0441 0. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043d\u0443\u043b\u0435\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430 <code>output<\/code> \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043d\u0443\u043b\u0438. \u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0438 <code>trg<\/code> \u0438 <code>output<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} \\text{trg} = [&lt;sos&gt;, &amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [0, &amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" alt=\"\\begin{align*} \\text{trg} = [&lt;sos&gt;, &amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [0, &amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bd0\/7c7\/080\/bd07c7080c007a80e441506b549c304a.svg\" width=\"294\" height=\"50\"><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u0438, \u043c\u044b \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{align*} \\text{trg} = [&amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [&amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" alt=\"\\begin{align*} \\text{trg} = [&amp;y_1, y_2, y_3, &lt;eos&gt;]\\\\ \\text{outputs} = [&amp;\\hat{y}_1, \\hat{y}_2, \\hat{y}_3, &lt;eos&gt;] \\end{align*}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5cb\/aff\/91b\/5cbaff91b09db526b2c63e32968e22fd.svg\" width=\"254\" height=\"50\"><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430, <img decoding=\"async\" class=\"formula inline\" source=\" \" alt=\" \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e69\/c36\/c9d\/e69c36c9de4cce43ec47a30c94652a33.svg\">X \u0438 <img decoding=\"async\" class=\"formula inline\" source=\"Y\" alt=\"Y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/52b\/881\/f2e\/52b881f2e716089b536f784b812de3d2.svg\"><\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{Y}\" alt=\"\\hat{Y}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/272\/735\/fd8\/272735fd81d513e773fc3c0893ac3b76.svg\"><\/p>\n<\/li>\n<li>\n<p>\u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0432\u0443\u043c\u0435\u0440\u044b\u043d\u043c \u0432\u0445\u043e\u0434\u043e\u043c \u0441 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u043c \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0432\u044b\u0445\u043e\u0434\u043e\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e <code>\u0441\u043f\u0440\u044f\u043c\u0438\u0442\u044c<\/code> \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>.view<\/code><\/p>\n<ul>\n<li>\n<p>\u043c\u044b \u043e\u0442\u0440\u0435\u0437\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0445 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432, \u043a\u0430\u043a \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e \u0432\u044b\u0448\u0435<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e<code>loss.backward ()<\/code><\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0440\u0435\u0437\u0430\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0432\u0437\u0440\u044b\u0432 (\u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 RNN)<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0448\u0430\u0433 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u0442\u0435\u0440\u0438, \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u0432\u0441\u0435\u043c \u0431\u0430\u0442\u0447\u0430\u043c.<\/p>\n<pre><code class=\"python\">def train(model, iterator, optimizer, criterion, clip):          model.train()          epoch_loss = 0          for i, batch in enumerate(iterator):                  src = batch.src         trg = batch.trg                  optimizer.zero_grad()                  output = model(src, trg)                  #trg = [trg len, batch size]         #output = [trg len, batch size, output dim]                  output_dim = output.shape[-1]                  output = output[1:].view(-1, output_dim)         trg = trg[1:].view(-1)                  #trg = [(trg len - 1) * batch size]         #output = [(trg len - 1) * batch size, output dim]                  loss = criterion(output, trg)                  loss.backward()                  torch.nn.utils.clip_grad_norm_(model.parameters(), clip)                  optimizer.step()                  epoch_loss += loss.item()              return epoch_loss \/ len(iterator)<\/code><\/pre>\n<p>\u041d\u0430\u0448 \u0446\u0438\u043a\u043b \u043e\u0446\u0435\u043d\u043a\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043d\u0430\u0448\u0435\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0441\u0435\u0447\u043a\u0438.<\/p>\n<p>\u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0440\u0435\u0436\u0438\u043c \u043e\u0446\u0435\u043d\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>model.eval()<\/code>. \u042d\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442 \u0434\u0440\u043e\u043f\u0430\u0443\u0442\u0438 (\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0430\u0440\u0442\u0438\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f).<\/p>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u043b\u043e\u043a <code>with torch.no_grad()<\/code>, \u0447\u0442\u043e\u0431\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043d\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<p>\u0426\u0438\u043a\u043b \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d (\u0431\u0435\u0437 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432), \u043e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u0440\u0438\u043d\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0442\u043e, \u043a\u0430\u043a \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0438.<\/p>\n<pre><code class=\"python\">def evaluate(model, iterator, criterion):          model.eval()          epoch_loss = 0          with torch.no_grad():              for i, batch in enumerate(iterator):              src = batch.src             trg = batch.trg              output = model(src, trg, 0) #turn off teacher forcing              #trg = [trg len, batch size]             #output = [trg len, batch size, output dim]              output_dim = output.shape[-1]                          output = output[1:].view(-1, output_dim)             trg = trg[1:].view(-1)              #trg = [(trg len - 1) * batch size]             #output = [(trg len - 1) * batch size, output dim]              loss = criterion(output, trg)                          epoch_loss += loss.item()              return epoch_loss \/ len(iterator)<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043d\u0430\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u043f\u043e\u0445\u0430.<\/p>\n<pre><code class=\"python\">def epoch_time(start_time, end_time):     elapsed_time = end_time - start_time     elapsed_mins = int(elapsed_time \/ 60)     elapsed_secs = int(elapsed_time - (elapsed_mins * 60))     return elapsed_mins, elapsed_secs<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438!<\/p>\n<p>\u0412 \u043a\u0430\u0436\u0434\u0443\u044e \u044d\u043f\u043e\u0445\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0430 \u043b\u0438 \u043d\u0430\u0448\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u043e\u0442\u0435\u0440\u044c \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443, \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0449\u0443\u044e \u043b\u0443\u0447\u0448\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 \u043f\u0440\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 <code>state_dict<\/code> \u0432 PyTorch). \u0417\u0430\u0442\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u043e\u0442\u0435\u0440\u044c \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0442\u0435\u0440\u0438, \u0438 <code>\u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/code> (perplexity) \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043f\u043e\u0445\u0435. \u041b\u0435\u0433\u0447\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 <code>\u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/code>, \u0447\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u044c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0446\u0438\u0444\u0440\u044b \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<pre><code class=\"python\">N_EPOCHS = 10 CLIP = 1  best_valid_loss = float('inf')  for epoch in range(N_EPOCHS):          start_time = time.time()          train_loss = train(model, train_iterator, optimizer, criterion, CLIP)     valid_loss = evaluate(model, valid_iterator, criterion)          end_time = time.time()          epoch_mins, epoch_secs = epoch_time(start_time, end_time)          if valid_loss &lt; best_valid_loss:         best_valid_loss = valid_loss         torch.save(model.state_dict(), 'tut1-model.pt')          print(f'Epoch: {epoch+1:02} | Time: {epoch_mins}m {epoch_secs}s')     print(f'\\tTrain Loss: {train_loss:.3f} | Train PPL: {math.exp(train_loss):7.3f}')     print(f'\\t Val. Loss: {valid_loss:.3f} |  Val. PPL: {math.exp(valid_loss):7.3f}')<\/code><\/pre>\n<p>\u041c\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (<code>state_dict<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435, \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438\u0445 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435.<\/p>\n<pre><code class=\"python\">model.load_state_dict(torch.load('tut1-model.pt'))  test_loss = evaluate(model, test_iterator, criterion)  print(f'| Test Loss: {test_loss:.3f} | Test PPL: {math.exp(test_loss):7.3f} |')<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/567142\/\"> https:\/\/habr.com\/ru\/post\/567142\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 sequence-to-sequence (seq2seq) \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/pytorch\/pytorch\" rel=\"noopener noreferrer nofollow\">PyTorch<\/a> 1.8, <a href=\"https:\/\/github.com\/pytorch\/text\" rel=\"noopener noreferrer nofollow\">torchtext<\/a> 0.9 \u0438 <a href=\"https:\/\/spacy.io\/\" rel=\"noopener noreferrer nofollow\">spaCy<\/a> 3.0, \u043f\u043e\u0434 Python 3.8. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0432 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435: \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e. <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d \u0444\u0440\u0435\u0439\u043c\u0432\u0451\u0440\u043a PyTorch, \u0442.\u043a. \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0441\u043c\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 TensorFlow. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f PyTorch \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u0443\u044e \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e TensorFlow (\u0441\u043c. \u043d\u0435\u0434\u0430\u0432\u043d\u0438\u0439 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/company\/ru_mts\/blog\/565456\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u0442<\/a>).<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b\u044b<\/h3>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c 4-\u0433\u043e, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u0440\u043e\u0434\u0438\u0432\u0448\u0435\u0439 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u043e\u0441\u0442\u043e\u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432 \u0432\u0430\u043c \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f, \u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u0431\u0443\u0434\u0435\u0442 \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0443\u044e \u0438 \u0440\u0443\u0441\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u0438 jupyter notebook.<\/p>\n<ul>\n<li>\n<p>1 &#8212; Sequence to Sequence Learning with Neural Networks<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043c\u043e\u0434\u0435\u043b\u044c\u044e seq2seq \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyTorch \u0438 torchtext. \u041c\u044b \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u0441\u043d\u043e\u0432 \u0441\u0435\u0442\u0435\u0439 seq2seq \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u0432\u0449\u0438\u043a (\u043a\u043e\u0434\u0435\u0440-\u0434\u0435\u043a\u043e\u0434\u0435\u0440), \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 PyTorch \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c torchtext \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0442\u044f\u0436\u0435\u043b\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u0430. \u0421\u0430\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.3215\" rel=\"noopener noreferrer nofollow\">Sequence to Sequence Learning with Neural Networks<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0439\u043d\u044b\u0435 LSTM \u0441\u0435\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>2 &#8212; Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u0438 seq2seq, \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043d\u0430\u0448\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u044f\u0445 \u043e PyTorch \u0438 torchtext, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0435\u0448\u0435\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0436\u0430\u0442\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0430\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u0434\u0435\u0440\u0430-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430. \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438  <a href=\"https:\/\/arxiv.org\/abs\/1406.1078\" rel=\"noopener noreferrer nofollow\">Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 GRU \u0441\u0435\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>3 &#8212; Neural Machine Translation by Jointly Learning to Align and Translate<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u0438\u0435\u043c \u043a\u0430\u043a \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.0473\" rel=\"noopener noreferrer nofollow\">Neural Machine Translation by Jointly Learning to Align and Translate<\/a>. \u042d\u0442\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u0436\u0430\u0442\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0443 \u00ab\u043e\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f\u00bb \u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0443\u043c\u043c\u0430\u043c\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043a\u043e\u0434\u0435\u0440\u0430. \u0412\u0435\u0441\u0430 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u043c\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041a\u0430\u043a \u0438\u0442\u043e\u0433, \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0443\u0447\u0438\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>4 &#8212; \u0423\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u041c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 BLEU<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043c\u043e\u0434\u0435\u043b\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 <em>\u0443\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> \u0438 <em>\u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0443<\/em>. \u042d\u0442\u0438 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 (NLP). \u0423\u043f\u043b\u043e\u0442\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e. \u041c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435\\\u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u043c\u0443, \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u0432 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0443 BLEU \u043f\u043e \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p>5 &#8212; Convolutional Sequence to Sequence Learning<\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043e\u0442\u043e\u0439\u0434\u0451\u043c \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 seq2seq \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438. \u0422\u043e \u0435\u0441\u0442\u044c, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e, \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0451. \u0421\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c <a href=\"https:\/\/arxiv.org\/abs\/1705.03122\" rel=\"noopener noreferrer nofollow\">Convolutional Sequence to Sequence<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0435\u0432 \u043a\u0430\u043a \u0432 \u043a\u043e\u0434\u0435\u0440\u0435, \u0442\u0430\u043a \u0438 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u0441 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. <\/p>\n<\/li>\n<li>\n<p>6 &#8212; Attention Is All You Need<\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0435 \u0431\u0430\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c Transformer \u0438\u0437 <a href=\"https:\/\/arxiv.org\/abs\/1706.03762\" rel=\"noopener noreferrer nofollow\">Attention Is All You Need<\/a>. \u042d\u0442\u0430 \u0441\u0435\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0441 \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 &#171;\u043c\u043d\u043e\u0433\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f&#187;. \u041a\u043e\u0434\u0435\u0440 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u0434\u0441\u043b\u043e\u0435\u0432 &#171;\u043c\u043d\u043e\u0433\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f&#187; \u0438 Positionwise Feedforward. \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0437\u043d\u0430\u043d\u0438\u0439. <\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u043f\u0438\u0441\u043e\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u0443\u0447\u0435\u0431\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c\u0438.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/spro\/practical-pytorch\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/spro\/practical-pytorch<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/keon\/seq2seq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/keon\/seq2seq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pengshuang\/CNN-Seq2Seq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/pengshuang\/CNN-Seq2Seq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pytorch\/fairseq\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/pytorch\/fairseq<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/jadore801120\/attention-is-all-you-need-pytorch\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/jadore801120\/attention-is-all-you-need-pytorch<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/nlp.seas.harvard.edu\/2018\/04\/03\/attention.html\" rel=\"noopener noreferrer nofollow\">http:\/\/nlp.seas.harvard.edu\/2018\/04\/03\/attention.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.analyticsvidhya.com\/blog\/2019\/06\/understanding-transformers-nlp-state-of-the-art-models\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.analyticsvidhya.com\/blog\/2019\/06\/understanding-transformers-nlp-state-of-the-art-models\/<\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0438\u043a\u043e\u043b\u0435\u043d\u043a\u043e \u0421.\u0418., \u041a\u0430\u0434\u0443\u0440\u0438\u043d \u0410., \u0410\u0440\u0445\u0430\u043d\u0433\u0435\u043b\u044c\u0441\u043a\u0430\u044f \u0415.\u0412. \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0432 \u043c\u0438\u0440 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439. \u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433: \u041f\u0438\u0442\u0435\u0440. 2020. 481 \u0441.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0443\u0434\u0444\u0435\u043b\u043b\u043e\u0443 \u042f., \u0411\u0435\u043d\u0434\u0436\u0438\u043e \u0418., \u041a\u0443\u0440\u0432\u0438\u043b\u043b\u044c \u0410. \u0413\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \u041c\u043e\u0441\u043a\u0432\u0430: \u0414\u041c\u041a-\u041f\u0440\u0435\u0441\u0441. 2018. 652 \u0441.<\/p>\n<\/li>\n<\/ul>\n<h2>1 &#8212; Sequence to Sequence Learning with Neural Networks<\/h2>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u0434\u0430 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432 Google Colab):<\/p>\n<p> <a href=\"https:\/\/github.com\/bentrevett\/pytorch-seq2seq\/blob\/master\/1%20-%20Sequence%20to%20Sequence%20Learning%20with%20Neural%20Networks.ipynb\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f jupyter notebook<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/vasiliyeskin\/bentrevett-pytorch-seq2seq_ru\/blob\/master\/1%20-%20Sequence%20to%20Sequence%20Learning%20with%20Neural%20Networks.ipynb\" rel=\"noopener noreferrer nofollow\">\u0420\u0443\u0441\u0441\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f jupyter notebook<\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0438\u0437 \u0441\u0435\u0440\u0438\u0438 \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f PyTorch \u0438 torchtext. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u0432 \u0441 \u043d\u0435\u043c\u0435\u0446\u043a\u043e\u0433\u043e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u043a \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0443\u044e \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u044f\u0437\u044b\u043a\u0435, \u0438\u043b\u0438 \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0442\u0440\u0435\u0442\u0438\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0435\u043b\u043a\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u043a\u043b\u0435\u043e\u0442\u0438\u0434\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043c\u0420\u041d\u041a (<a href=\"https:\/\/deepmind.com\/blog\/article\/alphafold-a-solution-to-a-50-year-old-grand-challenge-in-biology\" rel=\"noopener noreferrer nofollow\">AlphaFold<\/a>).<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 seq2seq \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/arxiv.org\/abs\/1409.3215\" rel=\"noopener noreferrer nofollow\">Sequence to Sequence Learning with Neural Networks<\/a>.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 sequence-to-sequence (seq2seq) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <em>\u043a\u043e\u0434\u0435\u0440\u0430-\u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <em>\u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c<\/em> (RNN) \u0434\u043b\u044f <em>\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/em> \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e (\u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e) \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440. \u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u0435\u0440\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <em>\u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/em>. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u0430\u043a \u043e\u0431 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u043d\u0438\u0442\u0438\u0432\u0438\u0441\u0442\u043e\u0432, \u044d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u043d\u0430\u0431\u043e\u0440 \u043e\u0431\u0440\u0430\u0437\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0441 \u043e\u0431\u0440\u0430\u0437\u0430\u043c\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <em>\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/em> \u0432\u0442\u043e\u0440\u043e\u0439 RNN, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0447\u0438\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0435 (\u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435) \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u0435\u0433\u043e \u0441\u043b\u043e\u0432\u043e \u0437\u0430 \u0441\u043b\u043e\u0432\u043e\u043c, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043b\u0438\u043a\u0441\u0435\u043c\u0435 \u0437\u0430 \u0440\u0430\u0437.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0432\u044b\u0448\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430. \u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0432\u043e\u0434\u0430\/\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u00abguten morgen\u00bb, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 (\u0436\u0435\u043b\u0442\u044b\u0439, \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0435\u0447\u0438 (\u0441\u043b\u043e\u0432\u0430, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f,&#8230;) \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0443), \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a (\u0437\u0435\u043b\u0435\u043d\u044b\u0439). \u0412\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043a\u0435\u043d\u044b <em>\u043d\u0430\u0447\u0430\u043b\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> (<code>&lt;sos&gt;<\/code> \u2014 <em>start of sequence<\/em>) \u0438 <em>\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/em> (<code>&lt;eos&gt;<\/code> \u2014 <em>end of sequence<\/em>) \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043a\u043e\u043d\u0435\u0446 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0432 RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433-\u0432\u0435\u0440\u0441\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u0430 \u0441\u043b\u043e\u0435\u043c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 e, \u0442\u0430\u043a \u0438 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430, \u041d\u0430 \u0432\u044b\u0445\u043e\u0434 RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u0430\u043a \u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. RNN \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f (EncoderRNN) \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u0431\u0431\u0440\u0435\u0432\u0438\u0430\u0442\u0443\u0440\u0443 RNN, \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u043c \u043f\u043e\u0434 \u043d\u0435\u0439 \u0441\u0435\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>LSTM<\/em> (Long Short-Term Memory) \u0438\u043b\u0438 <em>GRU<\/em> (Gated Recurrent Unit).<\/p>\n<p>\u041c\u044b \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0433\u0434\u0435 \u0438 \u0442.\u0434. \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043e\u0431\u044b\u0447\u043d\u043e \u043b\u0438\u0431\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u044f\u043c\u0438, \u043b\u0438\u0431\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 RNN \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0430\u043a \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0442\u043e \u0435\u0441\u0442\u044c . \u042d\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 z, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435\/\u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u00abgood morning\u00bb. \u041a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u0432\u0445\u043e\u0434\u043e\u043c \u0432 RNN \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 (\u0441\u0438\u043d\u0438\u0439) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430 , \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 , \u0433\u0434\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 , \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, . \u0422.\u0435. \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0435\u0440\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043a\u043e\u0434\u0435\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 :<\/p>\n<p>\u0425\u043e\u0442\u044f \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0432\u0445\u043e\u0434\u0430\/\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 e \u0438 \u0441\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0432\u044b\u0445\u043e\u0434\u0430 d \u043e\u0431\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0436\u0451\u043b\u0442\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435, \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u043e\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0412 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f (\u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u044d\u0442\u0443 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0439 <code>Linear<\/code>, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043e\u043b\u0435\u0442\u043e\u0432\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c) \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 .<\/p>\n<p>\u0421\u043b\u043e\u0432\u0430 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c, \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u0430\u0433. \u041c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>&lt;sos&gt;<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0432 \u0434\u0435\u043a\u043e\u0434\u0435\u0440, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 y<sub>t&gt; 1<\/sub>, \u043c\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435, \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435\/\u0446\u0435\u043b\u0435\u0432\u043e\u0435<\/p>\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-326288","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326288","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=326288"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326288\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}