<commit_before>{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "6bYaCABobL5q"
      },
      "source": [
        "##### Copyright 2018 The TensorFlow Authors."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "cellView": "form",
        "colab": {},
        "colab_type": "code",
        "id": "FlUw7tSKbtg4"
      },
      "outputs": [],
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "08OTcmxgqkc2"
      },
      "source": [
        "# Автоматическое обновление кода до TensorFlow 2\n",
        "\n",
        "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/guide/upgrade\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003e\n",
        "    Смотрите на TensorFlow.org\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003e\n",
        "    Запустите в Google Colab\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003e\n",
        "    Изучайте код на GitHub\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://storage.googleapis.com/tensorflow_docs/docs/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003e\n",
        "    Скачайте ноутбук\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "\u003c/table\u003e\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fj66ZXAzrJC2",
        "colab_type": "text"
      },
      "source": [
        "Note: Вся информация в этом разделе переведена с помощью русскоговорящего Tensorflow сообщества на общественных началах. Поскольку этот перевод не является официальным, мы не гарантируем что он на 100% аккуратен и соответствует [официальной документации на английском языке](https://www.tensorflow.org/?hl=en). Если у вас есть предложение как исправить этот перевод, мы будем очень рады увидеть pull request в [tensorflow/docs](https://github.com/tensorflow/docs) репозиторий GitHub. Если вы хотите помочь сделать документацию по Tensorflow лучше (сделать сам перевод или проверить перевод подготовленный кем-то другим), напишите нам на [<EMAIL> list](https://groups.google.com/a/tensorflow.org/forum/#!forum/docs-ru)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "hZSaRPoybOp5"
      },
      "source": [
        "TensorFlow 2.0 includes many API changes, such as reordering arguments, renaming symbols, and changing default values for parameters. Manually performing all of these modifications would be tedious and prone to error. To streamline the changes, and to make your transition to TF 2.0 as seamless as possible, the TensorFlow team has created the `tf_upgrade_v2` utility to help transition legacy code to the new API.\n",
        "\n",
        "Note: `tf_upgrade_v2` is installed automatically for TensorFlow 1.13 and later (including all TF 2.0 builds).\n",
        "\n",
        "Typical usage is like this:\n",
        "\n",
        "\u003cpre class=\"devsite-terminal devsite-click-to-copy prettyprint lang-bsh\"\u003e\n",
        "tf_upgrade_v2 \\\n",
        "  --intree my_project/ \\\n",
        "  --outtree my_project_v2/ \\\n",
        "  --reportfile report.txt\n",
        "\u003c/pre\u003e\n",
        "\n",
        "It will accelerate your upgrade process by converting existing TensorFlow 1.x Python scripts to TensorFlow 2.0.\n",
        "\n",
        "The conversion script automates as much as possible, but there are still syntactical and stylistic changes that cannot be performed by the script."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "gP9v2vgptdfi"
      },
      "source": [
        "## Compatibility modules\n",
        "\n",
        "Certain API symbols can not be upgraded simply by using a string replacement. To ensure your code is still supported in TensorFlow 2.0, the upgrade script includes a `compat.v1` module. This module replaces TF 1.x symbols like `tf.foo` with the equivalent `tf.compat.v1.foo` reference. While the compatibility module is nice, we recommend that you manually proofread replacements and migrate them to new APIs in the `tf.*` namespace instead of `tf.compat.v1` namespace as quickly as possible.\n",
        "\n",
        "Because of TensorFlow 2.x module deprecations (for example, `tf.flags` and `tf.contrib`), some changes can not be worked around by switching to `compat.v1`. Upgrading this code may require using an additional library (for example, [`absl.flags`](https://github.com/abseil/abseil-py)) or switching to a package in [tensorflow/addons](http://www.github.com/tensorflow/addons).\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "s78bbfjkXYb7"
      },
      "source": [
        "## Recommended upgrade process\n",
        "\n",
        "The rest of this guide demonstrates how to use the upgrade script. While the upgrade script is easy to use, it is strongly recomended that you use the script as part of the following process: \n",
        "\n",
        "1. **Unit Test**: Ensure that the code you’re upgrading has a unit test suite with reasonable coverage. This is Python code, so the language won’t protect you from many classes of mistakes. Also ensure that any dependency you have has already been upgraded to be compatible with TensorFlow 2.0.\n",
        "\n",
        "1. **Install TensorFlow 1.14**: Upgrade your TensorFlow to the latest TensorFlow 1.x version, at least 1.14. This includes the final TensorFlow 2.0 API in `tf.compat.v2`.\n",
        "\n",
        "1. **Test With 1.14**: Ensure your unit tests pass at this point. You’ll be running them repeatedly as you upgrade so starting from green is important.\n",
        "\n",
        "1. **Run the upgrade script**: Run `tf_upgrade_v2` on your entire source tree, tests included. This will upgrade your code to a format where it only uses symbols available in TensorFlow 2.0. Deprecated symbols will be accessed with `tf.compat.v1`. These will will eventually require manual attention, but not immediately.\n",
        "\n",
        "1. **Run the converted tests with TensorFlow 1.14**: Your code should still run fine in TensorFlow 1.14. Run your unit tests again. Any error in your tests here means there’s a bug in the upgrade script. [Please let us know](https://github.com/tensorflow/tensorflow/issues).\n",
        "\n",
        "1. **Check the upgrade report for warnings and errors**: The script writes a report file that explains any conversions you should double-check, or any manual action you need to take. For example: Any remaining instances of contrib will require manual action to remove. Please consult [the RFC for more instructions](https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md). \n",
        "\n",
        "1. **Install TensorFlow 2.0**: At this point it should be safe to switch to TensorFlow 2.0\n",
        "\n",
        "1. **Test with `v1.disable_v2_behavior`**: Re-running your tests with al `v1.disable_v2_behavior()` in the tests main function should give the same results as running under 1.14.\n",
        "\n",
        "1. **Enable V2 Behavior**: Now that your tests work using the v2 API, you can start looking into turning on v2 behavior. Depending on how your code is written this may require some changes. See the [Migration guide](migrate.ipynb) for details."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "6pwSAQEwvscP"
      },<commit_msg>Update upgrade.ipynb<commit_after>{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "6bYaCABobL5q"
      },
      "source": [
        "##### Copyright 2018 The TensorFlow Authors."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 0,
      "metadata": {
        "cellView": "form",
        "colab": {},
        "colab_type": "code",
        "id": "FlUw7tSKbtg4"
      },
      "outputs": [],
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "08OTcmxgqkc2"
      },
      "source": [
        "# Автоматическое обновление кода до TensorFlow 2\n",
        "\n",
        "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/guide/upgrade\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003e\n",
        "    Смотрите на TensorFlow.org\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003e\n",
        "    Запустите в Google Colab\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003e\n",
        "    Изучайте код на GitHub\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://storage.googleapis.com/tensorflow_docs/docs/site/ru/guide/upgrade.ipynb\"\u003e\n",
        "    \u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003e\n",
        "    Скачайте ноутбук\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "\u003c/table\u003e\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fj66ZXAzrJC2",
        "colab_type": "text"
      },
      "source": [
        "Note: Вся информация в этом разделе переведена с помощью русскоговорящего Tensorflow сообщества на общественных началах. Поскольку этот перевод не является официальным, мы не гарантируем что он на 100% аккуратен и соответствует [официальной документации на английском языке](https://www.tensorflow.org/?hl=en). Если у вас есть предложение как исправить этот перевод, мы будем очень рады увидеть pull request в [tensorflow/docs](https://github.com/tensorflow/docs) репозиторий GitHub. Если вы хотите помочь сделать документацию по Tensorflow лучше (сделать сам перевод или проверить перевод подготовленный кем-то другим), напишите нам на [<EMAIL> list](https://groups.google.com/a/tensorflow.org/forum/#!forum/docs-ru)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "hZSaRPoybOp5"
      },
      "source": [
        "TensorFlow 2.0 включает много изменений API, таких как изменение порядка аргументов, переименование символов и изменение значений по умолчанию длы параметров. Ручное исправление всех этих модификций утомительно и подвержено ошибкам. Чтобы упростить изменения и сделать ваш переход на TF 2.0 как можно более плавным, команда TensorFlow создала утилиту `tf_upgrade_v2`, помогающую перейти от legacy кода к новому API.\n",
        "\n",
        "Примечание: `tf_upgrade_v2` устанавливается автоматически для TensorFlow 1.13 и более поздних версий (включая все сборки TF 2.0).\n",
        "\n",
        "Типичное использование выглядит так:\n",
        "\n",
        "\u003cpre class=\"devsite-terminal devsite-click-to-copy prettyprint lang-bsh\"\u003e\n",
        "tf_upgrade_v2 \\\n",
        "  --intree my_project/ \\\n",
        "  --outtree my_project_v2/ \\\n",
        "  --reportfile report.txt\n",
        "\u003c/pre\u003e\n",
        "\n",
        "Это ускорит процесс обновления за счет конвертации существующих скриптов TensorFlow 1.x Python в TensorFlow 2.0.\n",
        "\n",
        "Скрипт конвертации максимально автоматизирует процесс, но все еще существуют синтаксические и стилистические изменения, которые не могут быть выполнены скриптом."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "gP9v2vgptdfi"
      },
      "source": [
        "## Модули совместимости\n",
        "\n",
        "Некоторые символы API не могут быть обновлены просто с использованием замены строк. Чтобы гарантировать поддержку вашего кода в TensorFlow 2.0, скрипт обновления включает в себя модуль `compat.v1`. Этот модуль заменяет символы TF 1.x, такие как `tf.foo`, на эквивалентную ссылку` tf.compat.v1.foo`. Хотя модуль совместимости хорош, мы рекомендуем вам вручную вычитать замены и перенести их на новые API в пространстве имен `tf. *` вместо пространства имен `tf.compat.v1` как можно быстрее.\n",
        "\n",
        "Из-за устаревания модулей TensorFlow 2.x (например, `tf.flags` и` tf.contrib`) некоторые изменения не могут быть обойдены путем переключения на `compat.v1`. Обновление этого кода может потребовать использования дополнительной библиотеки (например, [`absl.flags`] (https://github.com/abseil/abseil-py)) или переключения на пакет в [tenorflow / addons] (http: //www.github.com/tensorflow/addons).\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "s78bbfjkXYb7"
      },
      "source": [
        "## Рекомендуемый процесс обновления\n",
        "\n",
        "Оставшаяся часть руководства демонстрирует использование скрипта обновления. Хоть скрипт обновления прост в использовании, очень рекомендуем вам использовать скрипт как часть следующего процесса: \n",
        "\n",
        "1. ** Модульное тестирование **: убедитесь, что в обновляемом коде имеется набор модульных тестов с разумным охватом. Это код Python, поэтому язык не защитит вас от многих классов ошибок. Также убедитесь, что все ваши зависимости были обновлены до совместимых с TensorFlow 2.0. \n",
        "\n",
        "1. **Install TensorFlow 1.14**: Upgrade your TensorFlow to the latest TensorFlow 1.x version, at least 1.14. This includes the final TensorFlow 2.0 API in `tf.compat.v2`.\n",
        "\n",
        "1. **Test With 1.14**: Ensure your unit tests pass at this point. You’ll be running them repeatedly as you upgrade so starting from green is important.\n",
        "\n",
        "1. **Run the upgrade script**: Run `tf_upgrade_v2` on your entire source tree, tests included. This will upgrade your code to a format where it only uses symbols available in TensorFlow 2.0. Deprecated symbols will be accessed with `tf.compat.v1`. These will will eventually require manual attention, but not immediately.\n",
        "\n",
        "1. **Run the converted tests with TensorFlow 1.14**: Your code should still run fine in TensorFlow 1.14. Run your unit tests again. Any error in your tests here means there’s a bug in the upgrade script. [Please let us know](https://github.com/tensorflow/tensorflow/issues).\n",
        "\n",
        "1. **Check the upgrade report for warnings and errors**: The script writes a report file that explains any conversions you should double-check, or any manual action you need to take. For example: Any remaining instances of contrib will require manual action to remove. Please consult [the RFC for more instructions](https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md). \n",
        "\n",
        "1. **Install TensorFlow 2.0**: At this point it should be safe to switch to TensorFlow 2.0\n",
        "\n",
        "1. **Test with `v1.disable_v2_behavior`**: Re-running your tests with al `v1.disable_v2_behavior()` in the tests main function should give the same results as running under 1.14.\n",
        "\n",
        "1. **Enable V2 Behavior**: Now that your tests work using the v2 API, you can start looking into turning on v2 behavior. Depending on how your code is written this may require some changes. See the [Migration guide](migrate.ipynb) for details."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "6pwSAQEwvscP"
      },
{'fraction_non_alphanumeric': 0.1277891559771478, 'fraction_numerical': 0.02824188854155438, 'mean_word_length': 2.6289849403481322, 'pattern_counts': {'":': 88, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 30, 'lorem ipsum': 0, 'www.': 16, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1635220', 'n_tokens_mistral': 6528, 'n_tokens_neox': 6436, 'n_words': 1809}