<commit_before>{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZwZNOAMZcxl3"
      },
      "source": [
        "##### Copyright 2019 The TensorFlow Neural Structured Learning Authors"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "nxbcnXODdE06"
      },
      "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": {
        "id": "-BszoQj0dSZO"
      },
      "source": [
        "# 使用对抗正则化实现图像分类"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wfqlePz0g6o5"
      },
      "source": [
        "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/adversarial_keras_cnn_mnist\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\">View on TensorFlow.org</a>\n",
        "  </td>\n",
        "  <td>     <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\">在 Google Colab 中运行</a>\n",
        "</td>\n",
        "  <td>\n",
        "    <a target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\">View source on GitHub</a>\n",
        "  </td>\n",
        "  <td>\n",
        "    <a href=\"https://storage.googleapis.com/tensorflow_docs/neural-structured-learning/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\">Download notebook</a>\n",
        "  </td>\n",
        "</table>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oHEGl8h_m6tS"
      },
      "source": [
        "## 概述\n",
        "\n",
        "在本教程中，我们将了解如何使用对抗学习 ([Goodfellow et al., 2014](https://arxiv.org/abs/1412.6572)) 来实现使用神经结构学习 (NSL) 框架的图像分类。\n",
        "\n",
        "对抗学习的核心思想是，除了有机训练数据外，还将使用对抗性扰动数据（称为对抗样本）来训练模型。在人眼看来，这些对抗样本看起来与原始样本相同，但扰动会导致模型混淆并做出错误的预测或分类。对抗样本旨在有意误导模型做出错误的预测或分类。通过使用此类样本进行训练，模型将学习以具备在预测时能够免受对抗扰动影响的鲁棒性。\n",
        "\n",
        "在本教程中，我们以如下几个步骤展示了应用对抗学习以获得使用神经结构学习框架的鲁棒模型：\n",
        "\n",
        "1. 作为基础模型创建神经网络。在本教程中，基础模型是使用 `tf.keras` 函数式 API 创建的；此过程也与使用 `tf.keras` 序列式和子类化 API 创建的模型兼容。有关 TensorFlow 中的 Keras 模型的更多信息，请参阅此[文档](https://www.tensorflow.org/api_docs/python/tf/keras/Model)。\n",
        "2. 使用 NSL 框架提供的 **`AdversarialRegularization`** 封装容器类封装基础模型，以创建新的 `tf.keras.Model` 实例。这个新模型将包含对抗损失，作为其训练目标中的一个正则化项。\n",
        "3. 将训练数据中的样本转换为特征字典。\n",
        "4. 训练并评估新模型。"<commit_msg>Translate adversarial_keras_cnn_mnist.ipynb via GitLocalize<commit_after>{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZwZNOAMZcxl3"
      },
      "source": [
        "##### Copyright 2019 The TensorFlow Neural Structured Learning Authors"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "nxbcnXODdE06"
      },
      "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": {
        "id": "-BszoQj0dSZO"
      },
      "source": [
        "# 使用对抗正则化实现图像分类"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wfqlePz0g6o5"
      },
      "source": [
        "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
        "  <td>     <a target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/adversarial_keras_cnn_mnist\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\">在 TensorFlow.org 上查看</a>   </td>\n",
        "  <td>     <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\">在 Google Colab 中运行</a>\n",
        "</td>\n",
        "  <td>     <a target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\">在 Github 上查看源代码</a>   </td>\n",
        "  <td>     <a href=\"https://storage.googleapis.com/tensorflow_docs/neural-structured-learning/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\">下载笔记本</a>\n",
        "</td>\n",
        "</table>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oHEGl8h_m6tS"
      },
      "source": [
        "## 概述\n",
        "\n",
        "在本教程中，我们将了解如何使用对抗学习 ([Goodfellow et al., 2014](https://arxiv.org/abs/1412.6572)) 来实现使用神经结构学习 (NSL) 框架的图像分类。\n",
        "\n",
        "对抗学习的核心思想是，除了有机训练数据外，还将使用对抗性扰动数据（称为对抗样本）来训练模型。在人眼看来，这些对抗样本看起来与原始样本相同，但扰动会导致模型混淆并做出错误的预测或分类。对抗样本旨在有意误导模型做出错误的预测或分类。通过使用此类样本进行训练，模型将学习以具备在预测时能够免受对抗扰动影响的鲁棒性。\n",
        "\n",
        "在本教程中，我们以如下几个步骤展示了应用对抗学习以获得使用神经结构学习框架的鲁棒模型：\n",
        "\n",
        "1. 作为基础模型创建神经网络。在本教程中，基础模型是使用 `tf.keras` 函数式 API 创建的；此过程也与使用 `tf.keras` 序列式和子类化 API 创建的模型兼容。有关 TensorFlow 中的 Keras 模型的更多信息，请参阅此[文档](https://www.tensorflow.org/api_docs/python/tf/keras/Model)。\n",
        "2. 使用 NSL 框架提供的 **`AdversarialRegularization`** 封装容器类封装基础模型，以创建新的 `tf.keras.Model` 实例。这个新模型将包含对抗损失，作为其训练目标中的一个正则化项。\n",
        "3. 将训练数据中的样本转换为特征字典。\n",
        "4. 训练并评估新模型。"
{'fraction_non_alphanumeric': 0.1709222826845263, 'fraction_numerical': 0.012278498674480257, 'mean_word_length': 2.6129032258064515, 'pattern_counts': {'":': 48, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 22, 'lorem ipsum': 0, 'www.': 14, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2374128', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3264, 'n_words': 408}