Skip to content

Commit

Permalink
update to 2.0 (PaddlePaddle/book#948)
Browse files Browse the repository at this point in the history
* update to 2.0

* fix typo bugs
  • Loading branch information
TCChenlong authored and wadefelix committed Jul 30, 2021
1 parent 2ebd9cc commit 403515b
Show file tree
Hide file tree
Showing 15 changed files with 1,150 additions and 2,135 deletions.
289 changes: 104 additions & 185 deletions paddle2.0_docs/Autoencoder/AutoEncoder.ipynb

Large diffs are not rendered by default.

832 changes: 50 additions & 782 deletions paddle2.0_docs/addition_rnn/addition_rnn.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

87 changes: 40 additions & 47 deletions paddle2.0_docs/dynamic_graph/dynamic_graph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
"source": [
"# 动态图\n",
"\n",
"从飞桨开源框架2.0RC1版本开始,飞桨默认为用户开启了动态图开发模式。在这种模式下,每次执行一个运算,可以立即得到结果(而不是事先定义好网络结构,然后再执行)。\n",
"\n",
"在动态图模式下,您可以更加方便的组织代码,更容易的调试程序,本示例教程将向你介绍飞桨的动态图的使用。\n"
"**作者:** [PaddlePaddle](https://github.com/PaddlePaddle) <br>\n",
"**日期:** 2021.01 <br>\n",
"**摘要:** 从飞桨开源框架2.0版本开始,飞桨默认为用户开启了动态图开发模式。在这种模式下,每次执行一个运算,可以立即得到结果(而不是事先定义好网络结构,然后再执行)。在动态图模式下,你可以更加方便的组织代码,更容易的调试程序,本示例教程将向你介绍飞桨的动态图的使用。\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 设置环境\n",
"## 一、环境配置\n",
"\n",
"我们将使用飞桨2.0RC1版本,从该版本开始,飞桨框架默认开启了动态图模式"
"本教程基于Paddle 2.0 编写,如果您的环境不是本版本,请先参考官网[安装](https://www.paddlepaddle.org.cn/install/quick) Paddle 2.0 "
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.0.0-rc1\n"
"2.0.0\n"
]
}
],
Expand All @@ -45,34 +45,34 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 基本用法\n",
"## 二、基本用法\n",
"\n",
"在动态图模式下,您可以直接运行一个飞桨提供的API,它会立刻返回结果到python。不再需要首先创建一个计算图,然后再给定数据去运行。"
"在动态图模式下,ni可以直接运行一个飞桨提供的API,它会立刻返回结果到python。不再需要首先创建一个计算图,然后再给定数据去运行。"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tensor(shape=[4, 2], dtype=float32, place=CPUPlace, stop_gradient=True,\n",
" [[-0.84287941, -0.43028113],\n",
" [-0.95773113, 0.47691804],\n",
" [ 0.06073142, -1.07852530],\n",
" [ 0.58765173, -0.16525090]])\n",
" [[-0.69923532, 0.61731714],\n",
" [-0.73845196, -0.32286811],\n",
" [ 1.05555582, 0.83517230],\n",
" [-0.54771936, 0.10178845]])\n",
"Tensor(shape=[2], dtype=float32, place=CPUPlace, stop_gradient=True,\n",
" [1., 2.])\n",
"Tensor(shape=[4, 2], dtype=float32, place=CPUPlace, stop_gradient=True,\n",
" [[0.15712059, 1.56971884],\n",
" [0.04226887, 2.47691798],\n",
" [1.06073141, 0.92147470],\n",
" [1.58765173, 1.83474910]])\n",
" [[0.30076468, 2.61731720],\n",
" [0.26154804, 1.67713189],\n",
" [2.05555582, 2.83517218],\n",
" [0.45228064, 2.10178852]])\n",
"Tensor(shape=[4], dtype=float32, place=CPUPlace, stop_gradient=True,\n",
" [-1.70344162, -0.00389504, -2.09631920, 0.25714993])\n"
" [ 0.53539896, -1.38418818, 2.72590041, -0.34414244])\n"
]
}
],
Expand All @@ -94,29 +94,29 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 使用python的控制流\n",
"## 三、使用python的控制流\n",
"\n",
"动态图模式下,您可以使用python的条件判断和循环,这类控制语句来执行神经网络的计算。(不再需要`cond`, `loop`这类OP)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 +> [5 6 7]\n",
"1 -> [-3 -3 -3]\n",
"1 +> [5 7 9]\n",
"2 +> [ 5 9 15]\n",
"3 -> [-3 3 21]\n",
"4 -> [-3 11 75]\n",
"4 +> [ 5 21 87]\n",
"5 -> [ -3 27 237]\n",
"6 +> [ 5 69 735]\n",
"7 +> [ 5 133 2193]\n",
"8 +> [ 5 261 6567]\n",
"7 -> [ -3 123 2181]\n",
"8 -> [ -3 251 6555]\n",
"9 -> [ -3 507 19677]\n"
]
}
Expand All @@ -139,15 +139,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 构建更加灵活的网络:控制流\n",
"## 四、构建更加灵活的网络:控制流\n",
"\n",
"- 使用动态图可以用来创建更加灵活的网络,比如根据控制流选择不同的分支网络,和方便的构建权重共享的网络。接下来我们来看一个具体的例子,在这个例子中,第二个线性变换只有0.5的可能性会运行。\n",
"- 在sequence to sequence with attention的机器翻译的示例中,你会看到更实际的使用动态图构建RNN类的网络带来的灵活性。\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -229,31 +229,31 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 构建更加灵活的网络:共享权重\n",
"## 五、构建更加灵活的网络:共享权重\n",
"\n",
"- 使用动态图还可以更加方便的创建共享权重的网络,下面的示例展示了一个共享了权重的简单的AutoEncoder。\n",
"- 你也可以参考图像搜索的示例看到共享参数权重的更实际的使用。"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"step: 0, loss: [0.33854288]\n",
"step: 1, loss: [0.30896515]\n",
"step: 2, loss: [0.28540164]\n",
"step: 3, loss: [0.25925428]\n",
"step: 4, loss: [0.22952458]\n",
"step: 5, loss: [0.19782335]\n",
"step: 6, loss: [0.16653982]\n",
"step: 7, loss: [0.13852617]\n",
"step: 8, loss: [0.11632853]\n",
"step: 9, loss: [0.10132948]\n"
"step: 0, loss: [0.33400834]\n",
"step: 1, loss: [0.31674492]\n",
"step: 2, loss: [0.29477125]\n",
"step: 3, loss: [0.2680785]\n",
"step: 4, loss: [0.23595281]\n",
"step: 5, loss: [0.20035137]\n",
"step: 6, loss: [0.16562223]\n",
"step: 7, loss: [0.13548139]\n",
"step: 8, loss: [0.11210174]\n",
"step: 9, loss: [0.09638017]\n"
]
}
],
Expand All @@ -279,17 +279,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## The end\n",
"## The End\n",
"\n",
"可以看到使用动态图带来了更灵活易用的方式来组网和训练。你也可以在【使用注意力机制的LSTM的机器翻译】和【图片检索】两个示例中看到更完整的动态图的实际应用的灵活和便利。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 403515b

Please sign in to comment.