{"id":302530,"date":"2020-04-26T15:00:30","date_gmt":"2020-04-26T15:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=302530"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=302530","title":{"rendered":"\u0412\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 BERT: \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498144\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1t\/0s\/2u\/1t0s2udwz_c-rqf3jvlxkigemhm.png\" alt=\"bert-distilbert-sentence-classification\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \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 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u043b\u0441\u044f \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442. \u041c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u0442\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0434\u0443\u0449\u0438\u0445 \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0443\u0436\u0438\u0442 <a href=\"https:\/\/www.blog.google\/products\/search\/search-language-understanding-bert\/\" rel=\"nofollow\">\u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0435 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0441\u0442\u043e\u044f\u0449\u0438\u043c \u0437\u0430 \u043f\u043e\u0438\u0441\u043a\u043e\u043c Google, \u0441\u0442\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c BERT<\/a>. Google \u0432\u0435\u0440\u0438\u0442, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0433 (\u0442.\u0435. \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0432 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u00ab\u0432\u0435\u043b\u0438\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0440\u043e\u0440\u044b\u0432 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u044f\u0442\u044c \u043b\u0435\u0442 \u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u0432\u043e \u0432\u0441\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u00bb.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0432\u0435\u0440\u0441\u0438\u0439 BERT&#8217;\u0430 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438, \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u043d\u043e\u0443\u0442\u0431\u0443\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u0438\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 <a href=\"https:\/\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynbhttps:\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">Colab<\/a>.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"dannye-sst2\">\u0414\u0430\u043d\u043d\u044b\u0435: SST2<\/h1>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/nlp.stanford.edu\/sentiment\/index.html\" rel=\"nofollow\">SST2<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0437 \u043e\u0442\u0437\u044b\u0432\u043e\u0432 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u043b\u0438\u0431\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043c\u0435\u0442\u043a\u0443 (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1), \u043b\u0438\u0431\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0):<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zn\/el\/tu\/zneltu_kmrm0a2l1duybrs6ust8.png\" alt=\"sst2\"><\/p>\n<p>  <\/p>\n<h1 id=\"modeli-klassifikaciya-tonalnosti-predlozheniy\">\u041c\u043e\u0434\u0435\u043b\u0438: \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2013 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0435\u0442 \u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (\u0432\u0440\u043e\u0434\u0435 \u0442\u0435\u0445, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445) \u0438 \u0432\u044b\u0434\u0430\u0435\u0442 \u0438\u043b\u0438 1 (\u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f), \u0438\u043b\u0438 0 (\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c). \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u044d\u0442\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/f4\/mk\/px\/f4mkpxxli5t3izoldbz2qzfucei.png\" alt=\"sentiment-classifier-1.png\"><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0436\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0445 \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/medium.com\/huggingface\/distilbert-8cf3380435b5\" rel=\"nofollow\">DistilBERT<\/a> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u043d\u0443\u044e \u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. DistilBERT \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e BERT&#8217;\u0430, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0443\u044e \u0438 \u0432\u044b\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0432 \u043e\u0442\u0440\u044b\u0442\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0433\u0440\u0443\u043f\u043f\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 <a href=\"https:\/\/huggingface.co\/\" rel=\"nofollow\">HuggingFace<\/a>. \u041e\u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043b\u0435\u0433\u0447\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u0430, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043c\u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438.<\/li>\n<li>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2013 \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 scikit learn, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 DistilBERT&#8217;\u043e\u043c \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 (1 \u0438\u043b\u0438 0 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 768. \u041c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0v\/2c\/2f\/0v2c2fzigdyzff3vqurbanyc2tk.png\" alt=\"distilbert-bert-sentiment-classifier.png\"><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0447\u0438\u0442\u0430\u043b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/487358\/\">BERT, ELMO \u0438 \u041a\u043e \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445 (\u043a\u0430\u043a \u0432 NLP \u043f\u0440\u0438\u0448\u043b\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u0435\u0440\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435)<\/a>: \u044d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0442\u043e\u043a\u0435\u043d [CLS]).<\/p>\n<p>  <\/p>\n<h1 id=\"obuchenie-modeli\">\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h1>\n<p>  <\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043b\u0438\u0448\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f DistilBERT&#8217;\u0430, \u0442\u043e \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0434\u043b\u044f \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0418 \u0445\u043e\u0442\u044f \u043e\u043d\u0430 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043d\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0430, \u043d\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u00ab\u043d\u0430\u0432\u044b\u043a\u0430\u043c\u0438\u00bb BERT&#8217;\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e BERT \u043f\u043e\u0434\u0430\u0435\u0442 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 [CLS] \u0442\u043e\u043a\u0435\u043d\u043e\u043c. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044d\u0442\u043e\u0442 \u043d\u0430\u0432\u044b\u043a \u043e\u043d \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u043b \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443, BERT \u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0432\u043e\u0434 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438. <\/p>\n<p>  <\/p>\n<p>\u0412 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/487358\/\">transformers<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DistilBERT&#8217;\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/lx\/du\/gi\/lxdugirbo9cgxehjoggycphulr8.png\" alt=\"model-training\"><\/p>\n<p>  <\/p>\n<h1 id=\"obzor-rukovodstva\">\u041e\u0431\u0437\u043e\u0440 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430<\/h1>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0432\u043e\u0442 \u043f\u043b\u0430\u043d \u043d\u0430\u0448\u0435\u0439 \u0438\u0433\u0440\u044b. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u043c DistilBERT&#8217;\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u0434\u043b\u044f 2 \u0442\u044b\u0441\u044f\u0447 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bb\/uv\/_t\/bbuv_tdc97jm9upvgj1gcyefemy.png\" alt=\"bert-distilbert-tutorial-sentence-embedding\"><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043a\u0430\u0441\u0430\u0442\u044c\u0441\u044f DistilBERT&#8217;\u0430. \u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u043e Scikit Learn. \u041c\u044b, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/r_\/e3\/mq\/r_e3mqtxvjry5xoabovb7il_iec.png\" alt=\"bert-distilbert-train-test-split-sentence-embedding\"><\/p>\n<p>  <\/p>\n<p><em>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 distilBERT&#8217;\u0430 (\u043c\u043e\u0434\u0435\u043b\u044c #1) \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 (\u043c\u043e\u0434\u0435\u043b\u044c #2). \u0418\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 sklearn \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0435\u0440\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 75% \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u043d\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/em><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wn\/f6\/9k\/wnf69kgqr5azls-edvk6gidjoui.png\" alt=\"bert-training-logistic-regression\"><\/p>\n<p>  <\/p>\n<h1 id=\"kak-vychislyaetsya-predskazannoe-znachenie\">\u041a\u0430\u043a \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u043a\u043e\u0434 \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u00aba visually stunning rumination on love\u00bb. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 BERT&#8217;\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d\u044b. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u043a\u0435\u043d [CLS] \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 [SEP] \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f).<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/rd\/cu\/me\/rdcumeyavzwbbbleog8_tv1y0o8.png\" alt=\"bert-distilbert-tokenization-1\"><\/p>\n<p>  <\/p>\n<p>\u0422\u0440\u0435\u0442\u044c\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u0445 \u0441\u043b\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/446530\/\">Word2vec \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-8\/o5\/tv\/-8o5tv8c37kuyvnzvgcr9dt6vam.png\" alt=\"bert-distilbert-tokenization-2-token-ids\"><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u044d\u0442\u0438 \u0442\u0440\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439 \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">tokenizer.encode(&quot;a visually stunning rumination on love&quot;, add_special_tokens=True)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 DistilBERT&#8217;\u0435.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0447\u0438\u0442\u0430\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/487358\/\">BERT, ELMO \u0438 \u041a\u043e \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445 (\u043a\u0430\u043a \u0432 NLP \u043f\u0440\u0438\u0448\u043b\u043e \u0442\u0440\u0430\u043d\u0441\u0444\u0435\u0440\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435)<\/a>, \u0442\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/3u\/i-\/gl\/3ui-glcku_tpcg8cjoghffb0vt0.png\"><\/p>\n<p>  <\/p>\n<h1 id=\"prohodya-cherez-distilbert\">\u041f\u0440\u043e\u0445\u043e\u0434\u044f \u0447\u0435\u0440\u0435\u0437 DistilBERT<\/h1>\n<p>  <\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0432 DistilBERT&#8217;\u0435 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/487358\/\">\u043e\u0431\u044b\u0447\u043d\u043e\u043c BERT&#8217;\u0435<\/a>. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 768 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/oq\/nf\/ip\/oqnfip8zglclubfblimrqvwrdz8.png\" alt=\"bert-model-input-output-1\"><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043c\u044b \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441 [CLS] \u0442\u043e\u043a\u0435\u043d\u043e\u043c). \u042d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vr\/-x\/my\/vr-xmyzsavuid9mrskzpysxbvhw.png\" alt=\"bert-model-calssification-output-vector-cls\"><\/p>\n<p>  <\/p>\n<p>\u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u044d\u0441\u0442\u0430\u0444\u0435\u0442\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u043e\u0433\u043e, \u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u043d\u0430\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041c\u043e\u0436\u043d\u043e \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jm\/oy\/or\/jmoyorskol1nxvxarefclben_ky.png\" alt=\"bert-distilbert-sentence-classification-example\"><\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, \u0433\u0434\u0435 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<h1 id=\"kod\">\u041a\u043e\u0434<\/h1>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041d\u043e\u0443\u0442\u0431\u0443\u043a \u0441\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 <a href=\"https:\/\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">Colab<\/a> \u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">github<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd import torch import transformers as ppb # pytorch transformers from sklearn.linear_model import LogisticRegression from sklearn.model_selection import cross_val_score from sklearn.model_selection import train_test_split<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/github.com\/clairett\/pytorch-sentiment-classification\/\" rel=\"nofollow\">\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d<\/a> \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u043d\u0430 github, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c pandas:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">df = pd.read_csv('https:\/\/github.com\/clairett\/pytorch-sentiment-classification\/raw\/master\/data\/SST2\/train.tsv', delimiter='\\t', header=None)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c df.head() \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0441\u0442\u0440\u043e\u043a \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u0430 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">df.head()<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/t2\/-_\/tl\/t2-_tljwx7gvvwsoqs3hlt6w7ya.png\" alt=\"sst2-df-head\"><\/p>\n<p>  <\/p>\n<h1 id=\"zagruzka-predobuchennoy-modeli-distilbert-i-tokenizatora\">\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 DistilBERT \u0438 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430<\/h1>\n<p>  <\/p>\n<pre><code class=\"python\">model_class, tokenizer_class, pretrained_weights = (ppb.DistilBertModel, ppb.DistilBertTokenizer, 'distilbert-base-uncased')  ## \u0425\u043e\u0442\u0438\u0442\u0435 BERT \u0432\u043c\u0435\u0441\u0442\u043e distilBERT? \u0420\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443: #model_class, tokenizer_class, pretrained_weights = (ppb.BertModel, ppb.BertTokenizer, 'bert-base-uncased')  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438\/\u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430  tokenizer = tokenizer_class.from_pretrained(pretrained_weights) model = model_class.from_pretrained(pretrained_weights)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435. \u0422\u0430\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u044b \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435 (\u0432 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 \u0438\u0437 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043e\u043a\u043e\u043b\u043e 2000).<\/p>\n<p>  <\/p>\n<h1 id=\"tokenizaciya\">\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>  <\/p>\n<pre><code class=\"python\">tokenized = df[0].apply((lambda x: tokenizer.encode(x, add_special_tokens=True)))<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/le\/zs\/gr\/lezsgrmkronylp8wh-kays3c0c8.png\" alt=\"sst2-text-to-tokenized-ids-bert-example\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a (\u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 Series\/DataFrame \u0438\u0437 pandas) \u0441\u043f\u0438\u0441\u043a\u043e\u0432. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c DistilBERT \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 \u0432\u0445\u043e\u0434\u0435, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 0 (padding). \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435 (\u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u0441\u0435 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u0432 Python).<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443\/\u0442\u0435\u043d\u0437\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c BERT&#8217;\u0443:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/u7\/uz\/ma\/u7uzma5jjkbif--qi60zgb0xyy8.png\" alt=\"bert-input-tensor\"><\/p>\n<p>  <\/p>\n<h1 id=\"obrabotka-v-distilberte\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432 DistilBERT&#8217;\u0435<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u0432 DistilBERT.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">input_ids = torch.tensor(np.array(padded))  with torch.no_grad():     last_hidden_states = model(input_ids)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <strong>last_hidden_states<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 DistilBERT&#8217;\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u0440\u0442\u0435\u0436 \u0444\u043e\u0440\u043c\u044b (\u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0447\u0438\u0441\u043b\u043e \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 DistilBERT). \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 2000 (\u0442.\u043a. \u043c\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0438 \u0441\u0435\u0431\u044f 2000 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432), 66 (\u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 \u0441\u0430\u043c\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438\u0437 2000 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432), 278 (\u0447\u0438\u0441\u043b\u043e \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 DistilBERT).<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yi\/bf\/lp\/yibflpzn_dbzi72nvns_q92gaqw.png\" alt=\"bert-distilbert-output-tensor-predictions\"><\/p>\n<p>  <\/p>\n<h1 id=\"raspakovka-vyhodnogo-tenzora-berta\">\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430 BERT&#8217;\u0430<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u043f\u0430\u043a\u0443\u0435\u043c \u044d\u0442\u043e\u0442 3-d \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043d\u0437\u043e\u0440. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kq\/cr\/k1\/kqcrk198-zwu5t10mtsq4pxri3i.png\" alt=\"bert-output-tensor\"><\/p>\n<p>  <\/p>\n<h1 id=\"puteshestvie-podhodit-k-koncu\">\u041f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443<\/h1>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ie\/a4\/ob\/iea4ob8zt474ku1j4uw1uthupdq.png\" alt=\"bert-input-to-output-tensor-recap\"><\/p>\n<p>  <\/p>\n<h1 id=\"poluchenie-samoy-vazhnoy-chasti\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0439 \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/h1>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434 BERT&#8217;\u0430 \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u0430 [CLS]. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043a\u0443\u0431\u0430 \u0438 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/84\/5i\/pd\/845ipdjygzhjk4t-k6vj4hrbmem.png\" alt=\"bert-output-tensor-selection\"><\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u0435\u043c \u044d\u0442\u043e\u0442 3d \u0442\u0435\u043d\u0437\u043e\u0440 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c 2d \u0442\u0435\u043d\u0437\u043e\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0420\u0430\u0437\u0440\u0435\u0436\u044c\u0442\u0435 \u0432\u044b\u0445\u043e\u0434 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u0445, \u0432\u043e\u0437\u044c\u043c\u0438\u0442\u0435 \u0432\u0441\u0435 \u0432\u044b\u0445\u043e\u0434\u044b \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u043a  features = last_hidden_states[0][:,0,:].numpy()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>features<\/strong> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f 2d \u043c\u0430\u0441\u0441\u0438\u0432 numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sg\/e7\/_i\/sge7_iy7hdtmvxyk41ajpm4xt_a.png\" alt=\"bert-output-cls-senteence-embeddings\"><\/p>\n<p>  <\/p>\n<p><em>\u0422\u0435\u043d\u0437\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u043b\u0438 \u0438\u0437 \u0432\u044b\u0445\u043e\u0434\u0430 BERT&#8217;\u0430<\/em><\/p>\n<p>  <\/p>\n<h1 id=\"nabor-dannyh-dlya-logisticheskoy-regressii\">\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 BERT&#8217;\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438. \u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f 768 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0430 \u043c\u0435\u0442\u043a\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ul\/33\/yn\/ul33ynyfjqqgqwuk-uvwe3mty1k.png\" alt=\"logistic-regression-dataset-features-labels\"><\/p>\n<p>  <\/p>\n<p><em>\u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u044b BERT&#8217;\u0430 \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u0430 [CLS] (\u043f\u043e\u0437\u0438\u0446\u0438\u044f #0), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u043b\u0438 (\u0441\u043c. \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443). \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u2013 \u0432\u044b\u0445\u043e\u0434\u0443 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0438\u0437 \u0441\u0435\u0442\u0438 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u0439\u0441\u044f \u043d\u0430\u0434 \u0431\u043b\u043e\u043a\u043e\u043c \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 BERT\/DistilBERT<\/em><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u0435\u0435 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">labels = df[1] train_features, test_features, train_labels, test_labels = train_test_split(features, labels)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/r_\/e3\/mq\/r_e3mqtxvjry5xoabovb7il_iec.png\" alt=\"bert-distilbert-train-test-split-sentence-embedding\"><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">lr_clf = LogisticRegression() lr_clf.fit(train_features, train_labels)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0430, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">lr_clf.score(test_features, test_labels)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 (accuracy) \u043c\u043e\u0434\u0435\u043b\u0438 \u2013 81%.<\/p>\n<p>  <\/p>\n<h1 id=\"benchmarki\">\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438<\/h1>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f: \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 <strong>96.8<\/strong>. DistilBERT \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u2013 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u043e\u043d\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439. \u0412 \u0445\u043e\u0434\u0435 \u043d\u0435\u0433\u043e BERT \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u0432\u0435\u0441\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439 (\u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u0442\u044c downstream task). \u0422\u043e\u043d\u043a\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 DistilBERT&#8217;\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 <strong>90.7<\/strong>. \u041f\u043e\u043b\u043d\u043e\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c BERT&#8217;\u0430 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 <strong>94.9<\/strong>.<\/p>\n<p>  <\/p>\n<h1 id=\"noutbuk\">\u041d\u043e\u0443\u0442\u0431\u0443\u043a<\/h1>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u0440\u044f\u043c\u043e \u0432 <a href=\"https:\/\/github.com\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">\u043d\u043e\u0442\u0431\u0443\u043a<\/a> \u0438\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 <a href=\"https:\/\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">Colab<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u0425\u043e\u0440\u043e\u0448\u0435\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0442\u043e\u043d\u043a\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430\u0437\u0430\u0434 \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 distilBERT&#8217;\u0430 \u043a BERT&#8217;\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438 <a href=\"https:\/\/twitter.com\/ClementDelangue\" rel=\"nofollow\">Cl\u00e9ment Delangue<\/a>, <a href=\"https:\/\/twitter.com\/SanhEstPasMoi\" rel=\"nofollow\">Victor Sanh<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 Huggingface, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043e\u0442\u0437\u044b\u0432 \u043e \u0440\u0430\u043d\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430.<\/p>\n<p>  <\/p>\n<h1 id=\"avtory\">\u0410\u0432\u0442\u043e\u0440\u044b<\/h1>\n<p>  <\/p>\n<ul>\n<li><strong>\u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430<\/strong> \u2013 <a href=\"https:\/\/jalammar.github.io\/a-visual-guide-to-using-bert-for-the-first-time\/\" rel=\"nofollow\">Jay Alammar<\/a><\/li>\n<li><strong>\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/strong> \u2013 <a href=\"https:\/\/habr.com\/ru\/users\/smekur\/\">\u0421\u043c\u0438\u0440\u043d\u043e\u0432\u0430 \u0415\u043a\u0430\u0442\u0435\u0440\u0438\u043d\u0430<\/a><\/li>\n<li><strong>\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432\u0451\u0440\u0441\u0442\u043a\u0430<\/strong> \u2013 <a href=\"https:\/\/habr.com\/ru\/users\/kouki_rus\/\">\u0428\u043a\u0430\u0440\u0438\u043d \u0421\u0435\u0440\u0433\u0435\u0439<\/a><\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/498144\/\"> https:\/\/habr.com\/ru\/post\/498144\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498144\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1t\/0s\/2u\/1t0s2udwz_c-rqf3jvlxkigemhm.png\" alt=\"bert-distilbert-sentence-classification\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \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 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u043b\u0441\u044f \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442. \u041c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043b\u0430\u0431\u043e\u0440\u0430\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u0442\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0434\u0443\u0449\u0438\u0445 \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u0443\u0436\u0438\u0442 <a href=\"https:\/\/www.blog.google\/products\/search\/search-language-understanding-bert\/\" rel=\"nofollow\">\u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0435 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0441\u0442\u043e\u044f\u0449\u0438\u043c \u0437\u0430 \u043f\u043e\u0438\u0441\u043a\u043e\u043c Google, \u0441\u0442\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c BERT<\/a>. Google \u0432\u0435\u0440\u0438\u0442, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0433 (\u0442.\u0435. \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0432 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u00ab\u0432\u0435\u043b\u0438\u0447\u0430\u0439\u0448\u0438\u0439 \u043f\u0440\u043e\u0440\u044b\u0432 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u044f\u0442\u044c \u043b\u0435\u0442 \u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u0432\u043e \u0432\u0441\u0435\u0439 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u00bb.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0432\u0435\u0440\u0441\u0438\u0439 BERT&#8217;\u0430 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438, \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e, \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u043d\u043e\u0443\u0442\u0431\u0443\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u0438\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 <a href=\"https:\/\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynbhttps:\/colab.research.google.com\/github\/jalammar\/jalammar.github.io\/blob\/master\/notebooks\/bert\/A_Visual_Notebook_to_Using_BERT_for_the_First_Time.ipynb\" rel=\"nofollow\">Colab<\/a>.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-302530","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302530","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=302530"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302530\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}