{"id":334265,"date":"2022-06-09T15:01:02","date_gmt":"2022-06-09T15:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334265"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334265","title":{"rendered":"<span>\u0422\u0440\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432<\/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<p>\u0414\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 LDA (Latent Dirichlet Allocation). \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 Bert. \u0418 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 WordToVec, \u0441\u043b\u0443\u0436\u0430\u0449\u0438\u0439 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0441\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/18c\/fa5\/01b\/18cfa501b7719193e47a260d5be547b2.jpeg\" width=\"1884\" height=\"1074\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18c\/fa5\/01b\/18cfa501b7719193e47a260d5be547b2.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 110 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043d\u0430 \u043e\u0431\u0449\u0443\u044e \u0442\u0435\u043c\u0443 \u0430\u0443\u0434\u0438\u0442. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u044d\u0442\u0438 \u0442\u0435\u043a\u0441\u0442\u044b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438. \u041c\u0435\u0442\u043e\u0434 LDA \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u0442\u0435\u043c\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043f\u0443\u043b \u0442\u0435\u043a\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/h3>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0418\u0442\u0430\u043a, \u043d\u0430\u0448 \u043a\u043e\u0440\u043f\u0443\u0441 \u2013 \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 python, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u0441\u0432\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440<\/p>\n<pre><code>#\u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0432\u0441\u0435 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 for i in range(len(corpus)):   for j in range(len(corpus[i])):     corpus[i][j] = corpus[i][j].lower()<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0447\u0438\u0441\u043b\u0430.  <\/p>\n<pre><code>#\u0443\u0434\u0430\u043b\u0438\u043c \u0447\u0438\u0441\u043b\u0430 import string def remove_chars_from_text(text, chars):   return ''.join([i for i in text if i not in chars])  for i in range(len(corpus)):   for j in range(len(corpus[i])):     corpus[i][j] = remove_chars_from_text(corpus[i][j], string.digits)<\/code><\/pre>\n<p>\u041d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0448\u0430\u0433\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u044e \u0438 \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b. \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0447\u043d\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.  <\/p>\n<pre><code>replace('~', '').replace('?', '').replace(\"''\", '').replace(\"'\", '').replace(\"=\", '').replace('\u2192', '')<\/code><\/pre>\n<h3>LDA<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0442\u0435\u043a\u0441\u0442 \u0433\u043e\u0442\u043e\u0432 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \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>import nltk from sklearn import feature_extraction import mpld3 from nltk.tokenize import word_tokenize from nltk.tokenize import sent_tokenize from collections import Counter from gensim.corpora.dictionary import Dictionary import pymorphy2<\/code><\/pre>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u2013\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.  <\/p>\n<pre><code>#\u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 def tokenize(texts):     tokens = [w for w in word_tokenize(texts)]     return tokens<\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u043b\u0443\u0447\u0448\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435. \u041f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u043b\u0435\u043c\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443.  <\/p>\n<pre><code>morph = pymorphy2.MorphAnalyzer() for i in range(len(totalvocab_tokenized)):   k = [morph.parse(word)[0].normal_form for word in totalvocab_tokenized[i]]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0432\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c, \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 1 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c \u0432 0,8 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0440\u043f\u0443\u0441\u0430.  <\/p>\n<pre><code>from gensim import corpora dictionary = corpora.Dictionary(l) dictionary.filter_extremes(no_below=1, no_above=0.8)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043a\u0430\u043a\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f.  <\/p>\n<pre><code>corpus_2 = [dictionary.doc2bow(text) for text in l]<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c LDA, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435.  <\/p>\n<pre><code>from gensim import corpora, models, similarities  %time lda = models.LdaModel(corpus_2, num_topics=40, id2word=dictionary) lda.show_topics(10)<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u044b  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/702\/bb4\/3a5\/702bb43a5ce7ea6751e54ae718e97968.jpeg\" width=\"1024\" height=\"496\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/702\/bb4\/3a5\/702bb43a5ce7ea6751e54ae718e97968.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<pre><code>import pyLDAvis import pyLDAvis.gensim_models as gensimvis  pyLDAvis.enable_notebook() vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, dictionary=lda_model.id2word) vis<\/code><\/pre>\n<h3>Bert<\/h3>\n<p>Bert \u2013 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0430\u0437\u044b \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u044b, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0442\u0435\u0440\u044f\u044f \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 Bert, \u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435. \u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CountVectorizer. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 n_gram_range(2, 2,), \u0447\u0442\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<pre><code>from sklearn.feature_extraction.text import CountVectorizer  c = CountVectorizer(ngram_range=(2, 2)).fit([full_list]) candidates = c.get_feature_names()<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Bert \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432-\u0444\u0440\u0430\u0437 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  <\/p>\n<pre><code>from sentence_transformers import SentenceTransformer  bert = SentenceTransformer('distilbert-base-nli-mean-tokens') embedding = bert.encode([full_list]) candidate = bert.encode(candidates)<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u0441\u043b\u043e\u0432\u0430. \u0418 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.  <\/p>\n<pre><code>from sklearn.metrics.pairwise import cosine_similarity top_n = 10 distances = cosine_similarity(doc_embedding, candidate_embeddings) keywords = [candidates[index] for index in distances.argsort()[0][-top_n:]]<\/code><\/pre>\n<pre><code>['\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u0441\u043a\u0438\u043c\u0438',  '\u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0430\u0432\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438',  '\u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f',  '\u043a\u043e\u043c\u043f\u043b\u0430\u0435\u043d\u0441-\u0440\u0438\u0441\u043a\u043e\u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432',  '\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439']<\/code><\/pre>\n<h3>WordToVec<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 2\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c WordToVec, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 python-nltk \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0434\u0430\u043b\u0435\u0435 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<pre><code>words = [nltk.word_tokenize(sentence) for sent in all_sentences] words = [nltk.word_tokenize(sentence) for sent in all_sentences]<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c WordToVec, \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u0440\u043f\u0443\u0441 \u0441\u043b\u043e\u0432 \u043f\u043e\u043f\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442\u0441\u044f 2 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u0441\u043b\u043e\u0432:  <\/p>\n<pre><code>from gensim.models import Word2Vec word2vec = Word2Vec(all_words, min_count=2) vocabulary = word2vec.wv.vocab<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043b\u043e\u0432\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 LDA, \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c.  <\/p>\n<pre><code>sim_words = word2vec.wv.most_similar('\u043e\u0442\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438') sim_words [('\u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u0439', 0.9878754615783691),  ('\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f', 0.9878393411636353),  ('\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438', 0.9859713315963745),  ('\u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435', 0.9857062101364136),  ('\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e\u0441\u0442\u0438', 0.985139787197113),  ('\u0434\u0440\u0443\u0433\u043e\u0439', 0.985068678855896),  ('\u043e\u0431\u0437\u043e\u0440\u043d\u043e\u0439', 0.9845501184463501),  ('\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0439', 0.9845477342605591),  ('\u043f\u0440\u043e\u0430\u0443\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439', 0.9842839241027832),  ('\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e', 0.9833971261978149)]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0439, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432. \u041c\u0435\u0442\u043e\u0434 LDA, \u0445\u043e\u0442\u044c \u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u043d\u043e, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b. Word-to-vec \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f. Bert \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f\u043c\u0438.  <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/670566\/\"> https:\/\/habr.com\/ru\/post\/670566\/<\/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<p>\u0414\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 LDA (Latent Dirichlet Allocation). \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 Bert. \u0418 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 WordToVec, \u0441\u043b\u0443\u0436\u0430\u0449\u0438\u0439 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0441\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 110 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043d\u0430 \u043e\u0431\u0449\u0443\u044e \u0442\u0435\u043c\u0443 \u0430\u0443\u0434\u0438\u0442. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u044d\u0442\u0438 \u0442\u0435\u043a\u0441\u0442\u044b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438. \u041c\u0435\u0442\u043e\u0434 LDA \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u0442\u0435\u043c\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043f\u0443\u043b \u0442\u0435\u043a\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u041f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/h3>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0418\u0442\u0430\u043a, \u043d\u0430\u0448 \u043a\u043e\u0440\u043f\u0443\u0441 \u2013 \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 python, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u0441\u0432\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440<\/p>\n<pre><code>#\u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0432\u0441\u0435 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 for i in range(len(corpus)):   for j in range(len(corpus[i])):     corpus[i][j] = corpus[i][j].lower()<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0447\u0438\u0441\u043b\u0430.  <\/p>\n<pre><code>#\u0443\u0434\u0430\u043b\u0438\u043c \u0447\u0438\u0441\u043b\u0430 import string def remove_chars_from_text(text, chars):   return ''.join([i for i in text if i not in chars])  for i in range(len(corpus)):   for j in range(len(corpus[i])):     corpus[i][j] = remove_chars_from_text(corpus[i][j], string.digits)<\/code><\/pre>\n<p>\u041d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0448\u0430\u0433\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u044e \u0438 \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b. \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0447\u043d\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.  <\/p>\n<pre><code>replace('~', '').replace('?', '').replace(\"''\", '').replace(\"'\", '').replace(\"=\", '').replace('\u2192', '')<\/code><\/pre>\n<h3>LDA<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0442\u0435\u043a\u0441\u0442 \u0433\u043e\u0442\u043e\u0432 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \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>import nltk from sklearn import feature_extraction import mpld3 from nltk.tokenize import word_tokenize from nltk.tokenize import sent_tokenize from collections import Counter from gensim.corpora.dictionary import Dictionary import pymorphy2<\/code><\/pre>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u2013\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.  <\/p>\n<pre><code>#\u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 def tokenize(texts):     tokens = [w for w in word_tokenize(texts)]     return tokens<\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u043b\u0443\u0447\u0448\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435. \u041f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u043b\u0435\u043c\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443.  <\/p>\n<pre><code>morph = pymorphy2.MorphAnalyzer() for i in range(len(totalvocab_tokenized)):   k = [morph.parse(word)[0].normal_form for word in totalvocab_tokenized[i]]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0432\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c, \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0435\u043c \u0432 1 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435, \u0447\u0435\u043c \u0432 0,8 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u043a\u043e\u0440\u043f\u0443\u0441\u0430.  <\/p>\n<pre><code>from gensim import corpora dictionary = corpora.Dictionary(l) dictionary.filter_extremes(no_below=1, no_above=0.8)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043a\u0430\u043a\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f.  <\/p>\n<pre><code>corpus_2 = [dictionary.doc2bow(text) for text in l]<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c LDA, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435.  <\/p>\n<pre><code>from gensim import corpora, models, similarities  %time lda = models.LdaModel(corpus_2, num_topics=40, id2word=dictionary) lda.show_topics(10)<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u044b  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code>import pyLDAvis import pyLDAvis.gensim_models as gensimvis  pyLDAvis.enable_notebook() vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, dictionary=lda_model.id2word) vis<\/code><\/pre>\n<h3>Bert<\/h3>\n<p>Bert \u2013 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0430\u0437\u044b \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u044b, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0442\u0435\u0440\u044f\u044f \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 Bert, \u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435. \u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CountVectorizer. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 n_gram_range(2, 2,), \u0447\u0442\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<pre><code>from sklearn.feature_extraction.text import CountVectorizer  c = CountVectorizer(ngram_range=(2, 2)).fit([full_list]) candidates = c.get_feature_names()<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Bert \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432-\u0444\u0440\u0430\u0437 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  <\/p>\n<pre><code>from sentence_transformers import SentenceTransformer  bert = SentenceTransformer('distilbert-base-nli-mean-tokens') embedding = bert.encode([full_list]) candidate = bert.encode(candidates)<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u0441\u043b\u043e\u0432\u0430. \u0418 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.  <\/p>\n<pre><code>from sklearn.metrics.pairwise import cosine_similarity top_n = 10 distances = cosine_similarity(doc_embedding, candidate_embeddings) keywords = [candidates[index] for index in distances.argsort()[0][-top_n:]]<\/code><\/pre>\n<pre><code>['\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u0441\u043a\u0438\u043c\u0438',  '\u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u043f\u0440\u0430\u0432\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438',  '\u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f',  '\u043a\u043e\u043c\u043f\u043b\u0430\u0435\u043d\u0441-\u0440\u0438\u0441\u043a\u043e\u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432',  '\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439']<\/code><\/pre>\n<h3>WordToVec<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 2\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c WordToVec, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 python-nltk \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0434\u0430\u043b\u0435\u0435 \u043d\u0430 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<pre><code>words = [nltk.word_tokenize(sentence) for sent in all_sentences] words = [nltk.word_tokenize(sentence) for sent in all_sentences]<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c WordToVec, \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u0440\u043f\u0443\u0441 \u0441\u043b\u043e\u0432 \u043f\u043e\u043f\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442\u0441\u044f 2 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u0441\u043b\u043e\u0432:  <\/p>\n<pre><code>from gensim.models import Word2Vec word2vec = Word2Vec(all_words, min_count=2) vocabulary = word2vec.wv.vocab<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043b\u043e\u0432\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u0438 LDA, \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c.  <\/p>\n<pre><code>sim_words = word2vec.wv.most_similar('\u043e\u0442\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438') sim_words [('\u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u0439', 0.9878754615783691),  ('\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f', 0.9878393411636353),  ('\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438', 0.9859713315963745),  ('\u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435', 0.9857062101364136),  ('\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e\u0441\u0442\u0438', 0.985139787197113),  ('\u0434\u0440\u0443\u0433\u043e\u0439', 0.985068678855896),  ('\u043e\u0431\u0437\u043e\u0440\u043d\u043e\u0439', 0.9845501184463501),  ('\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0439', 0.9845477342605591),  ('\u043f\u0440\u043e\u0430\u0443\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439', 0.9842839241027832),  ('\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e', 0.9833971261978149)]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0439, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432. \u041c\u0435\u0442\u043e\u0434 LDA, \u0445\u043e\u0442\u044c \u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u043d\u043e, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0435\u043c\u044b. Word-to-vec \u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f. Bert \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f\u043c\u0438.  <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/670566\/\"> https:\/\/habr.com\/ru\/post\/670566\/<\/a><br \/><\/br><\/br><\/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-334265","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334265","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=334265"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334265\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}