{"id":371402,"date":"2024-05-21T04:48:06","date_gmt":"2024-05-21T04:48:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=371402"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=371402","title":{"rendered":"<span>\u041e\u0431\u0449\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Word2Vec \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyTorch<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432 &#8212; \u043c\u043e\u0434\u0435\u043b\u044c <code>word2vec<\/code>. \u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 <code>word2vec<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>PyTorch<\/code>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u043a \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b <code>skip-gram<\/code> \u0442\u0430\u043a \u0438 <code>CBOW<\/code>.<\/p>\n<p><a href=\"https:\/\/github.com\/AntonSHBK\/word2vec_pytorch_realization\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p><code>Word2Vec<\/code> \u2014 \u044d\u0442\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 <code>Google<\/code> \u0432 2013 \u0433\u043e\u0434\u0443 (\u0422\u043e\u043c\u0430\u0441 \u041c\u0438\u043a\u043e\u043b\u043e\u0432). \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043a\u043e\u0440\u043f\u0443\u0441\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0447\u0438\u0441\u0435\u043b \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0441\u043b\u043e\u0432\u0430 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u043c\u0435\u044e\u0442 \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>Word2Vec<\/code> \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 (<code>NLP<\/code>), \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0430\u043d\u0430\u043b\u0438\u0437 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0435\u0437\u044e\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 <code>Word2Vec<\/code>:<\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435: \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0433\u0434\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f: Word2Vec \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043a\u043e\u0440\u043f\u0443\u0441\u0430\u0445 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u0445 \u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u0412\u0435\u043a\u0442\u043e\u0440\u044b \u0441\u043b\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a <code>word2vec<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a\u0430\u043a &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187;. \u0412 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0431\u0430 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043d\u0430\u043f\u0438\u0442\u043a\u043e\u0432 \u0438 \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0441\u0445\u043e\u0436\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u043e\u0432\u0430: &#171;\u043a\u043e\u0444\u0435&#187;, &#171;\u0447\u0430\u0439&#187;, &#171;\u0432\u043e\u0434\u0430&#187;, \u0438 &#171;\u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c&#187;.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 <code>word2vec<\/code>, &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187; \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u044b, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u0438\u0437-\u0437\u0430 \u0438\u0445 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0442\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0432\u043e &#171;\u0432\u043e\u0434\u0430&#187; \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187;, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0430\u043f\u0438\u0442\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u0441\u043b\u043e\u0432\u043e &#171;\u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c&#187; \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u2014 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0414\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438 Word2Vec:<\/h3>\n<p><code>CBOW<\/code> (Continuous Bag of Words): \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0444\u0440\u0430\u0437\u044b &#171;\u0441\u0438\u043d\u0435\u0435 \u043d\u0435\u0431\u043e \u043d\u0430\u0434 \u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187;, \u043c\u043e\u0434\u0435\u043b\u044c <code>CBOW<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e &#171;\u043d\u0435\u0431\u043e&#187; \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 &#171;\u0441\u0438\u043d\u0435\u0435&#187;, &#171;\u043d\u0430\u0434&#187;, &#171;\u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187;. <code>CBOW<\/code> \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043c\u0435\u043d\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0434\u043b\u044f \u0440\u0435\u0434\u043a\u0438\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<p><code>Skip-Gram<\/code>: \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043c\u043e\u0434\u0435\u043b\u044c <code>Skip-Gram<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 &#171;\u0441\u0438\u043d\u0435\u0435&#187;, &#171;\u043d\u0430\u0434&#187;, &#171;\u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187; \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043b\u043e\u0432\u0430 &#171;\u043d\u0435\u0431\u043e&#187;. <code>Skip-Gram<\/code> \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0440\u0435\u0434\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0438 \u043c\u0435\u043d\u0435\u0435 \u0447\u0430\u0441\u0442\u044b\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438.<\/p>\n<h4>CBOW (Continuous Bag of Words)<\/h4>\n<p>\u0426\u0435\u043b\u044c\u044e <code>CBOW<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430. \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u0441\u043b\u043e\u0432 \u0432\u043e\u043a\u0440\u0443\u0433 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u0440\u0435\u0445\u0441\u043b\u043e\u0439\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c: \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439, \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u041d\u0430 \u0432\u0445\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0434\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430. \u042d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#171;one-hot encoding&#187;, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c, \u0440\u0430\u0432\u043d\u0443\u044e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 1 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0438 0 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445.<\/p>\n<p>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439: \u0412\u0435\u043a\u0442\u043e\u0440\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043b\u043e\u0435\u043c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0447\u0435\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f. \u0414\u043b\u044f CBOW \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412\u0435\u043a\u0442\u043e\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <code>softmax<\/code>-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c. \u0426\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430.<\/p>\n<h4>Skip-Gram<\/h4>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 CBOW, \u0446\u0435\u043b\u044c Skip-Gram &#8212; \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430. \u042d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0441\u043b\u043e\u0432 (\u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u043a\u043d\u043e\u043c).<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412\u0445\u043e\u0434\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c <code>one-hot<\/code>.<br \/> \u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439: \u0422\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 <code>CBOW<\/code>, \u0433\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432, \u0432\u0435\u0434\u0443\u0449\u0443\u044e \u043a \u0441\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u0441\u043b\u043e\u044e.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>CBOW<\/code>, \u0433\u0434\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d <code>softmax<\/code>, \u0432 <code>Skip-Gram<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 <code>softmax<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0426\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Pytorch<\/h3>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c Word2Vec \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 <code>Skip-Gram<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>PyTorch<\/code>. \u042d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Word2Vec, \u043d\u043e \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"python\">import re from collections import Counter  import numpy as np import torch from torch import nn from torch.utils.data import DataLoader, Dataset <\/code><\/pre>\n<h4>Skip-Gram:<\/h4>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0430\u043f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u043b\u043e\u0432 \u043a \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043f\u0430\u0440 (\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e).<\/p>\n<pre><code class=\"python\">def prepare_data(text, window_size=2): # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043a\u0440\u043e\u043c\u0435 a-z, @, \u0438 # text = re.sub(r'[^a-z@# ]', '', text)     # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 text = text.lower() # \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u043c tokens = text.split()     # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 vocab = set(tokens) # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430 \u0441\u043b\u043e\u0432 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430  \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 word_to_ix = {word: i for i, word in enumerate(vocab)} # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u0440\u044b \u0441\u043b\u043e\u0432 n-\u0433\u0440\u0430\u043c\u043c data = [] for i in range(len(tokens)): for j in range(max(0, i - window_size), min(len(tokens), i + window_size + 1)): if i != j: data.append((tokens[i], tokens[j]))     return data, word_to_ix, len(vocab) <\/code><\/pre>\n<p><strong>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Skip-Gram<\/strong><\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0434\u043b\u044f \u0434\u0430\u0442\u0430\u043b\u043e\u0430\u0434\u0435\u0440\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/pytorch.org\/tutorials\/beginner\/basics\/data_tutorial.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Dataset \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>__init__<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><code>__len__<\/code>: \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><code>__getitem__<\/code>: \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0438\u043d\u0434\u0435\u043a\u0441, \u0432\u043e\u0437\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0430\u0442\u0447\u0430 (\u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b), \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">class SkipGramModelDataset(Dataset): def __init__(self, data, word_to_ix): self.data = [(word_to_ix[center], word_to_ix[context]) for center, context in data] def __len__(self): return len(self.data) def __getitem__(self, idx): return torch.tensor(self.data[idx][0], dtype=torch.long), torch.tensor(self.data[idx][1], dtype=torch.long)  <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 <code>PyTorch<\/code>.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439 &#8212; <code>nn.Embedding<\/code> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 <code>NLP<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (\u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439) \u0441\u043b\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0451\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0441\u043b\u043e\u0439. \u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>softmax<\/code>.<\/p>\n<p><code>LogSoftmax<\/code> \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0441\u043b\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>NLLLoss<\/code> (Negative Log Likelihood Loss). <code>LogSoftmax<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u0442\u044b (\u0432\u044b\u0445\u043e\u0434\u044b \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f) \u0432 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 <code>NLLLoss<\/code>. \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e <code>NLLLoss<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0435\u0451 \u0431\u0443\u0434\u0443\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"python\">class Word2VecSkipGramModel(nn.Module): def __init__(self, vocab_size, embedding_dim): super(Word2VecSkipGramModel, self).__init__() self.embeddings = nn.Embedding(vocab_size, embedding_dim) self.out_layer = nn.Linear(embedding_dim, vocab_size) self.activation_function = nn.LogSoftmax(dim=-1)  def forward(self, center_word_idx): hidden_layer = self.embeddings(center_word_idx) out_layer = self.out_layer(hidden_layer) log_probs = self.activation_function(out_layer) return log_probs <\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong><\/p>\n<p>\u041e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<ol>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f- \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0441\u043b\u043e\u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 &#8212; \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (\u0432\u044b\u0445\u043e\u0434 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438) \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 (\u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0445\u043e\u0434 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>softmax<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u042d\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u043e\u0432 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u0438 &#8212; \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def train_model(data, word_to_ix, vocab_size, embedding_dim=50, epochs=10, batch_size=1): # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 dataset = SkipGramModelDataset(data, word_to_ix) dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True) # \u043c\u043e\u0434\u0435\u043b\u044c model = Word2VecSkipGramModel(vocab_size, embedding_dim) # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c loss_function = nn.NLLLoss() #  \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 optimizer = torch.optim.SGD(model.parameters(), lr=0.05)  for epoch in range(epochs): total_loss = 0 for center_word, context_word in dataloader: model.zero_grad() log_probs = model(center_word) loss = loss_function(log_probs, context_word) loss.backward() optimizer.step()             total_loss += loss.item() print(f'Epoch {epoch + 1}, Loss: {total_loss}') return model <\/code><\/pre>\n<pre><code class=\"python\"># \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 def train(data: str): # \u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: # \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 window_size = 2 # \u0434\u043b\u0438\u043d\u0430 \u0435\u043c\u0431\u0435\u0434\u0438\u043d\u0433\u0430 embedding_dim = 10 # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f epochs = 5 # \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 batch_size = 1  # \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 ngramm_data, word_to_ix, vocab_size = prepare_data(data, window_size)  # \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 model = train_model(ngramm_data, word_to_ix, vocab_size, embedding_dim, epochs, batch_size)  # # \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0441\u043b\u043e\u0432 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 embeddings = model.embeddings.weight.data.numpy() # \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043b\u043e\u0432 \u0438 \u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 ix_to_word = {i: word for word, i in word_to_ix.items()} w2v_dict = {ix_to_word[ix]: embeddings[ix] for ix in range(vocab_size)} return w2v_dict <\/code><\/pre>\n<p>\u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0443\u0447\u0435\u0431\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445.<\/p>\n<pre><code class=\"python\"># \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 test_text = 'Captures Semantic Relationships: The skip-gram model effectively captures semantic relationships between words. It learns word embeddings that encode similar meanings and associations, allowing for tasks like word analogies and similarity calculations. Handles Rare Words: The skip-gram model performs well even with rare words or words with limited occurrences in the training data. It can generate meaningful representations for such words by leveraging the context in which they appear. Contextual Flexibility: The skip-gram model allows for flexible context definitions by using a window around each target word. This flexibility captures local and global word associations, resulting in richer semantic representations. Scalability: The skip-gram model can be trained efficiently on large-scale datasets due to its simplicity and parallelization potential. It can process vast amounts of text data to generate high-quality word embeddings.'  w2v_dict = train(test_text) <\/code><\/pre>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0438 \u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0445\u043e\u0434\u044b \u0438 \u0446\u0435\u043b\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<br \/> \u041c\u043e\u0434\u0435\u043b\u044c <code>Word2VecSkipGramModel<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043b\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435.<br \/> \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f <code>train_model<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>NLLLoss<\/code> \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<h4>CBOW:<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0430 \u0432\u0445\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e.<\/p>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0435\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043a\u0430\u043a \u0446\u0435\u043b\u0438:<\/p>\n<pre><code class=\"python\">def prepare_data_cbow(text: str, window_size=2): text = re.sub(r'[^a-z@# ]', '', text.lower())     tokens = text.split()     vocab = set(tokens) word_to_ix = {word: i for i, word in enumerate(vocab)} data = [] for i in range(window_size, len(tokens) - window_size): context = [tokens[i - j - 1] for j in range(window_size)] + [tokens[i + j + 1] for j in range(window_size)] target = tokens[i] data.append((context, target)) return data, word_to_ix, len(vocab)  class SkipGramDataset(Dataset): def __init__(self, data, word_to_ix): self.data = [(word_to_ix[center], word_to_ix[context]) for center, context in data]  def __len__(self): return len(self.data)  def __getitem__(self, idx): return torch.tensor(self.data[idx][0], dtype=torch.long), torch.tensor(self.data[idx][1], dtype=torch.long) <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0430 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e:<\/p>\n<pre><code class=\"python\">class Word2VecCBOWModel(nn.Module): def __init__(self, vocab_size, embedding_dim): super(Word2VecCBOWModel, self).__init__() self.embeddings = nn.Embedding(vocab_size, embedding_dim) self.out_layer = nn.Linear(embedding_dim, vocab_size) self.activation_function = nn.LogSoftmax(dim=1)  def forward(self, center_word_idx): hidden_layer = torch.mean(self.embeddings(center_word_idx), dim=1) out_layer = self.out_layer(hidden_layer) log_probs = self.activation_function(out_layer) return log_probs <\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u043e\u0432\u044b\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c\u044e CBOW:<\/p>\n<pre><code class=\"python\">def train_model_cbow(data, word_to_ix, vocab_size, embedding_dim=50, epochs=10, batch_size=1): dataset = CBOWDataset(data, word_to_ix) dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True) model = Word2VecCBOWModel(vocab_size, embedding_dim) loss_function = nn.NLLLoss() optimizer = torch.optim.SGD(model.parameters(), lr=0.001) for epoch in range(epochs): total_loss = 0 for context_words, target_word in dataloader: context_words = context_words model.zero_grad() log_probs = model(context_words) loss = loss_function(log_probs, target_word) loss.backward() optimizer.step() total_loss += loss.item() print(f'Epoch {epoch + 1}, Loss: {total_loss}') return model <\/code><\/pre>\n<h3>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0414\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 Word2Vec \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0442\u0435\u0445\u043d\u0438\u043a:<\/p>\n<ol>\n<li>\n<p>\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u0430 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 <\/p>\n<ul>\n<li>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: \u0411\u043e\u043b\u044c\u0448\u0438\u0439 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0439 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0440\u043f\u0443\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <\/p>\n<ul>\n<li>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f: \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432: \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u043d\u0435\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u043b\u043e\u0433\u0438, \u0441\u043e\u044e\u0437\u044b).<\/p>\n<\/li>\n<li>\n<p>\u041b\u0435\u043c\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0441\u0442\u0435\u043c\u043c\u0438\u043d\u0433: \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432 \u043a \u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0448\u0443\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 n-\u0433\u0440\u0430\u043c\u043c: \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0444\u0440\u0430\u0437\u0430\u0445 \u0438\u043b\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f\u0445 \u0441\u043b\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;\u041d\u044c\u044e-\u0419\u043e\u0440\u043a&#187; \u0432\u043c\u0435\u0441\u0442\u043e &#171;\u041d\u044c\u044e&#187; \u0438 &#171;\u0419\u043e\u0440\u043a&#187; \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e) \u043c\u043e\u0436\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 \u0432\u0435\u043a\u0442\u043e\u0440\u0430: \u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430: \u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u043e\u043a\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u0438\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (<code>subsampling<\/code>): \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0441\u043b\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043f\u043e\u0445: \u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432 \u043f\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u043d\u043e \u0441 \u0440\u0438\u0441\u043a\u043e\u043c \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>Negative Sampling<\/code> \u0438 <code>Hierarchical Softmax<\/code> <\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432: \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u0444\u0442\u043c\u0430\u043a\u0441\u0430: \u041c\u043e\u0436\u0435\u0442 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0437\u0430 \u0441\u0447\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0439 \u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 <\/p>\n<ul>\n<li>\n<p>\u0410\u043d\u0441\u0430\u043c\u0431\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439: \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 (\u0442\u0435\u043a\u0441\u0442, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0437\u0432\u0443\u043a) \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u0433\u0430\u0442\u044b\u0435 \u0438 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 <\/p>\n<ul>\n<li>\n<p>\u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430: \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u043a \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044e, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0441\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435: \u041d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u0442\u044c \u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0442\u0435\u0445\u043d\u0438\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u0440\u044c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0421 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <code>word2vec<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0441\u043b\u043e\u0432\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 (<code>NLP<\/code>) \u0431\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440. \u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0445 \u043d\u0430 \u0441\u043c\u0435\u043d\u0443 <code>word2vec<\/code>:<\/p>\n<ul>\n<li>\n<p><code>GloVe<\/code> (Global Vectors for Word Representation): \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0439 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0432 \u0432 \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432. <code>GloVe<\/code> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0434\u0432\u0443\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0441\u043b\u043e\u0432: \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u043e\u0439 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u0440\u043e\u0434\u0435 word2vec, \u0441\u0442\u0440\u0435\u043c\u044f\u0441\u044c \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><code>fastText<\/code>: \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u0432 <code>Facebook Research<\/code>, <code>fastText<\/code> \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 <code>word2vec<\/code> \u0437\u0430 \u0441\u0447\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0446\u0435\u043b\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 \u043f\u043e\u0434\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, n-\u0433\u0440\u0430\u043c\u043c). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <code>fastText<\/code> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0441\u043b\u043e\u0432, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u0434\u043b\u044f \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u0431\u043e\u0433\u0430\u0442\u043e\u0439 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><code>ELMo<\/code> (Embeddings from Language Models): <code>ELMo<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 <code>LSTM<\/code> (Long Short-Term Memory) \u0441\u0435\u0442\u0435\u0439 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432. \u042d\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043e\u0433\u0430\u0442\u044b \u043d\u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u043e\u043b\u0438\u0441\u0435\u043c\u0438\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u043c\u0438 \u043d\u044e\u0430\u043d\u0441\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>BERT<\/code> (Bidirectional Encoder Representations from Transformers): <code>BERT<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044e \u0432 <code>NLP<\/code> \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0432\u043e\u0435\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d (\u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e \u0438 \u0441\u043f\u0440\u0430\u0432\u0430 \u043d\u0430\u043b\u0435\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e). \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b Transformer, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u043d\u044e\u0430\u043d\u0441\u044b \u044f\u0437\u044b\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><code>GPT<\/code> (Generative Pre-trained Transformer): \u0421\u0435\u0440\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 <code>GPT<\/code> \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 <code>Transformer<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 <code>NLP<\/code>. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u043c\u043e\u0434\u0435\u043b\u0438 <code>GPT<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0432\u044b\u0434\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430, \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p><code>T5<\/code> (Text-to-Text Transfer Transformer): \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0442 <code>Google Research<\/code> \u0442\u0440\u0430\u043a\u0442\u0443\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 <code>NLP<\/code> \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0434\u0438\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0441\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <code>T5<\/code> \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0434\u0432\u0438\u0433 \u0432 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u043e\u0442\u0445\u043e\u0434\u044f \u043e\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432 \u043a \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/h3>\n<p><code>Word2Vec<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043f\u0440\u043e\u0440\u044b\u0432 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 <code>NLP<\/code>, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0432 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0415\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 <code>NLP<\/code> \u0438 \u043f\u043e \u0441\u0435\u0439 \u0434\u0435\u043d\u044c \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/arxiv.org\/abs\/1301.3781\" rel=\"noopener noreferrer nofollow\">Efficient Estimation of Word Representations in Vector Space<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/Voximplant\/articles\/446738\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b Natural Language Processing \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/574624\/\" rel=\"noopener noreferrer nofollow\">NLP \u2014 \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430: Word2Vec<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/neurohive.io\/ru\/osnovy-data-science\/word2vec-vektornye-predstavlenija-slov-dlja-mashinnogo-obuchenija\/\" rel=\"noopener noreferrer nofollow\">Word2Vec: \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u043b\u043e\u0432<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/sysblok.ru\/knowhow\/word2vec-pokazhi-mne-svoj-kontekst-i-ja-skazhu-kto-ty\/\" rel=\"noopener noreferrer nofollow\">Word2Vec: \u043f\u043e\u043a\u0430\u0436\u0438 \u043c\u043d\u0435 \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0438 \u044f \u0441\u043a\u0430\u0436\u0443, \u043a\u0442\u043e \u0442\u044b<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/801807\/\"> https:\/\/habr.com\/ru\/articles\/801807\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432 &#8212; \u043c\u043e\u0434\u0435\u043b\u044c <code>word2vec<\/code>. \u0422\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 <code>word2vec<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>PyTorch<\/code>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u043a \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b <code>skip-gram<\/code> \u0442\u0430\u043a \u0438 <code>CBOW<\/code>.<\/p>\n<p><a href=\"https:\/\/github.com\/AntonSHBK\/word2vec_pytorch_realization\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<p><code>Word2Vec<\/code> \u2014 \u044d\u0442\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0432, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 <code>Google<\/code> \u0432 2013 \u0433\u043e\u0434\u0443 (\u0422\u043e\u043c\u0430\u0441 \u041c\u0438\u043a\u043e\u043b\u043e\u0432). \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 \u043a\u043e\u0440\u043f\u0443\u0441\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0447\u0438\u0441\u0435\u043b \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0441\u043b\u043e\u0432\u0430 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u043c\u0435\u044e\u0442 \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>Word2Vec<\/code> \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 (<code>NLP<\/code>), \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0430\u043d\u0430\u043b\u0438\u0437 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0435\u0437\u044e\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 <code>Word2Vec<\/code>:<\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435: \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u0432 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0433\u0434\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f: Word2Vec \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043a\u043e\u0440\u043f\u0443\u0441\u0430\u0445 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u0445 \u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u0412\u0435\u043a\u0442\u043e\u0440\u044b \u0441\u043b\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a <code>word2vec<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a\u0430\u043a &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187;. \u0412 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0431\u0430 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043d\u0430\u043f\u0438\u0442\u043a\u043e\u0432 \u0438 \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0441\u0445\u043e\u0436\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong><\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u043e\u0432\u0430: &#171;\u043a\u043e\u0444\u0435&#187;, &#171;\u0447\u0430\u0439&#187;, &#171;\u0432\u043e\u0434\u0430&#187;, \u0438 &#171;\u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c&#187;.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 <code>word2vec<\/code>, &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187; \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u044b, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u0438\u0437-\u0437\u0430 \u0438\u0445 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0442\u043a\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0432\u043e &#171;\u0432\u043e\u0434\u0430&#187; \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 &#171;\u043a\u043e\u0444\u0435&#187; \u0438 &#171;\u0447\u0430\u0439&#187;, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0430\u043f\u0438\u0442\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u0441\u043b\u043e\u0432\u043e &#171;\u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044c&#187; \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u2014 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0414\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438 Word2Vec:<\/h3>\n<p><code>CBOW<\/code> (Continuous Bag of Words): \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0444\u0440\u0430\u0437\u044b &#171;\u0441\u0438\u043d\u0435\u0435 \u043d\u0435\u0431\u043e \u043d\u0430\u0434 \u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187;, \u043c\u043e\u0434\u0435\u043b\u044c <code>CBOW<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e &#171;\u043d\u0435\u0431\u043e&#187; \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 &#171;\u0441\u0438\u043d\u0435\u0435&#187;, &#171;\u043d\u0430\u0434&#187;, &#171;\u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187;. <code>CBOW<\/code> \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043c\u0435\u043d\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0434\u043b\u044f \u0440\u0435\u0434\u043a\u0438\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<p><code>Skip-Gram<\/code>: \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043c\u043e\u0434\u0435\u043b\u044c <code>Skip-Gram<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 &#171;\u0441\u0438\u043d\u0435\u0435&#187;, &#171;\u043d\u0430\u0434&#187;, &#171;\u0433\u043e\u043b\u043e\u0432\u043e\u0439&#187; \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043b\u043e\u0432\u0430 &#171;\u043d\u0435\u0431\u043e&#187;. <code>Skip-Gram<\/code> \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0440\u0435\u0434\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0438 \u043c\u0435\u043d\u0435\u0435 \u0447\u0430\u0441\u0442\u044b\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438.<\/p>\n<h4>CBOW (Continuous Bag of Words)<\/h4>\n<p>\u0426\u0435\u043b\u044c\u044e <code>CBOW<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430. \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u0441\u043b\u043e\u0432 \u0432\u043e\u043a\u0440\u0443\u0433 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u0440\u0435\u0445\u0441\u043b\u043e\u0439\u043d\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c: \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439, \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u041d\u0430 \u0432\u0445\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0434\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430. \u042d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#171;one-hot encoding&#187;, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c, \u0440\u0430\u0432\u043d\u0443\u044e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 1 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0438 0 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445.<\/p>\n<p>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439: \u0412\u0435\u043a\u0442\u043e\u0440\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0441\u043b\u043e\u0435\u043c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0447\u0435\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f. \u0414\u043b\u044f CBOW \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412\u0435\u043a\u0442\u043e\u0440 \u0441\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u043a\u0440\u044b\u0442\u044b\u043c \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <code>softmax<\/code>-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c. \u0426\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430.<\/p>\n<h4>Skip-Gram<\/h4>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 CBOW, \u0446\u0435\u043b\u044c Skip-Gram &#8212; \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430. \u042d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0441\u043b\u043e\u0432 (\u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u043a\u043d\u043e\u043c).<\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412\u0445\u043e\u0434\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c <code>one-hot<\/code>.<br \/> \u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0441\u043b\u043e\u0439: \u0422\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 <code>CBOW<\/code>, \u0433\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440 \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u0441\u043e\u0432, \u0432\u0435\u0434\u0443\u0449\u0443\u044e \u043a \u0441\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u0441\u043b\u043e\u044e.<\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439: \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>CBOW<\/code>, \u0433\u0434\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d <code>softmax<\/code>, \u0432 <code>Skip-Gram<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 <code>softmax<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0426\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Pytorch<\/h3>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c Word2Vec \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 <code>Skip-Gram<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>PyTorch<\/code>. \u042d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Word2Vec, \u043d\u043e \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"python\">import re from collections import Counter  import numpy as np import torch from torch import nn from torch.utils.data import DataLoader, Dataset <\/code><\/pre>\n<h4>Skip-Gram:<\/h4>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u0430\u043f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u043b\u043e\u0432 \u043a \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043f\u0430\u0440 (\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e).<\/p>\n<pre><code class=\"python\">def prepare_data(text, window_size=2): # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043a\u0440\u043e\u043c\u0435 a-z, @, \u0438 # text = re.sub(r'[^a-z@# ]', '', text)     # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 text = text.lower() # \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u043c tokens = text.split()     # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 vocab = set(tokens) # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430 \u0441\u043b\u043e\u0432 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430  \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 word_to_ix = {word: i for i, word in enumerate(vocab)} # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u0440\u044b \u0441\u043b\u043e\u0432 n-\u0433\u0440\u0430\u043c\u043c data = [] for i in range(len(tokens)): for j in range(max(0, i - window_size), min(len(tokens), i + window_size + 1)): if i != j: data.append((tokens[i], tokens[j]))     return data, word_to_ix, len(vocab) <\/code><\/pre>\n<p><strong>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Skip-Gram<\/strong><\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0434\u043b\u044f \u0434\u0430\u0442\u0430\u043b\u043e\u0430\u0434\u0435\u0440\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/pytorch.org\/tutorials\/beginner\/basics\/data_tutorial.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Dataset \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>__init__<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><code>__len__<\/code>: \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><code>__getitem__<\/code>: \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0438\u043d\u0434\u0435\u043a\u0441, \u0432\u043e\u0437\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0430\u0442\u0447\u0430 (\u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b), \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">class SkipGramModelDataset(Dataset): def __init__(self, data, word_to_ix): self.data = [(word_to_ix[center], word_to_ix[context]) for center, context in data] def __len__(self): return len(self.data) def __getitem__(self, idx): return torch.tensor(self.data[idx][0], dtype=torch.long), torch.tensor(self.data[idx][1], dtype=torch.long)  <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 <code>PyTorch<\/code>.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439 &#8212; <code>nn.Embedding<\/code> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 <code>NLP<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (\u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439) \u0441\u043b\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0451\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0441\u043b\u043e\u0439. \u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>softmax<\/code>.<\/p>\n<p><code>LogSoftmax<\/code> \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0441\u043b\u043e\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>NLLLoss<\/code> (Negative Log Likelihood Loss). <code>LogSoftmax<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u0442\u044b (\u0432\u044b\u0445\u043e\u0434\u044b \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f) \u0432 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 <code>NLLLoss<\/code>. \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e <code>NLLLoss<\/code> \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0435\u0451 \u0431\u0443\u0434\u0443\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"python\">class Word2VecSkipGramModel(nn.Module): def __init__(self, vocab_size, embedding_dim): super(Word2VecSkipGramModel, self).__init__() self.embeddings = nn.Embedding(vocab_size, embedding_dim) self.out_layer = nn.Linear(embedding_dim, vocab_size) self.activation_function = nn.LogSoftmax(dim=-1)  def forward(self, center_word_idx): hidden_layer = self.embeddings(center_word_idx) out_layer = self.out_layer(hidden_layer) log_probs = self.activation_function(out_layer) return log_probs <\/code><\/pre>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong><\/p>\n<p>\u041e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<ol>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f- \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u0441\u043b\u043e\u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 &#8212; \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (\u0432\u044b\u0445\u043e\u0434 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438) \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0441\u043b\u043e\u0432 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 (\u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0445\u043e\u0434 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>softmax<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u042d\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u043e\u0432 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u0438 &#8212; \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def train_model(data, word_to_ix, vocab_size, embedding_dim=50, epochs=10, batch_size=1): # \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 dataset = SkipGramModelDataset(data, word_to_ix) dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True) # \u043c\u043e\u0434\u0435\u043b\u044c model = Word2VecSkipGramModel(vocab_size, embedding_dim) # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c loss_function = nn.NLLLoss() #  \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 optimizer = torch.optim.SGD(model.parameters(), lr=0.05)  for epoch in range(epochs): total_loss = 0 for center_word, context_word in dataloader: model.zero_grad() log_probs = model(center_word) loss = loss_function(log_probs, context_word) loss.backward() optimizer.step()             total_loss += loss.item() print(f'Epoch {epoch + 1}, Loss: {total_loss}') return model <\/code><\/pre>\n<pre><code class=\"python\"># \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 def train(data: str): # \u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: # \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 window_size = 2 # \u0434\u043b\u0438\u043d\u0430 \u0435\u043c\u0431\u0435\u0434\u0438\u043d\u0433\u0430 embedding_dim = 10 # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f epochs = 5 # \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 batch_size = 1  # \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 ngramm_data, word_to_ix, vocab_size = prepare_data(data, window_size)  # \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 model = train_model(ngramm_data,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-371402","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371402","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=371402"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371402\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}