{"id":431355,"date":"2024-09-05T21:00:23","date_gmt":"2024-09-05T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=431355"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=431355","title":{"rendered":"<span>GPT \u2014 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0434\u043e\u0431\u0440\u0430\/\u0437\u043b\u0430<\/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<blockquote>\n<p>\u041b\u044e\u0431\u0443\u044e \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0449\u043d\u0443\u044e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e \u043b\u044e\u0434\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0438 \u043a\u0430\u043a \u0432 \u0434\u043e\u0431\u0440\u0435, \u0442\u0430\u043a \u0438 \u0432 \u0437\u043b\u043e\u043c \u0443\u043c\u044b\u0441\u043b\u0435: \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043e\u0431\u0440\u0435\u043b\u0438 \u043f\u043e\u0440\u043e\u0445, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0444\u0435\u0439\u0435\u0440\u0432\u0435\u0440\u043a\u0438 \u0438 \u0441\u0430\u043b\u044e\u0442\u044b, \u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0440\u0443\u0436\u0438\u0435 \u0438 \u0431\u043e\u043c\u0431\u044b, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0441\u0449\u0435\u043f\u043b\u044f\u0442\u044c \u0430\u0442\u043e\u043c, \u0441\u0442\u0430\u043b\u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u0448\u0451\u0432\u043e\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u0431\u043e\u043c\u0431\u044b, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u0433\u043e\u0440\u043e\u0434\u0430 \u0438 \u0441\u0442\u0440\u0430\u043d\u044b. \u0422\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u043b\u0435\u043a\u0430\u0440\u0441\u0442\u0432\u0430 \u0431\u0435\u0437 \u043f\u043e\u0431\u043e\u0447\u0435\u043a, \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0437\u043d\u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u043b\u044e\u0431\u044b\u0445\u0434\u043e\u043a\u0442\u043e\u0440\u043e\u0432, \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043a\u043d\u0438\u0433\u0438 \u0438 \u043f\u043e\u043c\u043e\u0447\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u0442\u0432\u0443 \u0440\u0435\u0448\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043d\u043e\u00a0\u0442\u0430\u043a\u00a0\u0436\u0435 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 (\u043d\u0435 \u0432\u00a0\u0442\u0435\u0445 \u0440\u0443\u043a\u0430\u0445) \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0435 \u0432\u0438\u0440\u0443\u0441\u044b, \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0434\u044c\u043c\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435&#8230;. \u041d\u043e\u00a0\u044f\u0449\u0438\u043a \u00ab\u043f\u0430\u043d\u0434\u043e\u0440\u044b\u00bb \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0442 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0432\u00a0\u043c\u0438\u0440\u0435 \u0443\u0436\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439, \u043c\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043e\u00a0\u0441\u0438\u0435\u043c \u0447\u0443\u0434\u0435) \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f\u00a0\u0431\u043b\u0430\u0433\u0430!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0413\u0435\u043e\u0440\u0433\u0438\u0439 \u0413\u0430\u0448\u043e\u043a\u0438\u043d, \u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u044e \u0441 7-\u0438 \u043b\u0435\u0442&#8230;<\/p>\n<\/blockquote>\n<p>\u0412 \u043c\u0438\u0440\u0435 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430, \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 GPT, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0441\u043e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u041e\u043d\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u044f\u0437\u044b\u043a\u0438, \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u0430\u0448\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e. \u041d\u043e \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, GPT \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u0432\u043e \u0431\u043b\u0430\u0433\u043e, \u0442\u0430\u043a \u0438 \u0432\u043e \u0437\u043b\u043e.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043c\u043e\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 GPT \u043c\u043e\u0434\u0435\u043b\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u044d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439.<\/p>\n<p>\u0411\u043b\u0438\u0436\u0435 \u043a \u0434\u0435\u043b\u0443:<\/p>\n<h3>\u0427\u0430\u0441\u0442\u044c 1: \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"python\">import time import joblib import pandas as pd import tensorflow as tf # 2.5.2 from tensorflow.keras.layers import Input, Dense, Dropout, BatchNormalization, ActivityRegularization, Embedding from tensorflow.keras.models import Model from tensorflow.keras.optimizers import Adam from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences import numpy as np from tensorflow.python.keras.callbacks import ReduceLROnPlateau, LearningRateScheduler, EarlyStopping, ModelCheckpoint from tensorflow.python.keras.layers import TimeDistributed import tensorflow_datasets as tfds from tensorflow_addons.optimizers import LAMB from tensorflow.keras.regularizers import l1, l2 from transformers import AutoTokenizer from tensorflow.keras.models import load_model  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 with open(\"vopros_otvet.txt\", \"r\", encoding=\"utf-8\") as file:     data = file.read()  in_text_max = 128       # \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 out_text_max = 300      # \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438      gpt3     gpt4 embedding_dim = 16      # 768    # 2048 (\u0420\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432) num_heads = 3           # 12     # 64   (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u043b\u043e\u0432 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432 MultiHeadAttention) dense_dim = 8           # 3072   # 4096 (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 Dense \u0441\u043b\u043e\u044f\u0445) num_layers = 3          # 96     # 96   (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432 Transformer) dropout = 0.3           # 0.3           (\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c dropout)  train_text_but = 1     # \u0424\u043b\u0430\u0433 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 (1 - \u043e\u0431\u0443\u0447\u0430\u0442\u044c, 0 - \u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u0442\u044c) generate_text_but = 1  # \u0424\u043b\u0430\u0433 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 (1 - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, 0 - \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c)<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438. \u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0435\u0441\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 GPT-3 \u0438 GPT-4. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043c\u0430\u043b\u043e VRAM \u0442\u043e \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u044e \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0443&#8230;.<\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u0430 vopros_otvet.txt \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043d\u0435\u043c \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code>\u043f\u0440\u0438\u0432\u0435\u0442! &lt;VOP&gt;  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u0427\u0435\u043c \u044f \u043c\u043e\u0433\u0443 \u0412\u0430\u043c \u043f\u043e\u043c\u043e\u0447\u044c? &lt;END&gt;   \u041a\u0430\u043a\u043e\u0439 \u043a\u0430\u043b\u0438\u0431\u0440 \u0410\u041a \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 5,45 \u0438\u043b\u0438 7,62? &lt;VOP&gt;  \u041a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0435, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432 \u0438 \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c.  \u041a\u0430\u043b\u0438\u0431\u0440 5,45 \u043c\u043c \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432 \u0421\u0421\u0421\u0420 \u0432 1970-\u0445 \u0433\u043e\u0434\u0430\u0445 \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0430\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0438\u0439 \u043a\u0430\u043b\u0438\u0431\u0440 5,56 \u043c\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u0448\u0442\u0443\u0440\u043c\u043e\u0432\u044b\u0445 \u0432\u0438\u043d\u0442\u043e\u0432\u043a\u0430\u0445 M16. 5,45 \u043c\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043e\u0442\u0434\u0430\u0447\u0443 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0434\u0430\u043b\u044c\u043d\u0438\u0445 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f\u0445, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0430\u0442\u0440\u043e\u043d\u044b 5,45 \u043c\u043c \u043b\u0435\u0433\u0447\u0435 \u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u043e\u0441\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u043e\u0435\u043f\u0440\u0438\u043f\u0430\u0441\u043e\u0432. \u041a\u0430\u043b\u0438\u0431\u0440 7,62 \u043c\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0440\u0443\u0436\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0410\u041a-47 \u0438 \u0410\u041a\u041c. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0441\u0438\u043b\u0443 \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c \u0431\u0440\u043e\u043d\u0435\u0436\u0438\u043b\u0435\u0442\u044b \u0438 \u0441\u0442\u0435\u043d\u044b, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0431\u043e\u0435\u0432\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0431\u043b\u0438\u0436\u043d\u0438\u0445 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0440\u0435\u043b\u044f\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445 \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043a\u0430\u043b\u0438\u0431\u0440 5,45 \u043c\u043c. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c \u0431\u0440\u043e\u043d\u0435\u0436\u0438\u043b\u0435\u0442\u044b \u0438 \u0441\u0442\u0435\u043d\u044b, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u0430\u043b\u0438\u0431\u0440 7,62 \u043c\u043c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u044b\u0431\u043e\u0440 \u043a\u0430\u043b\u0438\u0431\u0440\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d \u0438 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. &lt;END&gt; <\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435 \u0447\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f &lt;VOP&gt; \u0430 \u043e\u0442\u0432\u0435\u0442 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f &lt;END&gt; \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 &lt;VOP&gt; \u043d\u0443\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0438 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0447\u0442\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0430 &lt;END&gt; \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u043d\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430 \u043c\u044b\u0441\u043b\u044c \u0438 \u043f\u043e\u0440\u0430 \u0435\u0451 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0440\u0435\u0434&#8230;<\/p>\n<h3>\u0427\u0430\u0441\u0442\u044c 2: \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u2014\u00a0<strong>\u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438.<\/strong>  \u041a\u043e\u0440\u043e\u0442\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0444\u0430\u0439\u043b\u0435 vopros_otvet.txt \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u0442\u0438\u043f\u0430 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438, \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u044b, \u043a\u043e\u0440\u043d\u0438 \u0432 \u0441\u043b\u043e\u0432\u0430\u0445, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0437\u043d\u0430\u043a\u0438, \u0438 \u0434\u0430\u0441\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u043e\u043a\u0435\u043d\u0443 \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440, \u0442\u0430\u043a \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0433\u0447\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b<\/p>\n<pre><code class=\"python\"># \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f special_tokens = [\"&lt;START&gt;\", \"&lt;END&gt;\",\"&lt;VOP&gt;\",\"&lt;\u0441rypto-15:&gt;\"] # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b oov_token = \"&lt;OOV&gt;\"                        # \u0422\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u0441\u043b\u043e\u0432, \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 tokenizer = Tokenizer(lower=False,         # \u041d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443                       split = ' ',         # \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c - \u043f\u0440\u043e\u0431\u0435\u043b                       filters = '',        # \u041d\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b                       oov_token=oov_token, # \u0422\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432                       #char_level=True     # \u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044e                       )  tokenizer.fit_on_texts(data.split('\\n'))   # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 word_index tokenizer.word_index.update({tok: idx+len(tokenizer.word_index) for idx, tok in enumerate(special_tokens)})  # \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432 \u0432 word_counts for tok in special_tokens:     tokenizer.word_counts[tok] = 1 # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432 tokenizer.num_words = len(tokenizer.word_index) + 1 joblib.dump(tokenizer,'tokenizer.joblib') # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430   total_words = len(tokenizer.word_index) + 1 # \u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 print(tokenizer.word_index) # \u0412\u044b\u0432\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 print(total_words) # \u0412\u044b\u0432\u043e\u0434 \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u00a0Tokenizer\u00a0\u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<ul>\n<li>\n<p>special_tokens\u00a0&#8212; \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c.<\/p>\n<\/li>\n<li>\n<p>oov_token\u00a0&#8212; \u044d\u0442\u043e \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043b\u043e\u0432, \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>Tokenizer\u00a0&#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.preprocessing.text, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>fit_on_texts\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Tokenizer, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>word_index\u00a0&#8212; \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>word_counts\u00a0&#8212; \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u0438\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>num_words\u00a0&#8212; \u044d\u0442\u043e \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>joblib.dump\u00a0&#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432 \u0444\u0430\u0439\u043b.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0430\u0441\u0442\u044c 3: \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/h3>\n<pre><code class=\"python\">input_sequences = [] for line in data.split(\"\\n\"):     token_list = tokenizer.texts_to_sequences([line])[0] # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c     for i in range(1, len(token_list)):         n_gram_sequence = token_list[: i + 1] # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 n-\u0433\u0440\u0430\u043c\u043c         input_sequences.append(n_gram_sequence)   max_sequence_len = in_text_max input_sequences = np.array(pad_sequences(input_sequences, maxlen=max_sequence_len, padding=\"pre\")) # \u0414\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0443\u043b\u044f\u043c\u0438  # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 x \u0438 y data = [] xs, labels = input_sequences[:, :-1], input_sequences[:, -1] # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u043a\u0438 input_sequences = [] ys = tf.keras.utils.to_categorical(labels, num_classes=total_words) # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u043a \u0432 one-hot \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<ul>\n<li>\n<p>texts_to_sequences\u00a0&#8212; \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>n-\u0433\u0440\u0430\u043c\u043c\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 n \u0441\u043b\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>pad_sequences\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.preprocessing.sequence, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0443\u043b\u044f\u043c\u0438 \u0434\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>xs\u00a0&#8212; \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>labels\u00a0&#8212; \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0435\u0442\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>to_categorical\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.utils, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u043a \u0432 one-hot \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0430\u0441\u0442\u044c 4: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<pre><code class=\"python\">if train_text_but == 1:      # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438     print(max_sequence_len-1)     input_layer = Input(shape=(max_sequence_len-1,)) # \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439     embedding_layer = tf.keras.layers.Embedding(total_words, embedding_dim)(input_layer) # \u0421\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432     for i in range(num_layers):         transformer_layer = tf.keras.layers.MultiHeadAttention(num_heads=num_heads, key_dim=embedding_dim)(embedding_layer,                                                                                                            embedding_layer) # \u0421\u043b\u043e\u0439 MultiHeadAttention         transformer_layer = tf.keras.layers.BatchNormalization()(transformer_layer) # \u0421\u043b\u043e\u0439 BatchNormalization         transformer_layer = tf.keras.layers.Dropout(dropout)(transformer_layer) # \u0421\u043b\u043e\u0439 Dropout         transformer_layer = tf.keras.layers.ActivityRegularization(l1=0.001, l2=0.001)(transformer_layer) # \u0421\u043b\u043e\u0439 ActivityRegularization          dense_layer = tf.keras.layers.Dense(dense_dim, activation='relu')(transformer_layer) # \u0421\u043b\u043e\u0439 Dense         dropout_layer = tf.keras.layers.Dropout(dropout)(dense_layer) # \u0421\u043b\u043e\u0439 Dropout         flatten_layer = tf.keras.layers.Flatten()(dropout_layer) # \u0421\u043b\u043e\u0439 Flatten     output_layer = tf.keras.layers.Dense(total_words, activation='softmax')(flatten_layer) # \u0412\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439      model = Model(inputs=input_layer, outputs=output_layer) # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438      # \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438     optimizer = LAMB(learning_rate=0.001) # \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 LAMB     model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy']) # \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438     model.summary() # \u0412\u044b\u0432\u043e\u0434 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043c\u043e\u0434\u0435\u043b\u0438<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435\u00a0MultiHeadAttention\u00a0\u0441\u043b\u043e\u0435\u0432 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 LAMB.<\/p>\n<h3>\u0427\u0430\u0441\u0442\u044c 5: \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<pre><code class=\"python\">reduce_lr = ReduceLROnPlateau(monitor='loss',                                   factor=0.98,                                   patience=3,                                   min_lr=0.0000001,                                   verbose=1                                   ) # Callback \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f learning rate     checkpointer = ModelCheckpoint(                         filepath=\"checkpointer.ckpt\",                         monitor='loss', verbose=1, save_weights_only=True) # Callback \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438     call_acc = tf.keras.callbacks.ModelCheckpoint(                         filepath='testing_accuracy.ckpt',                         monitor='accuracy', verbose=1, save_best_only=True,mode='max') # Callback \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043b\u0443\u0447\u0448\u0435\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e     call_loss = tf.keras.callbacks.ModelCheckpoint(                         filepath='testing_loss.ckpt',                         monitor='loss', verbose=1, save_best_only=True,mode='min') # Callback \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u043f\u043e\u0442\u0435\u0440\u0435\u0439     early_stopping = EarlyStopping(monitor='loss', patience=50, restore_best_weights=True) # Callback \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f      def schedule(epoch, lr):         if epoch % 1 == 0:             print('lr- ',round(lr,8))             if lr &gt; 0.000001:                 lr = lr * 0.995         return lr     lr_scheduler = LearningRateScheduler(schedule) # Callback \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f learning rate \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e      # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438     model.fit(xs, ys,               epochs=100,               verbose=1,               batch_size=32,               callbacks=[                         lr_scheduler,                         reduce_lr,                         early_stopping,                     ],               shuffle=True) # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438     model.save('GPT-3-my.h5') # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438     model.save_weights('model_weights_part_{}.h5'.format(1)) # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<ul>\n<li>\n<p>ReduceLROnPlateau\u00a0&#8212; \u044d\u0442\u043e callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 learning rate, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 monitored quantity \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>ModelCheckpoint\u00a0&#8212; \u044d\u0442\u043e callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>EarlyStopping\u00a0&#8212; \u044d\u0442\u043e callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 monitored quantity \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p>LearningRateScheduler\u00a0&#8212; \u044d\u0442\u043e callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 learning rate \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>fit\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Model, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>epochs\u00a0&#8212; \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>verbose\u00a0&#8212; \u044d\u0442\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u0435\u0442\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>batch_size\u00a0&#8212; \u044d\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430.<\/p>\n<\/li>\n<li>\n<p>callbacks\u00a0&#8212; \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a callback-\u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>shuffle\u00a0&#8212; \u044d\u0442\u043e \u0444\u043b\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043f\u043e\u0445\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>save\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Model, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>save_weights\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Model, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0430\u0441\u0442\u044c 6: \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430<\/h3>\n<pre><code class=\"python\">if generate_text_but == 1:     model = load_model('GPT-3-my.h5') # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438     tokenizer = joblib.load('tokenizer.joblib') # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430     # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430     def generate_text(seed_text, next_words, model, max_sequence_len):         for _ in range(next_words):             token_list = tokenizer.texts_to_sequences([seed_text])[0] # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c             token_list = pad_sequences([token_list], maxlen=max_sequence_len - 1, padding='pre') # \u0414\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u043b\u044f\u043c\u0438             predicted = model.predict(token_list, verbose=0) # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430             output_word = \"\"             for word, index in tokenizer.word_index.items():                 if index == np.argmax(predicted): # \u041f\u043e\u0438\u0441\u043a \u0441\u043b\u043e\u0432\u0430 \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e                     output_word = word                     print(output_word)                     break             seed_text += \" \" + output_word # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043a \u0442\u0435\u043a\u0441\u0442\u0443             # time.sleep(1)         return seed_text.title() # \u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430       text_in = '\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c LSD? ' # \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442     generated_text = generate_text(text_in, out_text_max, model, max_sequence_len) # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430     print(generated_text) # \u0412\u044b\u0432\u043e\u0434 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<ul>\n<li>\n<p>load_model\u00a0&#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.models, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>generate_text\u00a0&#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442.<\/p>\n<\/li>\n<li>\n<p>seed_text\u00a0&#8212; \u044d\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.<\/p>\n<\/li>\n<li>\n<p>next_words\u00a0&#8212; \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>predict\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Model, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>argmax\u00a0&#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0numpy, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/p>\n<\/li>\n<\/ul>\n<p><strong>GPT: \u0414\u043e\u0431\u0440\u043e \u0438 \u0417\u043b\u043e<\/strong><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043a\u043e\u0434\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u044d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c. \u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, GPT \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u043e\u043c \u043a\u0430\u043a \u0434\u043b\u044f \u0431\u043b\u0430\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 (\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u043c\u0435\u0434\u0438\u0446\u0438\u043d\u0430, \u043d\u0430\u0443\u043a\u0430, \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u043e), \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445 (\u0434\u0435\u0437\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043c\u043e\u0448\u0435\u043d\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u043a\u0438\u0431\u0435\u0440\u0431\u0443\u043b\u043b\u0438\u043d\u0433, \u043f\u043b\u0430\u0433\u0438\u0430\u0442).<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>GPT\u00a0\u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0438 \u0435\u0433\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430\u00a0\u043c\u0438\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442\u00a0\u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u00a0\u043c\u044b \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e\u0431 \u044d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430 \u0438 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u044c\u0441\u044f \u043a \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0442\u0430\u043a\u0438\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u043a\u0430\u043a GPT.<\/p>\n<p><strong>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GPT \u0432 \u0434\u043e\u0431\u0440\u044b\u0445 \u0438 \u0437\u043b\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 GPT \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c\u0438?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0432\u0430 \u0440\u043e\u043b\u044c \u044d\u0442\u0438\u043a\u0438 \u0432 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430?<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u044d\u0442\u0438 \u0432\u0430\u0436\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043d\u0430\u0439\u0434\u0435\u043c \u043f\u0443\u0442\u0438 \u043a \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e GPT \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e.<\/p>\n<\/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\/841212\/\"> https:\/\/habr.com\/ru\/articles\/841212\/<\/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<blockquote>\n<p>\u041b\u044e\u0431\u0443\u044e \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0449\u043d\u0443\u044e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e \u043b\u044e\u0434\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u043b\u0438 \u043a\u0430\u043a \u0432 \u0434\u043e\u0431\u0440\u0435, \u0442\u0430\u043a \u0438 \u0432 \u0437\u043b\u043e\u043c \u0443\u043c\u044b\u0441\u043b\u0435: \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043e\u0431\u0440\u0435\u043b\u0438 \u043f\u043e\u0440\u043e\u0445, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0444\u0435\u0439\u0435\u0440\u0432\u0435\u0440\u043a\u0438 \u0438 \u0441\u0430\u043b\u044e\u0442\u044b, \u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0440\u0443\u0436\u0438\u0435 \u0438 \u0431\u043e\u043c\u0431\u044b, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0441\u0449\u0435\u043f\u043b\u044f\u0442\u044c \u0430\u0442\u043e\u043c, \u0441\u0442\u0430\u043b\u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0435\u0448\u0451\u0432\u043e\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u0431\u043e\u043c\u0431\u044b, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u0433\u043e\u0440\u043e\u0434\u0430 \u0438 \u0441\u0442\u0440\u0430\u043d\u044b. \u0422\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u043b\u0435\u043a\u0430\u0440\u0441\u0442\u0432\u0430 \u0431\u0435\u0437 \u043f\u043e\u0431\u043e\u0447\u0435\u043a, \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0437\u043d\u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u043b\u044e\u0431\u044b\u0445\u0434\u043e\u043a\u0442\u043e\u0440\u043e\u0432, \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043a\u043d\u0438\u0433\u0438 \u0438 \u043f\u043e\u043c\u043e\u0447\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u0442\u0432\u0443 \u0440\u0435\u0448\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043d\u043e\u00a0\u0442\u0430\u043a\u00a0\u0436\u0435 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 (\u043d\u0435 \u0432\u00a0\u0442\u0435\u0445 \u0440\u0443\u043a\u0430\u0445) \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0435 \u0432\u0438\u0440\u0443\u0441\u044b, \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0434\u044c\u043c\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435&#8230;. \u041d\u043e\u00a0\u044f\u0449\u0438\u043a \u00ab\u043f\u0430\u043d\u0434\u043e\u0440\u044b\u00bb \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0442 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0432\u00a0\u043c\u0438\u0440\u0435 \u0443\u0436\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439, \u043c\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043e\u00a0\u0441\u0438\u0435\u043c \u0447\u0443\u0434\u0435) \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f\u00a0\u0431\u043b\u0430\u0433\u0430!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0413\u0435\u043e\u0440\u0433\u0438\u0439 \u0413\u0430\u0448\u043e\u043a\u0438\u043d, \u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u044e \u0441 7-\u0438 \u043b\u0435\u0442&#8230;<\/p>\n<\/blockquote>\n<p>\u0412 \u043c\u0438\u0440\u0435 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430, \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 GPT, \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0441\u043e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u041e\u043d\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u044f\u0437\u044b\u043a\u0438, \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0438\u0434\u044b \u0442\u0432\u043e\u0440\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u0430\u0448\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e. \u041d\u043e \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, GPT \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u0432\u043e \u0431\u043b\u0430\u0433\u043e, \u0442\u0430\u043a \u0438 \u0432\u043e \u0437\u043b\u043e.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043c\u043e\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 GPT \u043c\u043e\u0434\u0435\u043b\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u044d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439.<\/p>\n<p>\u0411\u043b\u0438\u0436\u0435 \u043a \u0434\u0435\u043b\u0443:<\/p>\n<h3>\u0427\u0430\u0441\u0442\u044c 1: \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"python\">import time import joblib import pandas as pd import tensorflow as tf # 2.5.2 from tensorflow.keras.layers import Input, Dense, Dropout, BatchNormalization, ActivityRegularization, Embedding from tensorflow.keras.models import Model from tensorflow.keras.optimizers import Adam from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences import numpy as np from tensorflow.python.keras.callbacks import ReduceLROnPlateau, LearningRateScheduler, EarlyStopping, ModelCheckpoint from tensorflow.python.keras.layers import TimeDistributed import tensorflow_datasets as tfds from tensorflow_addons.optimizers import LAMB from tensorflow.keras.regularizers import l1, l2 from transformers import AutoTokenizer from tensorflow.keras.models import load_model  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 with open(\"vopros_otvet.txt\", \"r\", encoding=\"utf-8\") as file:     data = file.read()  in_text_max = 128       # \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 out_text_max = 300      # \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438      gpt3     gpt4 embedding_dim = 16      # 768    # 2048 (\u0420\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432) num_heads = 3           # 12     # 64   (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u043b\u043e\u0432 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432 MultiHeadAttention) dense_dim = 8           # 3072   # 4096 (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 Dense \u0441\u043b\u043e\u044f\u0445) num_layers = 3          # 96     # 96   (\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432 Transformer) dropout = 0.3           # 0.3           (\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c dropout)  train_text_but = 1     # \u0424\u043b\u0430\u0433 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 (1 - \u043e\u0431\u0443\u0447\u0430\u0442\u044c, 0 - \u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u0442\u044c) generate_text_but = 1  # \u0424\u043b\u0430\u0433 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 (1 - \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, 0 - \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c)<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438. \u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0435\u0441\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 GPT-3 \u0438 GPT-4. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043c\u0430\u043b\u043e VRAM \u0442\u043e \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0433\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u044e \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0443&#8230;.<\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u0430 vopros_otvet.txt \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043d\u0435\u043c \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code>\u043f\u0440\u0438\u0432\u0435\u0442! &lt;VOP&gt;  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u0427\u0435\u043c \u044f \u043c\u043e\u0433\u0443 \u0412\u0430\u043c \u043f\u043e\u043c\u043e\u0447\u044c? &lt;END&gt;   \u041a\u0430\u043a\u043e\u0439 \u043a\u0430\u043b\u0438\u0431\u0440 \u0410\u041a \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 5,45 \u0438\u043b\u0438 7,62? &lt;VOP&gt;  \u041a\u0430\u043a \u0438 \u0432 \u043b\u044e\u0431\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0435, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432 \u0438 \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c.  \u041a\u0430\u043b\u0438\u0431\u0440 5,45 \u043c\u043c \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432 \u0421\u0421\u0421\u0420 \u0432 1970-\u0445 \u0433\u043e\u0434\u0430\u0445 \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0430\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u0438\u0439 \u043a\u0430\u043b\u0438\u0431\u0440 5,56 \u043c\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u0448\u0442\u0443\u0440\u043c\u043e\u0432\u044b\u0445 \u0432\u0438\u043d\u0442\u043e\u0432\u043a\u0430\u0445 M16. 5,45 \u043c\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043e\u0442\u0434\u0430\u0447\u0443 \u0438 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0434\u0430\u043b\u044c\u043d\u0438\u0445 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f\u0445, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0430\u0442\u0440\u043e\u043d\u044b 5,45 \u043c\u043c \u043b\u0435\u0433\u0447\u0435 \u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u043e\u0441\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u043e\u0435\u043f\u0440\u0438\u043f\u0430\u0441\u043e\u0432. \u041a\u0430\u043b\u0438\u0431\u0440 7,62 \u043c\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0440\u0443\u0436\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0410\u041a-47 \u0438 \u0410\u041a\u041c. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0441\u0438\u043b\u0443 \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c \u0431\u0440\u043e\u043d\u0435\u0436\u0438\u043b\u0435\u0442\u044b \u0438 \u0441\u0442\u0435\u043d\u044b, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0431\u043e\u0435\u0432\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0441\u0442\u0440\u0435\u043b\u044c\u0431\u044b \u043d\u0430 \u0431\u043b\u0438\u0436\u043d\u0438\u0445 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044f\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0440\u0435\u043b\u044f\u0442\u044c \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445 \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043a\u0430\u043b\u0438\u0431\u0440 5,45 \u043c\u043c. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u0438\u0432\u0430\u0442\u044c \u0431\u0440\u043e\u043d\u0435\u0436\u0438\u043b\u0435\u0442\u044b \u0438 \u0441\u0442\u0435\u043d\u044b, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u0430\u043b\u0438\u0431\u0440 7,62 \u043c\u043c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u044b\u0431\u043e\u0440 \u043a\u0430\u043b\u0438\u0431\u0440\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d \u0438 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. &lt;END&gt; <\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435 \u0447\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f &lt;VOP&gt; \u0430 \u043e\u0442\u0432\u0435\u0442 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f &lt;END&gt; \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 &lt;VOP&gt; \u043d\u0443\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0438 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0447\u0442\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0430 &lt;END&gt; \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u043d\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430 \u043c\u044b\u0441\u043b\u044c \u0438 \u043f\u043e\u0440\u0430 \u0435\u0451 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0440\u0435\u0434&#8230;<\/p>\n<h3>\u0427\u0430\u0441\u0442\u044c 2: \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u2014\u00a0<strong>\u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438.<\/strong>  \u041a\u043e\u0440\u043e\u0442\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0444\u0430\u0439\u043b\u0435 vopros_otvet.txt \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u0442\u0438\u043f\u0430 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438, \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u044b, \u043a\u043e\u0440\u043d\u0438 \u0432 \u0441\u043b\u043e\u0432\u0430\u0445, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0437\u043d\u0430\u043a\u0438, \u0438 \u0434\u0430\u0441\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u043e\u043a\u0435\u043d\u0443 \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440, \u0442\u0430\u043a \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0433\u0447\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b<\/p>\n<pre><code class=\"python\"># \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044f special_tokens = [\"&lt;START&gt;\", \"&lt;END&gt;\",\"&lt;VOP&gt;\",\"&lt;\u0441rypto-15:&gt;\"] # \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b oov_token = \"&lt;OOV&gt;\"                        # \u0422\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u0441\u043b\u043e\u0432, \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 tokenizer = Tokenizer(lower=False,         # \u041d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443                       split = ' ',         # \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c - \u043f\u0440\u043e\u0431\u0435\u043b                       filters = '',        # \u041d\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b                       oov_token=oov_token, # \u0422\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u043e\u0432                       #char_level=True     # \u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u044e                       )  tokenizer.fit_on_texts(data.split('\\n'))   # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432 word_index tokenizer.word_index.update({tok: idx+len(tokenizer.word_index) for idx, tok in enumerate(special_tokens)})  # \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432 \u0432 word_counts for tok in special_tokens:     tokenizer.word_counts[tok] = 1 # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432 tokenizer.num_words = len(tokenizer.word_index) + 1 joblib.dump(tokenizer,'tokenizer.joblib') # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430   total_words = len(tokenizer.word_index) + 1 # \u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 print(tokenizer.word_index) # \u0412\u044b\u0432\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 print(total_words) # \u0412\u044b\u0432\u043e\u0434 \u043e\u0431\u0449\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043b\u043e\u0432<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u00a0Tokenizer\u00a0\u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<ul>\n<li>\n<p>special_tokens\u00a0&#8212; \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c.<\/p>\n<\/li>\n<li>\n<p>oov_token\u00a0&#8212; \u044d\u0442\u043e \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043b\u043e\u0432, \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>Tokenizer\u00a0&#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.preprocessing.text, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>fit_on_texts\u00a0&#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0Tokenizer, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>word_index\u00a0&#8212; \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u0438\u0445 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>word_counts\u00a0&#8212; \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u0441 \u0438\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>num_words\u00a0&#8212; \u044d\u0442\u043e \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0432 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>joblib.dump\u00a0&#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432 \u0444\u0430\u0439\u043b.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0430\u0441\u0442\u044c 3: \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/h3>\n<pre><code class=\"python\">input_sequences = [] for line in data.split(\"\\n\"):     token_list = tokenizer.texts_to_sequences([line])[0] # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c     for i in range(1, len(token_list)):         n_gram_sequence = token_list[: i + 1] # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 n-\u0433\u0440\u0430\u043c\u043c         input_sequences.append(n_gram_sequence)   max_sequence_len = in_text_max input_sequences = np.array(pad_sequences(input_sequences, maxlen=max_sequence_len, padding=\"pre\")) # \u0414\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0443\u043b\u044f\u043c\u0438  # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 x \u0438 y data = [] xs, labels = input_sequences[:, :-1], input_sequences[:, -1] # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u043a\u0438 input_sequences = [] ys = tf.keras.utils.to_categorical(labels, num_classes=total_words) # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u043a \u0432 one-hot \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443<\/code><\/pre>\n<p>content_copyUse code\u00a0<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" rel=\"noopener noreferrer nofollow\">with caution<\/a>.Python<\/p>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<ul>\n<li>\n<p>texts_to_sequences\u00a0&#8212; \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>n-\u0433\u0440\u0430\u043c\u043c\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 n \u0441\u043b\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>pad_sequences\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.preprocessing.sequence, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0443\u043b\u044f\u043c\u0438 \u0434\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p>xs\u00a0&#8212; \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>labels\u00a0&#8212; \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0435\u0442\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>to_categorical\u00a0&#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0keras.utils, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u043a \u0432 one-hot \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0430\u0441\u0442\u044c 4: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<pre><code class=\"python\">if train_text_but == 1:      # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438     print(max_sequence_len-1)     input_layer = Input(shape=(max_sequence_len-1,)) # \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439     embedding_layer = tf.keras.layers.Embedding(total_words, embedding_dim)(input_layer) # \u0421\u043b\u043e\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432     for i in range(num_layers):         transformer_layer = tf.keras.layers.MultiHeadAttention(num_heads=num_heads, key_dim=embedding_dim)(embedding_layer,                                                                                                            embedding_layer) # \u0421\u043b\u043e\u0439 MultiHeadAttention         transformer_layer = tf.keras.layers.BatchNormalization()(transformer_layer) # \u0421\u043b\u043e\u0439 BatchNormalization         transformer_layer = tf.keras.layers.Dropout(dropout)(transformer_layer) # \u0421\u043b\u043e\u0439 Dropout         transformer_layer =<\/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-431355","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/431355","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=431355"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/431355\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=431355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=431355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=431355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}