{"id":295245,"date":"2019-11-26T21:00:12","date_gmt":"2019-11-26T21:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295245"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295245","title":{"rendered":"\u041d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0444\u0438\u043b\u044c\u043c \u2013 \u00ab\u0442\u0432\u043e\u0438 \u0432\u043a\u0443\u0441\u044b \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u00bb"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477630\/\">\u041f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>  \u0411\u044b\u0432\u0430\u0435\u0442 \u0441\u043c\u043e\u0442\u0440\u0438\u0448\u044c \u0444\u0438\u043b\u044c\u043c, \u0438 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u00ab\u044f \u0447\u0442\u043e \u043e\u043f\u044f\u0442\u044c \u043f\u043e\u043f\u0430\u043b\u0441\u044f \u043d\u0430 \u043a\u043b\u0438\u043a\u0431\u0435\u0439\u0442?\u00bb. \u0420\u0435\u0448\u0438\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u0431\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0434\u043d\u043e\u0435 \u043a\u0438\u043d\u043e. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0444\u0438\u043b\u044c\u043c\u0430.<\/p>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u043b\u0435\u0436\u0438\u0442 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0441\u0435\u043d\u0442\u0438\u043c\u0435\u043d\u0442-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0443. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0440\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043e\u0431\u0437\u043e\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0444\u0438\u043b\u044c\u043c\u044b IMDb. \u0421\u0440\u0435\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Google Colab \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0443 \u043a GPU (NVidia Tesla K80).<\/p>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Keras, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u0442\u043e\u044e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f backend TensorFlow, \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0432 Colab 1.15.0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0434\u043e 2.0.0. <\/p>\n<pre><code class=\"python\">from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf !tf_upgrade_v2 -h<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0442\u0443\u0434\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"python\">%matplotlib inline import matplotlib import matplotlib.pyplot as plt<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">import numpy as np from keras.utils import to_categorical from keras import models from keras import layers from keras.datasets import imdb<\/code><\/pre>\n<p>  <\/p>\n<h2>\u0420\u0430\u0437\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 IMDb <\/h2>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4m\/gg\/mj\/4mggmjh34w_zrwpseprbnv8gpwy.png\"><\/p>\n<p>  \u0414\u0430\u0442\u0430\u0441\u0435\u0442 IMDb \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 50 000 \u043e\u0431\u0437\u043e\u0440\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (1) \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (0).  <\/p>\n<ul>\n<li>\u0420\u0435\u0446\u0435\u043d\u0437\u0438\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0438 \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0441\u043b\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/li>\n<\/ul>\n<p>  <\/p>\n<ul>\n<li>\u0421\u043b\u043e\u0432\u0430 \u0432 \u043e\u0431\u0437\u043e\u0440\u0430\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0438\u0445 \u043e\u0431\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u00ab2\u00bb \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0441\u043b\u043e\u0432\u043e<\/li>\n<\/ul>\n<p>  <\/p>\n<ul>\n<li>50 000 \u043e\u0431\u0437\u043e\u0440\u043e\u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0434\u0432\u0430 \u043d\u0430\u0431\u043e\u0440\u0430: 25 000 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 25 000 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d \u0432 Keras. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442\u0435\u0441\u0442 \u0432 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0438 50-50, \u044f \u0441\u043e\u0435\u0434\u0438\u043d\u044e \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 80-20.<\/p>\n<pre><code class=\"python\">from keras.datasets import imdb (training_data, training_targets), (testing_data, testing_targets) = imdb.load_data(num_words=10000) data = np.concatenate((training_data, testing_data), axis=0) targets = np.concatenate((training_targets, testing_targets), axis=0)<\/code><\/pre>\n<p>  <\/p>\n<h2>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u0441 \u0447\u0435\u043c \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c.<\/p>\n<pre><code class=\"python\">print(\"Categories:\", np.unique(targets)) print(\"Number of unique words:\", len(np.unique(np.hstack(data))))<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/i4\/iv\/gq\/i4ivgqp7pzmudiozqn5ollfffcu.png\"><\/p>\n<pre><code class=\"python\">length = [len(i) for i in data] print(\"Average Review length:\", np.mean(length)) print(\"Standard Deviation:\", round(np.std(length)))<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/_l\/3z\/td\/_l3ztdm6ma6lanax8rzewdm_nk4.png\"><\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0434\u0432\u0443\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c: 0 \u0438\u043b\u0438 1, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043e\u0431\u0437\u043e\u0440\u0430. \u0412\u0435\u0441\u044c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 9998 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432, \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u0437\u043e\u0440\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 234 \u0441\u043b\u043e\u0432\u0430 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c 173.<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439.<\/p>\n<pre><code class=\"python\">print(\"Label:\", targets[0]) print(data[0])<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/c0\/fg\/et\/c0fgeth2sdc9d0ycekevqesuqwy.png\"><\/p>\n<pre><code class=\"python\">index = imdb.get_word_index() reverse_index = dict([(value, key) for (key, value) in index.items()])  decoded = \" \".join( [reverse_index.get(i - 3, \"#\") for i in data[0]] ) print(decoded)<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gl\/mj\/kd\/glmjkdqcbp0mha-udlo2g_qgni4.png\"><\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>  \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u0443\u0436\u043d\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0443\u043b\u044f\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0435\u043a\u0442\u043e\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b \u0440\u043e\u0432\u043d\u043e 10 000 \u0447\u0438\u0441\u0435\u043b. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u0437\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u0440\u043e\u0447\u0435 10 000 \u0441\u043b\u043e\u0432, \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043d\u0443\u043b\u044f\u043c\u0438. \u042f \u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u0437\u043e\u0440 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0430\u0437\u043c\u0435\u0440, \u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440. \u0422\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0442\u0438\u043f float.<\/p>\n<pre><code class=\"python\">def vectorize(sequences, dimension = 10000):  results = np.zeros((len(sequences), dimension))  for i, sequence in enumerate(sequences):   results[i, sequence] = 1  return results   data = vectorize(data) targets = np.array(targets).astype(\"float32\")<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u044e \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0435 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u0438 \u0434\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c 4:1.<\/p>\n<pre><code class=\"python\">test_x = data[:10000] test_y = targets[:10000] train_x = data[10000:] train_y = targets[10000:]<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c<\/h2>\n<p>  \u0414\u0435\u043b\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043d\u0430\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435. \u041d\u0430\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441 \u0432\u044b\u0431\u043e\u0440\u0430 \u0442\u0438\u043f\u0430. \u0412 Keras \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439: \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c API. \u0417\u0430\u0442\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435, \u0441\u043a\u0440\u044b\u0442\u044b\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0441\u043b\u043e\u0438. <\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (\u00abdropout\u00bb).\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u00abdense\u00bb \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0435\u0432 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u0412 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043b\u043e\u044f\u0445 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u00abrelu\u00bb, \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043b\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0438\u0433\u043c\u043e\u0438\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u043a\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1.<\/p>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u00abadam\u00bb, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0435\u0441\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044e, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u2014 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u043f\u0430\u0440\u0442\u0438\u0438 500 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u043c\u044f \u044d\u043f\u043e\u0445\u0430\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u044b\u043b\u043e \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u043e, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0430\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0434\u043e\u043b\u044c\u0448\u0435. <\/p>\n<pre><code class=\"python\">model = models.Sequential() # Input - Layer model.add(layers.Dense(50, activation = \"relu\", input_shape=(10000, ))) # Hidden - Layers model.add(layers.Dropout(0.3, noise_shape=None, seed=None)) model.add(layers.Dense(50, activation = \"relu\")) model.add(layers.Dropout(0.2, noise_shape=None, seed=None)) model.add(layers.Dense(50, activation = \"relu\")) # Output- Layer model.add(layers.Dense(1, activation = \"sigmoid\")) model.summary() # compiling the model model.compile(  optimizer = \"adam\",  loss = \"binary_crossentropy\",  metrics = [\"accuracy\"] ) results = model.fit(  train_x, train_y,  epochs= 3,  batch_size = 500,  validation_data = (test_x, test_y) ) print(\"Test-Accuracy:\", np.mean(results.history[\"val_acc\"]))<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fc\/ay\/fd\/fcayfd-sr1jv_ur91nve_ecqm-4.png\"><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0441 \u0448\u0435\u0441\u0442\u044c\u044e \u0441\u043b\u043e\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u043a\u0438\u043d\u043e\u0440\u0435\u0446\u0435\u043d\u0437\u0438\u0439 \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e 0,89. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0447\u0442\u043e \u0431\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u043c\u044b \u0432\u043e\u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u0431\u044b\u043b \u043b\u0438\u0448\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u0443, \u0432\u0435\u0434\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u043e\u043d\u0438 \u0438 \u043d\u0443\u0436\u043d\u044b. \u041d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0434\u043b\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447.<br \/>  \u0421\u0432\u043e\u0438 \u0438\u0434\u0435\u0438 \u0441\u043c\u0435\u043b\u043e \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/477630\/\"> https:\/\/habr.com\/ru\/post\/477630\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477630\/\">\u041f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>  \u0411\u044b\u0432\u0430\u0435\u0442 \u0441\u043c\u043e\u0442\u0440\u0438\u0448\u044c \u0444\u0438\u043b\u044c\u043c, \u0438 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u00ab\u044f \u0447\u0442\u043e \u043e\u043f\u044f\u0442\u044c \u043f\u043e\u043f\u0430\u043b\u0441\u044f \u043d\u0430 \u043a\u043b\u0438\u043a\u0431\u0435\u0439\u0442?\u00bb. \u0420\u0435\u0448\u0438\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u0431\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u043e\u0434\u043d\u043e\u0435 \u043a\u0438\u043d\u043e. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0444\u0438\u043b\u044c\u043c\u0430.<\/p>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u043b\u0435\u0436\u0438\u0442 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0441\u0435\u043d\u0442\u0438\u043c\u0435\u043d\u0442-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0443. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0440\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043e\u0431\u0437\u043e\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0444\u0438\u043b\u044c\u043c\u044b IMDb. \u0421\u0440\u0435\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Google Colab \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0443 \u043a GPU (NVidia Tesla K80).<\/p>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Keras, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u0442\u043e\u044e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f backend TensorFlow, \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0432 Colab 1.15.0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0434\u043e 2.0.0. <\/p>\n<pre><code class=\"python\">from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf !tf_upgrade_v2 -h<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u043a\u0446\u0435\u043d\u0442 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0442\u0443\u0434\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-295245","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295245","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=295245"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295245\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}