{"id":470129,"date":"2025-08-09T09:00:27","date_gmt":"2025-08-09T09:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=470129"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=470129","title":{"rendered":"<span>\u041e\u0442\u0433\u0430\u0434\u0430\u0439 \u0441\u043b\u043e\u0432\u043e \u0434\u043d\u044f: \u043e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043a \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438<\/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>\u041d\u0430 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0437\u0430\u0431\u0430\u0432\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u0432 \u0441\u043b\u043e\u0432\u0430 \u2013 <a href=\"https:\/\/contexto.me\" rel=\"noopener noreferrer nofollow\">contexto.me<\/a>, \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0441\u0442: \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0433\u0430\u0434\u0430\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u0438\u0437\u043a\u043e \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0432\u0430\u0448\u0435 \u0441\u043b\u043e\u0432\u043e \u0431\u044b\u043b\u043e \u043a \u043e\u0442\u0432\u0435\u0442\u0443. \u041f\u043e\u0438\u0433\u0440\u0430\u0432 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439, \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0438\u0433\u0440\u0443 \u0441\u0430\u043c\u043e\u043c\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u043e \u0447\u0442\u043e \u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<blockquote>\n<p>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0438\u0433\u0440\u044b: <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/705410\" rel=\"noopener noreferrer nofollow\">\u043e\u0434\u043d\u0430<\/a> \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u043e \u043a\u043e\u0434, <a href=\"https:\/\/habr.com\/ru\/companies\/aitalenthub\/articles\/718064\" rel=\"noopener noreferrer nofollow\">\u0434\u0440\u0443\u0433\u0430\u044f<\/a> \u043f\u0440\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0438\u0441\u0430\u043b\u0430\u0441\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0433\u0440\u044b, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<h2>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0441\u043b\u043e\u0432\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u00abcat\u00bb:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4ce\/2af\/1eb\/4ce2af1eb31440d4f7004cdb16e7f6a8.png\" alt=\"\u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u0448\u043a\u0430\" title=\"\u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u0448\u043a\u0430\" width=\"785\" height=\"339\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/4ce\/2af\/1eb\/4ce2af1eb31440d4f7004cdb16e7f6a8.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4ce\/2af\/1eb\/4ce2af1eb31440d4f7004cdb16e7f6a8.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u0448\u043a\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e 5014 \u2013 \u0437\u043d\u0430\u0447\u0438\u0442, \u0435\u0441\u0442\u044c 5012 \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u043a \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443, \u043e\u043d\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 1. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u00ab\u0433\u043e\u0440\u044f\u0447\u043e-\u0445\u043e\u043b\u043e\u0434\u043d\u043e\u00bb \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043a \u043e\u0442\u0432\u0435\u0442\u0443. \u0418\u0433\u0440\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d69\/760\/6ed\/d697606edbc1dac67697d8fe7dfebc84.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u044b\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u044b\" width=\"762\" height=\"475\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/d69\/760\/6ed\/d697606edbc1dac67697d8fe7dfebc84.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d69\/760\/6ed\/d697606edbc1dac67697d8fe7dfebc84.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u044b<\/figcaption><\/div>\n<\/figure>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u044c\u043c\u0435\u043c PostgreSQL.<\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432:<\/p>\n<pre><code class=\"sql\">CREATE TABLE word ( word VARCHAR NOT NULL, -- \u0441\u0430\u043c\u043e \u0441\u043b\u043e\u0432\u043e rank INTEGER NOT NULL, -- \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0443 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u2013 1 date DATE    NOT NULL, -- \u0434\u0430\u0442\u0430 \u0438\u0433\u0440\u044b CONSTRAINT word_word_date_pk PRIMARY KEY (word, date) );<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"sql\">CREATE TABLE guess ( user_id    VARCHAR   NOT NULL, -- \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f word       VARCHAR   NOT NULL, -- \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e date       DATE      NOT NULL, -- \u0434\u0430\u0442\u0430 \u0438\u0433\u0440\u044b CONSTRAINT guess_user_id_date_word_pk PRIMARY KEY(user_id, date, word),     CONSTRAINT guess_date_word_word_date_word_fk FOREIGN KEY (date, word)       REFERENCES word (date, word) );<\/code><\/pre>\n<h2>\u0421\u0435\u0440\u0432\u0435\u0440<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Next.js, \u0441\u0442\u0438\u043b\u0438 \u2013 Tailwind, ORM \u2013 Drizzle.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0430\u0439\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u0435\u0437 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438\u0433\u0440\u043e\u043a\u043e\u0432 \u043d\u0435 \u0442\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c cookie \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430:<\/p>\n<pre><code class=\"typescript\">export async function tryGuess({   date,   userId,   word, }: {   date: Date   userId: string   word: string }) {   try {     const foundWord = await findWord({ word, date })     if (foundWord == null) {       \/\/ \u0441\u043b\u043e\u0432\u0430 \u043d\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435       return undefined     }     \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0442\u0433\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e     await db       .insert(guess)       .values({         date,         userId,         word,       })       \/\/ \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c       .onConflictDoNothing()     return foundWord   } catch (error) {     logger.error('Failed to insert guess in database')     throw error   } }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043d\u043e Drizzle \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u044f\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443.<\/p>\n<h2>\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0440\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430?<\/h2>\n<p>\u0414\u043b\u044f \u0438\u0433\u0440\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043d\u0430 <a href=\"https:\/\/github.com\/Badestrand\/russian-dictionary\" rel=\"noopener noreferrer nofollow\">github<\/a> \u0438 \u0432\u043e\u043e\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u00abnouns.csv\u00bb.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c jupyter lab (\u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0438\u0442\u043e\u043d\u0430 3.10 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a)<\/p>\n<pre><code class=\"bash\">uv run --python 3.10 --with jupyter jupyter lab<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<pre><code class=\"bash\">!uv pip install navec pymorphy2 pandas<\/code><\/pre>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/natasha\/navec\" rel=\"noopener noreferrer nofollow\"><strong>navec<\/strong><\/a> \u2013 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0440\u0443\u0441\u0441\u043a\u0438\u0445 \u0441\u043b\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f; \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u2013 \u0443 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 (\u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pymorphy2\/pymorphy2\" rel=\"noopener noreferrer nofollow\"><strong>pymorphy2<\/strong><\/a> \u2013 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u043b\u043e\u0432, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430, \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u00abnouns.csv\u00bb, \u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u0438\u0433\u0440\u0435<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pandas-dev\/pandas\" rel=\"noopener noreferrer nofollow\"><strong>pandas<\/strong><\/a> \u2013 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from navec import Navec import pandas as pd import pymorphy2  # \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u043e\u0439 \u2013 bare nouns = pd.read_csv('nouns.csv', sep='\\t')[['bare']] # \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u043f\u043e\u0434 \u043d\u0430\u0448\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 nouns = nouns.rename(columns={\"bare\": \"word\"})  # \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438, \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 navec = Navec.load('navec_hudlit_v1_12B_500K_300d_100q.tar')  # \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u043b\u043e\u0432 morph = pymorphy2.MorphAnalyzer()<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 navec, \u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e (\u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u0442.\u0434.).<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430:<\/p>\n<pre><code class=\"python\">def is_proper_noun(word):     parsed = morph.parse(word)[0]     # \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432     if (word not in navec):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0433\u0435\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f     if ('Geox' in parsed.tag):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u043d\u0430     if ('Name' in parsed.tag):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0444\u0430\u043c\u0438\u043b\u0438\u0438     if ('Surn' in parsed.tag):         return False     # \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435     return 'NOUN' == parsed.tag.POS  filtered_nouns = nouns[nouns['word'].apply(is_proper_noun)] # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b filtered_nouns = filtered_nouns.sort_values('word').drop_duplicates('word', keep='last') filtered_nouns = filtered_nouns.reset_index(drop=True)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c 19874 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 26982.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">def to_vec(word):     return navec[word]  filtered_nouns['embeddings'] = filtered_nouns['word'].apply(to_vec)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fdb\/a68\/e87\/fdba68e87b818ffa85494651c68bcced.png\" width=\"638\" height=\"442\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/fdb\/a68\/e87\/fdba68e87b818ffa85494651c68bcced.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fdb\/a68\/e87\/fdba68e87b818ffa85494651c68bcced.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u044b\u0431\u043e\u0440 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0435\u043b\u0438\u043a\u043e\u043c\u0443 \u0440\u0430\u043d\u0434\u043e\u043c\u0443:<\/p>\n<pre><code class=\"python\">secret_word = filtered_nouns.sample(n=1)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u00ab\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u00bb, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u043c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438\u0433\u0440\u044b. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u2013 \u0443 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u0447\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432\u0430, \u0442\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0433\u043e\u043b \u043c\u0435\u0436\u0434\u0443 \u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ba6\/4c5\/997\/ba64c5997b077681a2802627d847645b.png\" alt=\"\u03b1 &lt; \u03b2\" title=\"\u03b1 &lt; \u03b2\" width=\"993\" height=\"597\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/ba6\/4c5\/997\/ba64c5997b077681a2802627d847645b.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ba6\/4c5\/997\/ba64c5997b077681a2802627d847645b.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u03b1 &lt; \u03b2<\/figcaption><\/div>\n<\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0433\u043b\u0430\u043c\u0438, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0445 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u044b: \u0447\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0433\u043e\u043b, \u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043b\u0438\u0436\u0435 \u043a 1 (\u0443\u0433\u043e\u043b \u0432 0 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443\/\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0433\u043e\u043b \u2013 \u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043b\u0438\u0436\u0435 \u043a -1 (\u0443\u0433\u043e\u043b \u0432 180 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438. \u041f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u043c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\u043c<\/strong> \u0434\u0432\u0443\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/47f\/529\/2f5\/47f5292f52e2a96f44abf622669ee2d6.png\" alt=\"\u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\" title=\"\u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\" width=\"1352\" height=\"482\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/47f\/529\/2f5\/47f5292f52e2a96f44abf622669ee2d6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/47f\/529\/2f5\/47f5292f52e2a96f44abf622669ee2d6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u0447\u0438\u0442\u0430\u0435\u043c:<\/p>\n<pre><code class=\"python\">import math  def cosine_similarity_manual(vec1, vec2):     dot_product = sum(v1 * v2 for v1, v2 in zip(vec1, vec2))     magnitude_vec1 = math.sqrt(sum(v1**2 for v1 in vec1))     magnitude_vec2 = math.sqrt(sum(v2**2 for v2 in vec2))      if magnitude_vec1 == 0 or magnitude_vec2 == 0:         return 0      return dot_product \/ (magnitude_vec1 * magnitude_vec2)    # \u0431\u0435\u0440\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 secret_word_vec = secret_word['embeddings'].values[0] # \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0441 \u043d\u0438\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 filtered_nouns['cosine_similarity'] = filtered_nouns['embeddings'].apply(lambda emb: cosine_similarity_manual(secret_word_vec, emb)) # \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e filtered_nouns = filtered_nouns.sort_values(by='cosine_similarity', ascending=False) filtered_nouns = filtered_nouns.reset_index(drop=True)<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a08\/c20\/1f3\/a08c201f3a25e7aec51ca7d3bf74788c.png\" alt=\"\u041e\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u043a\u0438 \u0434\u0430\u043b\u0435\u043a\u0438\" title=\"\u041e\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u043a\u0438 \u0434\u0430\u043b\u0435\u043a\u0438\" width=\"736\" height=\"435\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/a08\/c20\/1f3\/a08c201f3a25e7aec51ca7d3bf74788c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a08\/c20\/1f3\/a08c201f3a25e7aec51ca7d3bf74788c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041e\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u043a\u0438 \u0434\u0430\u043b\u0435\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440, \u0434\u0430\u0442\u0443 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">from datetime import datetime  filtered_nouns['rank'] = filtered_nouns.index + 1 filtered_nouns['date'] = datetime.today().strftime('%Y-%m-%d')  filtered_nouns[['word', 'rank', 'date']].to_csv('words.csv', index=False)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0434:<\/p>\n<pre><code>psql --command \"\\copy word FROM '\u043f\u0443\u0442\u044c\u0434\u043e\u043f\u0430\u043f\u043a\u0438\/words.csv' WITH (FORMAT csv, HEADER);\"<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u043e\u0434\u0438\u043d \u0434\u0435\u043d\u044c \u0438\u0433\u0440\u044b, \u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0438 \u043d\u0430 \u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434.<\/p>\n<h2>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u2013 \u043a\u0430\u043a \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u0443 \u043e\u0442\u0433\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e?<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u043f\u0435\u0440\u0432\u0430\u044f<\/strong>: \u0431\u0440\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438 \u0437\u0430\u0442\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043a\u043b\u043e\u043d\u044f\u0442\u044c? \u041e\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0435\u0449\u0435 \u0438 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u2013 300, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043e\u0436\u043d\u043e 300 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442.<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0432\u0442\u043e\u0440\u0430\u044f<\/strong>: \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e 2? \u041f\u0440\u043e\u0431\u0443\u0435\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA), \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f (\u043e\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2013 \u043c\u044b \u043f\u0440\u0438\u0432\u0435\u043b\u0438 300-\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043a 2-\u043c\u0435\u0440\u043d\u043e\u043c\u0443).<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0442\u0440\u0435\u0442\u044c\u044f<\/strong>: \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u0437 \u043d\u0438\u0445. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043d\u044e\u0430\u043d\u0441\u044b. \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u043e\u043c\u0435\u0440 5 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0438\u0437\u043a\u043e (5\/6), \u0435\u0433\u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u2013 1 \u0441\u043b\u043e\u0432\u043e. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u0437 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u0430\u043c\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0443\u0433\u043b\u0430, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0435 \u0441\u043c\u043e\u0433, \u0434\u0430 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043f\u043f\u0430\u0440\u0430\u0442 \u0445\u0440\u043e\u043c\u0430\u0435\u0442.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a23\/bba\/503\/a23bba50314579c21ba9e5218dd059ef.png\" alt=\"1 \u2013 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u0434\u043b\u044f 5\" title=\"1 \u2013 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u0434\u043b\u044f 5\" width=\"774\" height=\"538\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/a23\/bba\/503\/a23bba50314579c21ba9e5218dd059ef.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a23\/bba\/503\/a23bba50314579c21ba9e5218dd059ef.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>1 \u2013 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u0434\u043b\u044f 5<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f<\/strong>: \u0432\u0432\u043e\u0434\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 500, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u043c\u0443 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0443 \u043d\u0430 500 \u043c\u0435\u0441\u0442\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0432\u043e (\u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u043e\u043c\u0435\u0440). \u0412\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u044b\u0439 \u043f\u043b\u0430\u043d. \u041d\u0430\u0434\u0451\u0436\u043d\u044b\u0439, \u043a\u0430\u043a \u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u0431\u044b\u043b\u0430 \u0442\u043e\u0447\u043d\u0430\u044f \u043a\u043e\u043f\u0438\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0438\u0433\u0440\u044b, \u0447\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0447\u0435\u0441\u0442\u043d\u043e.<\/p>\n<p><strong>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c<\/strong>: \u043d\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u043d\u0430\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u043e\u0432? \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 <strong>\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439<\/strong> \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0430\u0448\u0438\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>!uv pip install numpy scikit-learn<\/code><\/pre>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/numpy\/numpy\" rel=\"noopener noreferrer nofollow\"><strong>numpy<\/strong><\/a> \u2013 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/scikit-learn\/scikit-learn\" rel=\"noopener noreferrer nofollow\"><strong>scikit-learn<\/strong><\/a> \u2013 \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 (\u0440\u0430\u0437\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0431\u0430\u0442\u0447\u0430 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432)<\/p>\n<pre><code class=\"python\">import numpy as np from sklearn.metrics.pairwise import cosine_similarity  # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 N_SAMPLES = 10 # \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 BATCH_SIZE = 5000  solution_nouns = filtered_nouns.copy() embeddings = np.vstack(solution_nouns['embeddings'].to_list())  # \u0443\u0437\u043d\u0430\u0435\u043c \u0440\u0430\u043d\u0433 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 = N_SAMPLES samples = solution_nouns.sample(n=N_SAMPLES) sample_indices = samples.index.to_numpy()  potential_first = set()  # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a samples \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f for start in range(0, len(solution_nouns), BATCH_SIZE):     end = min(start + BATCH_SIZE, len(solution_nouns))     similarities = cosine_similarity(embeddings[start:end], embeddings)     print(f\"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0431\u0430\u0442\u0447\u0430 {start}-{end}\")          for i, idx in enumerate(range(start, end)):         sorted_indices = np.argsort(similarities[i])[::-1]         sample_positions = [np.where(sorted_indices == si)[0][0] for si in sample_indices]          # \u0435\u0441\u043b\u0438 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0435         if np.array_equal(np.argsort(sample_indices), np.argsort(sample_positions)):             # \u0441\u043b\u043e\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c             potential_first.add(solution_nouns.iloc[idx]['word'])  print(\"\u0412\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430:\") print(samples[['rank', 'word']].values) print(f\"\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430 {N_SAMPLES} \u043f\u043e\u043f\u044b\u0442\u043e\u043a: {potential_first}\")<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/204\/0c7\/52d\/2040c752d924445439abacb97cbcc6d6.png\" alt=\"\u041d\u0430\u0448\u0435\u043b\u0441\u044f\" title=\"\u041d\u0430\u0448\u0435\u043b\u0441\u044f\" width=\"641\" height=\"285\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/204\/0c7\/52d\/2040c752d924445439abacb97cbcc6d6.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/204\/0c7\/52d\/2040c752d924445439abacb97cbcc6d6.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041d\u0430\u0448\u0435\u043b\u0441\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u043d\u0430\u043c \u0432\u0430\u0436\u0435\u043c \u043b\u0438\u0448\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u043e\u0432, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u0445\u043e\u0436\u0438\u043c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0440\u043e\u0438\u043b\u0430\u0441\u044c \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0438 \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0449\u0438\u0445 \u0441\u043b\u043e\u0432.<\/p>\n<p>\u041a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u043b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0441\u043b\u043e\u0432, \u0432\u0434\u0440\u0443\u0433 \u043d\u0430\u0439\u0434\u0435\u043c \u0437\u0430 9 \u043f\u043e\u043f\u044b\u0442\u043e\u043a?<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0435\u0440\u0441\u0438\u044f \u0441 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import numpy as np from sklearn.metrics.pairwise import cosine_similarity  def find_solution(original_nouns, solution_nouns, n_samples, batch_size, random_state):     \"\"\"     \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:         original_nouns: \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u0433\u0430\u0434\u0430\u043d\u043e \u0441\u043b\u043e\u0432\u043e         solution_nouns: \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441\u043b\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439         n_samples: \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u0441\u043b\u043e\u0432         batch_size: \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f         random_state: \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u0441\u043b\u043e\u0432     \"\"\"     embeddings = np.vstack(solution_nouns['embeddings'].to_list())          while True:         print(f\"\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430 {n_samples} \u043f\u043e\u043f\u044b\u0442\u043e\u043a...\")                  # \u0443\u0437\u043d\u0430\u0435\u043c \u0440\u0430\u043d\u0433 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 = n_samples         # random_state \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u0442\u0435\u0440\u044f\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0438 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0435 n_samples         samples = original_nouns.sample(n=n_samples, random_state=random_state)         sample_indices = samples.index.to_numpy()                  potential_first = set()                  # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f         for start in range(0, len(solution_nouns), batch_size):             end = min(start + batch_size, len(solution_nouns))             print(f\"\u041e\u0431\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0431\u0430\u0442\u0447 {start}-{end}\")                          # \u0440\u0430\u0437\u043e\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u0431\u0430\u0442\u0447\u0430 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439             similarities = cosine_similarity(embeddings[start:end], embeddings)                          for i, idx in enumerate(range(start, end)):                 sorted_indices = np.argsort(similarities[i])[::-1]                 sample_positions = [np.where(sorted_indices == si)[0][0] for si in sample_indices]                  # \u0435\u0441\u043b\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0441\u044f, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439                 if np.array_equal(np.argsort(sample_indices), np.argsort(sample_positions)):                     potential_first.add(solution_nouns.iloc[idx]['word'])                  print(f\"\u041d\u0430\u0448\u043b\u0438 {len(potential_first)} \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0437\u0430 {n_samples} \u043f\u043e\u043f\u044b\u0442\u043e\u043a\")                  # \u0432\u044b\u0445\u043e\u0434\u0438\u043c, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u043b\u0438 \u0432\u0435\u0441\u044c \u0434\u0430\u0442\u0430\u0441\u0435\u0442         if len(potential_first) &lt;= 1 or n_samples &gt;= len(solution_nouns):             print(samples[['word', 'rank']])             return n_samples, potential_first                  # \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 &gt; 1, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c         n_samples += 1  # \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 N_SAMPLES = 5 # \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 BATCH_SIZE = 5000 # \u0447\u0442\u043e\u0431\u044b \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0438\u0441\u044c RANDOM_STATE = 42  solution_nouns = filtered_nouns.copy() used_samples, potential_first = find_solution(filtered_nouns, solution_nouns, N_SAMPLES, BATCH_SIZE, RANDOM_STATE)  print(f\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 {potential_first} \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0437\u0430 {used_samples} \u043f\u043e\u043f\u044b\u0442\u043e\u043a\")<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u0443 \u0432 \u0434\u0435\u043b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430 <a href=\"https:\/\/1context.ru\/\" rel=\"noopener noreferrer nofollow\">1context.ru<\/a>.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 jupyter notebook \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 <a href=\"https:\/\/github.com\/veshutov\/contexto\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<p>P.S. \u0412 <a href=\"https:\/\/contexto.me\" rel=\"noopener noreferrer nofollow\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0433\u0440\u0435<\/a> \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u044b\u0433\u0440\u0430\u0442\u044c \u0437\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0434\u043d\u0438, \u0432 \u043d\u0430\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u2013 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/935566\/\"> https:\/\/habr.com\/ru\/articles\/935566\/<\/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>\u041d\u0430 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0437\u0430\u0431\u0430\u0432\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u0432 \u0441\u043b\u043e\u0432\u0430 \u2013 <a href=\"https:\/\/contexto.me\" rel=\"noopener noreferrer nofollow\">contexto.me<\/a>, \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0441\u0442: \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0433\u0430\u0434\u0430\u0442\u044c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u0438\u0434\u043d\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u0438\u0437\u043a\u043e \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0432\u0430\u0448\u0435 \u0441\u043b\u043e\u0432\u043e \u0431\u044b\u043b\u043e \u043a \u043e\u0442\u0432\u0435\u0442\u0443. \u041f\u043e\u0438\u0433\u0440\u0430\u0432 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439, \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0438\u0433\u0440\u0443 \u0441\u0430\u043c\u043e\u043c\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u043e \u0447\u0442\u043e \u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<blockquote>\n<p>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0438\u0433\u0440\u044b: <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/705410\" rel=\"noopener noreferrer nofollow\">\u043e\u0434\u043d\u0430<\/a> \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u043e \u043a\u043e\u0434, <a href=\"https:\/\/habr.com\/ru\/companies\/aitalenthub\/articles\/718064\" rel=\"noopener noreferrer nofollow\">\u0434\u0440\u0443\u0433\u0430\u044f<\/a> \u043f\u0440\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0438\u0441\u0430\u043b\u0430\u0441\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435, \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0433\u0440\u044b, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<h2>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0441\u043b\u043e\u0432\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u00abcat\u00bb:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0412\u0440\u044f\u0434 \u043b\u0438 \u043a\u043e\u0448\u043a\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e 5014 \u2013 \u0437\u043d\u0430\u0447\u0438\u0442, \u0435\u0441\u0442\u044c 5012 \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u043a \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443, \u043e\u043d\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 1. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u00ab\u0433\u043e\u0440\u044f\u0447\u043e-\u0445\u043e\u043b\u043e\u0434\u043d\u043e\u00bb \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043a \u043e\u0442\u0432\u0435\u0442\u0443. \u0418\u0433\u0440\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u044b<\/figcaption><\/div>\n<\/figure>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u044c\u043c\u0435\u043c PostgreSQL.<\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432:<\/p>\n<pre><code class=\"sql\">CREATE TABLE word ( word VARCHAR NOT NULL, -- \u0441\u0430\u043c\u043e \u0441\u043b\u043e\u0432\u043e rank INTEGER NOT NULL, -- \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0443 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u2013 1 date DATE    NOT NULL, -- \u0434\u0430\u0442\u0430 \u0438\u0433\u0440\u044b CONSTRAINT word_word_date_pk PRIMARY KEY (word, date) );<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"sql\">CREATE TABLE guess ( user_id    VARCHAR   NOT NULL, -- \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f word       VARCHAR   NOT NULL, -- \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e date       DATE      NOT NULL, -- \u0434\u0430\u0442\u0430 \u0438\u0433\u0440\u044b CONSTRAINT guess_user_id_date_word_pk PRIMARY KEY(user_id, date, word),     CONSTRAINT guess_date_word_word_date_word_fk FOREIGN KEY (date, word)       REFERENCES word (date, word) );<\/code><\/pre>\n<h2>\u0421\u0435\u0440\u0432\u0435\u0440<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Next.js, \u0441\u0442\u0438\u043b\u0438 \u2013 Tailwind, ORM \u2013 Drizzle.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0430\u0439\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u0435\u0437 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438\u0433\u0440\u043e\u043a\u043e\u0432 \u043d\u0435 \u0442\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c cookie \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430:<\/p>\n<pre><code class=\"typescript\">export async function tryGuess({   date,   userId,   word, }: {   date: Date   userId: string   word: string }) {   try {     const foundWord = await findWord({ word, date })     if (foundWord == null) {       \/\/ \u0441\u043b\u043e\u0432\u0430 \u043d\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435       return undefined     }     \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0442\u0433\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e     await db       .insert(guess)       .values({         date,         userId,         word,       })       \/\/ \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c       .onConflictDoNothing()     return foundWord   } catch (error) {     logger.error('Failed to insert guess in database')     throw error   } }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043d\u043e Drizzle \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u044f\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443.<\/p>\n<h2>\u041e\u0442\u043a\u0443\u0434\u0430 \u0431\u0440\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430?<\/h2>\n<p>\u0414\u043b\u044f \u0438\u0433\u0440\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043d\u0430 <a href=\"https:\/\/github.com\/Badestrand\/russian-dictionary\" rel=\"noopener noreferrer nofollow\">github<\/a> \u0438 \u0432\u043e\u043e\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u00abnouns.csv\u00bb.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c jupyter lab (\u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0438\u0442\u043e\u043d\u0430 3.10 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a)<\/p>\n<pre><code class=\"bash\">uv run --python 3.10 --with jupyter jupyter lab<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<pre><code class=\"bash\">!uv pip install navec pymorphy2 pandas<\/code><\/pre>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/natasha\/navec\" rel=\"noopener noreferrer nofollow\"><strong>navec<\/strong><\/a> \u2013 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0440\u0443\u0441\u0441\u043a\u0438\u0445 \u0441\u043b\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f; \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u2013 \u0443 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 (\u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pymorphy2\/pymorphy2\" rel=\"noopener noreferrer nofollow\"><strong>pymorphy2<\/strong><\/a> \u2013 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u043b\u043e\u0432, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430, \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u043e\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u00abnouns.csv\u00bb, \u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u0438\u0433\u0440\u0435<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/pandas-dev\/pandas\" rel=\"noopener noreferrer nofollow\"><strong>pandas<\/strong><\/a> \u2013 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from navec import Navec import pandas as pd import pymorphy2  # \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u043e\u0439 \u2013 bare nouns = pd.read_csv('nouns.csv', sep='\\t')[['bare']] # \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u043f\u043e\u0434 \u043d\u0430\u0448\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 nouns = nouns.rename(columns={\"bare\": \"word\"})  # \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438, \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 navec = Navec.load('navec_hudlit_v1_12B_500K_300d_100q.tar')  # \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0441\u043b\u043e\u0432 morph = pymorphy2.MorphAnalyzer()<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 navec, \u043d\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e (\u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u0442.\u0434.).<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430:<\/p>\n<pre><code class=\"python\">def is_proper_noun(word):     parsed = morph.parse(word)[0]     # \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432     if (word not in navec):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0433\u0435\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f     if ('Geox' in parsed.tag):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0438\u043c\u0435\u043d\u0430     if ('Name' in parsed.tag):         return False     # \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u0444\u0430\u043c\u0438\u043b\u0438\u0438     if ('Surn' in parsed.tag):         return False     # \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435     return 'NOUN' == parsed.tag.POS  filtered_nouns = nouns[nouns['word'].apply(is_proper_noun)] # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b filtered_nouns = filtered_nouns.sort_values('word').drop_duplicates('word', keep='last') filtered_nouns = filtered_nouns.reset_index(drop=True)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c 19874 \u0441\u043b\u043e\u0432\u0430 \u0438\u0437 26982.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">def to_vec(word):     return navec[word]  filtered_nouns['embeddings'] = filtered_nouns['word'].apply(to_vec)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u044b\u0431\u043e\u0440 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0434\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0435\u043b\u0438\u043a\u043e\u043c\u0443 \u0440\u0430\u043d\u0434\u043e\u043c\u0443:<\/p>\n<pre><code class=\"python\">secret_word = filtered_nouns.sample(n=1)<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u00ab\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u00bb, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u043c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438\u0433\u0440\u044b. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u2013 \u0443 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u0447\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u0441\u043b\u043e\u0432\u0430, \u0442\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0433\u043e\u043b \u043c\u0435\u0436\u0434\u0443 \u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u03b1 &lt; \u03b2<\/figcaption><\/div>\n<\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0433\u043b\u0430\u043c\u0438, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0445 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u044b: \u0447\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0433\u043e\u043b, \u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043b\u0438\u0436\u0435 \u043a 1 (\u0443\u0433\u043e\u043b \u0432 0 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443\/\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0433\u043e\u043b \u2013 \u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u043b\u0438\u0436\u0435 \u043a -1 (\u0443\u0433\u043e\u043b \u0432 180 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u0432\u0430\u043c\u0438. \u041f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u044b\u043c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e\u043c<\/strong> \u0434\u0432\u0443\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e<\/figcaption><\/div>\n<\/figure>\n<p>\u0421\u0447\u0438\u0442\u0430\u0435\u043c:<\/p>\n<pre><code class=\"python\">import math  def cosine_similarity_manual(vec1, vec2):     dot_product = sum(v1 * v2 for v1, v2 in zip(vec1, vec2))     magnitude_vec1 = math.sqrt(sum(v1**2 for v1 in vec1))     magnitude_vec2 = math.sqrt(sum(v2**2 for v2 in vec2))      if magnitude_vec1 == 0 or magnitude_vec2 == 0:         return 0      return dot_product \/ (magnitude_vec1 * magnitude_vec2)    # \u0431\u0435\u0440\u0435\u043c \u0432\u0435\u043a\u0442\u043e\u0440 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 secret_word_vec = secret_word['embeddings'].values[0] # \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0441 \u043d\u0438\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 filtered_nouns['cosine_similarity'] = filtered_nouns['embeddings'].apply(lambda emb: cosine_similarity_manual(secret_word_vec, emb)) # \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e filtered_nouns = filtered_nouns.sort_values(by='cosine_similarity', ascending=False) filtered_nouns = filtered_nouns.reset_index(drop=True)<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u043e\u0432:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041e\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u043a\u0438 \u0434\u0430\u043b\u0435\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440, \u0434\u0430\u0442\u0443 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">from datetime import datetime  filtered_nouns['rank'] = filtered_nouns.index + 1 filtered_nouns['date'] = datetime.today().strftime('%Y-%m-%d')  filtered_nouns[['word', 'rank', 'date']].to_csv('words.csv', index=False)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0434:<\/p>\n<pre><code>psql --command \"\\copy word FROM '\u043f\u0443\u0442\u044c\u0434\u043e\u043f\u0430\u043f\u043a\u0438\/words.csv' WITH (FORMAT csv, HEADER);\"<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430 \u043e\u0434\u0438\u043d \u0434\u0435\u043d\u044c \u0438\u0433\u0440\u044b, \u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0438 \u043d\u0430 \u0433\u043e\u0434 \u0432\u043f\u0435\u0440\u0435\u0434.<\/p>\n<h2>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u2013 \u043a\u0430\u043a \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u0443 \u043e\u0442\u0433\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e?<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u043f\u0435\u0440\u0432\u0430\u044f<\/strong>: \u0431\u0440\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438 \u0437\u0430\u0442\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043a\u043b\u043e\u043d\u044f\u0442\u044c? \u041e\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0435\u0449\u0435 \u0438 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u2013 300, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043e\u0436\u043d\u043e 300 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442.<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0432\u0442\u043e\u0440\u0430\u044f<\/strong>: \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e 2? \u041f\u0440\u043e\u0431\u0443\u0435\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA), \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f (\u043e\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2013 \u043c\u044b \u043f\u0440\u0438\u0432\u0435\u043b\u0438 300-\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043a 2-\u043c\u0435\u0440\u043d\u043e\u043c\u0443).<\/p>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0442\u0440\u0435\u0442\u044c\u044f<\/strong>: \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0438\u0437 \u043d\u0438\u0445. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043d\u044e\u0430\u043d\u0441\u044b. \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440 \u043d\u043e\u043c\u0435\u0440 5 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0438\u0437\u043a\u043e (5\/6), \u0435\u0433\u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u2013 1 \u0441\u043b\u043e\u0432\u043e. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u0437 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u0430\u043c\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0443\u0433\u043b\u0430, \u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0435 \u0441\u043c\u043e\u0433, \u0434\u0430 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043f\u043f\u0430\u0440\u0430\u0442 \u0445\u0440\u043e\u043c\u0430\u0435\u0442.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>1 \u2013 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0441\u043e\u0441\u0435\u0434 \u0434\u043b\u044f 5<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u041c\u044b\u0441\u043b\u044c \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f<\/strong>: \u0432\u0432\u043e\u0434\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 500, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u043c\u0443 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0443 \u043d\u0430 500 \u043c\u0435\u0441\u0442\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0432\u043e (\u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u043e\u043c\u0435\u0440). \u0412\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u044b\u0439 \u043f\u043b\u0430\u043d. \u041d\u0430\u0434\u0451\u0436\u043d\u044b\u0439, \u043a\u0430\u043a \u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u0431\u044b\u043b\u0430 \u0442\u043e\u0447\u043d\u0430\u044f \u043a\u043e\u043f\u0438\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0438\u0433\u0440\u044b, \u0447\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0447\u0435\u0441\u0442\u043d\u043e.<\/p>\n<p><strong>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c<\/strong>: \u043d\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u043d\u0430\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u043e\u0432? \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 <strong>\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439<\/strong> \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0430\u0448\u0438\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code>!uv pip install numpy scikit-learn<\/code><\/pre>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/numpy\/numpy\" rel=\"noopener noreferrer nofollow\"><strong>numpy<\/strong><\/a> \u2013 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/scikit-learn\/scikit-learn\" rel=\"noopener noreferrer nofollow\"><strong>scikit-learn<\/strong><\/a> \u2013 \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u043b \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 (\u0440\u0430\u0437\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0431\u0430\u0442\u0447\u0430 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432)<\/p>\n<pre><code class=\"python\">import numpy as np from sklearn.metrics.pairwise import cosine_similarity  # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 N_SAMPLES = 10 # \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 BATCH_SIZE = 5000  solution_nouns = filtered_nouns.copy() embeddings = np.vstack(solution_nouns['embeddings'].to_list())  # \u0443\u0437\u043d\u0430\u0435\u043c \u0440\u0430\u043d\u0433 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u043b\u043e\u0432 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 = N_SAMPLES samples = solution_nouns.sample(n=N_SAMPLES) sample_indices = samples.index.to_numpy()  potential_first = set()  # \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a samples \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f for start in range(0, len(solution_nouns), BATCH_SIZE):     end = min(start + BATCH_SIZE, len(solution_nouns))     similarities = cosine_similarity(embeddings[start:end],<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-470129","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470129","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=470129"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470129\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}