未验证 提交 31662047 编写于 作者: J jzhang533 提交者: GitHub

update several notebooks (#894)

上级 5ab525db
......@@ -29,8 +29,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.0.0\n",
"89af2088b6e74bdfeef2d4d78e08461ed2aafee5\n"
"2.0.0-beta0\n"
]
}
],
......@@ -40,8 +39,7 @@
"import numpy as np\n",
"\n",
"paddle.disable_static()\n",
"print(paddle.__version__)\n",
"print(paddle.__git_commit__)\n"
"print(paddle.__version__)"
]
},
{
......@@ -62,16 +60,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[-0.49341336 -0.8112665 ]\n",
" [ 0.8929015 0.24661176]\n",
" [-0.64440054 -0.7945008 ]\n",
" [-0.07345356 1.3641853 ]]\n",
"[[ 1.5645729 -0.74514765]\n",
" [-0.01248 0.68240154]\n",
" [ 0.11316949 -1.6579045 ]\n",
" [-0.1425675 -1.0153968 ]]\n",
"[1. 2.]\n",
"[[0.5065867 1.1887336 ]\n",
" [1.8929014 2.2466118 ]\n",
" [0.35559946 1.2054992 ]\n",
" [0.92654645 3.3641853 ]]\n",
"[-2.1159463 1.386125 -2.2334023 2.654917 ]\n"
"[[2.5645728 1.2548523 ]\n",
" [0.98752 2.6824017 ]\n",
" [1.1131694 0.3420955 ]\n",
" [0.8574325 0.98460317]]\n",
"[ 0.07427764 1.352323 -3.2026396 -2.173361 ]\n"
]
}
],
......@@ -100,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -108,12 +106,12 @@
"output_type": "stream",
"text": [
"0 +> [5 6 7]\n",
"1 +> [5 7 9]\n",
"1 -> [-3 -3 -3]\n",
"2 +> [ 5 9 15]\n",
"3 -> [-3 3 21]\n",
"4 -> [-3 11 75]\n",
"5 +> [ 5 37 249]\n",
"6 +> [ 5 69 735]\n",
"4 +> [ 5 21 87]\n",
"5 -> [ -3 27 237]\n",
"6 -> [ -3 59 723]\n",
"7 -> [ -3 123 2181]\n",
"8 +> [ 5 261 6567]\n",
"9 +> [ 5 517 19689]\n"
......@@ -146,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -172,28 +170,28 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 [2.0915627]\n",
"200 [0.67530334]\n",
"400 [0.52042854]\n",
"600 [0.28010666]\n",
"800 [0.09739777]\n",
"1000 [0.09307177]\n",
"1200 [0.04252927]\n",
"1400 [0.03095707]\n",
"1600 [0.03022156]\n",
"1800 [0.01616007]\n",
"2000 [0.01069116]\n",
"2200 [0.0055158]\n",
"2400 [0.00195092]\n",
"2600 [0.00101116]\n",
"2800 [0.00192219]\n"
"0 [1.3384138]\n",
"200 [0.7855983]\n",
"400 [0.59084535]\n",
"600 [0.30849028]\n",
"800 [0.26992702]\n",
"1000 [0.03990713]\n",
"1200 [0.07111286]\n",
"1400 [0.01177792]\n",
"1600 [0.03160322]\n",
"1800 [0.02757282]\n",
"2000 [0.00916022]\n",
"2200 [0.00217024]\n",
"2400 [0.00186833]\n",
"2600 [0.00101926]\n",
"2800 [0.0009654]\n"
]
}
],
......@@ -220,8 +218,8 @@
" print(t, loss.numpy())\n",
"\n",
" loss.backward()\n",
" optimizer.minimize(loss)\n",
" model.clear_gradients()"
" optimizer.step()\n",
" optimizer.clear_grad()"
]
},
{
......@@ -230,29 +228,29 @@
"source": [
"# 构建更加灵活的网络:共享权重\n",
"\n",
"- 使用动态图还可以更加方便的创建共享权重的网络,下面的示例展示了一个共享了权重的简单的AutoEncoder的示例。\n",
"- 使用动态图还可以更加方便的创建共享权重的网络,下面的示例展示了一个共享了权重的简单的AutoEncoder。\n",
"- 你也可以参考图像搜索的示例看到共享参数权重的更实际的使用。"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"step: 0, loss: [0.37666085]\n",
"step: 1, loss: [0.3063845]\n",
"step: 2, loss: [0.2647248]\n",
"step: 3, loss: [0.23831272]\n",
"step: 4, loss: [0.21714918]\n",
"step: 5, loss: [0.1955545]\n",
"step: 6, loss: [0.17261818]\n",
"step: 7, loss: [0.15009595]\n",
"step: 8, loss: [0.13051331]\n",
"step: 9, loss: [0.11537809]\n"
"step: 0, loss: [0.33474904]\n",
"step: 1, loss: [0.31669515]\n",
"step: 2, loss: [0.29729688]\n",
"step: 3, loss: [0.27288628]\n",
"step: 4, loss: [0.24694422]\n",
"step: 5, loss: [0.2203041]\n",
"step: 6, loss: [0.19171436]\n",
"step: 7, loss: [0.16213782]\n",
"step: 8, loss: [0.13443354]\n",
"step: 9, loss: [0.11170781]\n"
]
}
],
......@@ -270,8 +268,8 @@
" loss = loss_fn(outputs, inputs)\n",
" loss.backward()\n",
" print(\"step: {}, loss: {}\".format(i, loss.numpy()))\n",
" optimizer.minimize(loss)\n",
" linear.clear_gradients()"
" optimizer.step()\n",
" optimizer.clear_grad()"
]
},
{
......
......@@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 22,
"metadata": {},
"outputs": [
{
......@@ -90,21 +90,21 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"paddle version 0.0.0\n"
"paddle 2.0.0-beta0\n"
]
}
],
"source": [
"import paddle\n",
"paddle.disable_static()\n",
"print(\"paddle version \" + paddle.__version__)"
"print(\"paddle \" + paddle.__version__)"
]
},
{
......@@ -121,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
......@@ -150,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
......@@ -168,14 +168,14 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"w before optimize: -1.7107375860214233\n",
"w before optimize: -1.696260690689087\n",
"b before optimize: 0.0\n"
]
}
......@@ -205,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
......@@ -224,19 +224,19 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch 0 loss [2107.3943]\n",
"epoch 1000 loss [7.8432994]\n",
"epoch 2000 loss [1.7537074]\n",
"epoch 3000 loss [0.39211753]\n",
"epoch 4000 loss [0.08767726]\n",
"finished training, loss [0.01963376]\n"
"epoch 0 loss [2094.069]\n",
"epoch 1000 loss [7.8451133]\n",
"epoch 2000 loss [1.7541145]\n",
"epoch 3000 loss [0.39221546]\n",
"epoch 4000 loss [0.08769739]\n",
"finished training, loss [0.0196382]\n"
]
}
],
......@@ -246,8 +246,8 @@
" y_predict = linear(x_data)\n",
" loss = mse_loss(y_predict, y_data)\n",
" loss.backward()\n",
" sgd_optimizer.minimize(loss)\n",
" linear.clear_gradients()\n",
" sgd_optimizer.step()\n",
" sgd_optimizer.clear_grad()\n",
" \n",
" if i%1000 == 0:\n",
" print(\"epoch {} loss {}\".format(i, loss.numpy()))\n",
......@@ -266,15 +266,15 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"w after optimize: 2.017843246459961\n",
"b after optimize: 9.771851539611816\n"
"w after optimize: 2.0178451538085938\n",
"b after optimize: 9.771825790405273\n"
]
}
],
......@@ -297,7 +297,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 10,
"metadata": {},
"outputs": [
{
......@@ -339,5 +339,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -9,9 +9,7 @@
"本示例教程演示如何在IMDB数据集上用简单的BOW网络完成文本分类的任务。\n",
"\n",
"IMDB数据集是一个对电影评论标注为正向评论与负向评论的数据集,共有25000条文本数据作为训练集,25000条文本数据作为测试集。\n",
"该数据集的官方地址为: http://ai.stanford.edu/~amaas/data/sentiment/\n",
"\n",
"- Warning: `paddle.dataset.imdb`先在是一个非常粗野的实现,后续需要有替代的方案。"
"该数据集的官方地址为: http://ai.stanford.edu/~amaas/data/sentiment/"
]
},
{
......@@ -25,15 +23,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0.0\n",
"264e76cae6861ad9b1d4bcd8c3212f7a78c01e4d\n"
"2.0.0-beta0\n"
]
}
],
......@@ -42,8 +39,7 @@
"import numpy as np\n",
"\n",
"paddle.disable_static()\n",
"print(paddle.__version__)\n",
"print(paddle.__git_commit__)\n"
"print(paddle.__version__)"
]
},
{
......@@ -57,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
......@@ -78,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
......@@ -126,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
......@@ -157,7 +153,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 23,
"metadata": {},
"outputs": [
{
......@@ -190,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 24,
"metadata": {},
"outputs": [
{
......@@ -241,7 +237,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
......@@ -269,19 +265,19 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"epoch: 0, batch_id: 0, loss is: [0.6926701]\n",
"epoch: 0, batch_id: 500, loss is: [0.41248566]\n",
"[validation] accuracy/loss: 0.8505121469497681/0.3615057170391083\n",
"epoch: 1, batch_id: 0, loss is: [0.29521096]\n",
"epoch: 1, batch_id: 500, loss is: [0.2916747]\n",
"[validation] accuracy/loss: 0.86475670337677/0.3259459137916565\n"
"epoch: 0, batch_id: 0, loss is: [0.6918494]\n",
"epoch: 0, batch_id: 500, loss is: [0.33142853]\n",
"[validation] accuracy/loss: 0.8506321907043457/0.3620821535587311\n",
"epoch: 1, batch_id: 0, loss is: [0.37161]\n",
"epoch: 1, batch_id: 500, loss is: [0.2296829]\n",
"[validation] accuracy/loss: 0.8622759580612183/0.3286365270614624\n"
]
}
],
......@@ -311,8 +307,8 @@
" if batch_id % 500 == 0:\n",
" print(\"epoch: {}, batch_id: {}, loss is: {}\".format(epoch, batch_id, avg_loss.numpy()))\n",
" avg_loss.backward()\n",
" opt.minimize(avg_loss)\n",
" model.clear_gradients()\n",
" opt.step()\n",
" opt.clear_grad()\n",
"\n",
" # evaluate model after one epoch\n",
" model.eval()\n",
......@@ -349,13 +345,6 @@
"\n",
"可以看到,在这个数据集上,经过两轮的迭代可以得到86%左右的准确率。你也可以通过调整网络结构和超参数,来获得更好的效果。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......@@ -369,8 +358,20 @@
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
......@@ -27,8 +27,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.0.0\n",
"89af2088b6e74bdfeef2d4d78e08461ed2aafee5\n"
"2.0.0-beta0\n"
]
}
],
......@@ -39,8 +38,7 @@
"import numpy as np\n",
"\n",
"paddle.disable_static()\n",
"print(paddle.__version__)\n",
"print(paddle.__git_commit__)"
"print(paddle.__version__)"
]
},
{
......@@ -61,16 +59,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"--2020-09-04 16:13:35-- https://www.manythings.org/anki/cmn-eng.zip\n",
"Resolving www.manythings.org (www.manythings.org)... 104.24.109.196, 172.67.173.198, 2606:4700:3037::6818:6cc4, ...\n",
"Connecting to www.manythings.org (www.manythings.org)|104.24.109.196|:443... connected.\n",
"--2020-09-10 16:17:25-- https://www.manythings.org/anki/cmn-eng.zip\n",
"Resolving www.manythings.org (www.manythings.org)... 2606:4700:3033::6818:6dc4, 2606:4700:3036::ac43:adc6, 2606:4700:3037::6818:6cc4, ...\n",
"Connecting to www.manythings.org (www.manythings.org)|2606:4700:3033::6818:6dc4|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 1030722 (1007K) [application/zip]\n",
"Saving to: ‘cmn-eng.zip’\n",
"\n",
"cmn-eng.zip 100%[===================>] 1007K 520KB/s in 1.9s \n",
"cmn-eng.zip 100%[===================>] 1007K 91.2KB/s in 11s \n",
"\n",
"2020-09-04 16:13:38 (520 KB/s) - ‘cmn-eng.zip’ saved [1030722/1030722]\n",
"2020-09-10 16:17:38 (91.2 KB/s) - ‘cmn-eng.zip’ saved [1030722/1030722]\n",
"\n",
"Archive: cmn-eng.zip\n",
" inflating: cmn.txt \n",
......@@ -91,7 +89,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
" 23610 cmn.txt\r\n"
" 23610 cmn.txt\n"
]
}
],
......@@ -421,65 +419,65 @@
"output_type": "stream",
"text": [
"epoch:0\n",
"iter 0, loss:[7.6194725]\n",
"iter 200, loss:[3.4147663]\n",
"iter 0, loss:[7.620109]\n",
"iter 200, loss:[2.9760551]\n",
"epoch:1\n",
"iter 0, loss:[3.0931656]\n",
"iter 200, loss:[2.7543137]\n",
"iter 0, loss:[2.9679596]\n",
"iter 200, loss:[3.161064]\n",
"epoch:2\n",
"iter 0, loss:[2.8413522]\n",
"iter 200, loss:[2.340513]\n",
"iter 0, loss:[2.7516625]\n",
"iter 200, loss:[2.9755423]\n",
"epoch:3\n",
"iter 0, loss:[2.597812]\n",
"iter 200, loss:[2.5552855]\n",
"iter 0, loss:[2.7249248]\n",
"iter 200, loss:[2.3419888]\n",
"epoch:4\n",
"iter 0, loss:[2.0783448]\n",
"iter 200, loss:[2.4544785]\n",
"iter 0, loss:[2.3236473]\n",
"iter 200, loss:[2.3453429]\n",
"epoch:5\n",
"iter 0, loss:[1.8709135]\n",
"iter 200, loss:[1.8736631]\n",
"iter 0, loss:[2.1926975]\n",
"iter 200, loss:[2.1977856]\n",
"epoch:6\n",
"iter 0, loss:[1.9589291]\n",
"iter 200, loss:[2.119414]\n",
"iter 0, loss:[2.014393]\n",
"iter 200, loss:[2.1863418]\n",
"epoch:7\n",
"iter 0, loss:[1.5829577]\n",
"iter 200, loss:[1.6002902]\n",
"iter 0, loss:[1.8619595]\n",
"iter 200, loss:[1.8904227]\n",
"epoch:8\n",
"iter 0, loss:[1.6022769]\n",
"iter 200, loss:[1.52694]\n",
"iter 0, loss:[1.5901132]\n",
"iter 200, loss:[1.7812968]\n",
"epoch:9\n",
"iter 0, loss:[1.3616685]\n",
"iter 200, loss:[1.5420443]\n",
"iter 0, loss:[1.341565]\n",
"iter 200, loss:[1.4957166]\n",
"epoch:10\n",
"iter 0, loss:[1.0397792]\n",
"iter 200, loss:[1.2458231]\n",
"iter 0, loss:[1.2202356]\n",
"iter 200, loss:[1.3485341]\n",
"epoch:11\n",
"iter 0, loss:[1.2107158]\n",
"iter 200, loss:[1.426417]\n",
"iter 0, loss:[1.1035374]\n",
"iter 200, loss:[1.2871654]\n",
"epoch:12\n",
"iter 0, loss:[1.1840894]\n",
"iter 200, loss:[1.0999664]\n",
"iter 0, loss:[1.194801]\n",
"iter 200, loss:[1.0479954]\n",
"epoch:13\n",
"iter 0, loss:[1.0968472]\n",
"iter 200, loss:[0.8149167]\n",
"iter 0, loss:[1.0022258]\n",
"iter 200, loss:[1.0899843]\n",
"epoch:14\n",
"iter 0, loss:[0.95585203]\n",
"iter 200, loss:[1.0070628]\n",
"iter 0, loss:[0.93466896]\n",
"iter 200, loss:[0.99347967]\n",
"epoch:15\n",
"iter 0, loss:[0.89463925]\n",
"iter 200, loss:[0.8288595]\n",
"iter 0, loss:[0.83665943]\n",
"iter 200, loss:[0.9594004]\n",
"epoch:16\n",
"iter 0, loss:[0.5672495]\n",
"iter 200, loss:[0.7317069]\n",
"iter 0, loss:[0.78929776]\n",
"iter 200, loss:[0.945769]\n",
"epoch:17\n",
"iter 0, loss:[0.76785177]\n",
"iter 200, loss:[0.5319323]\n",
"iter 0, loss:[0.62574965]\n",
"iter 200, loss:[0.6308163]\n",
"epoch:18\n",
"iter 0, loss:[0.5250005]\n",
"iter 200, loss:[0.4182841]\n",
"iter 0, loss:[0.63433456]\n",
"iter 200, loss:[0.6287957]\n",
"epoch:19\n",
"iter 0, loss:[0.52320284]\n",
"iter 200, loss:[0.47618982]\n"
"iter 0, loss:[0.54270047]\n",
"iter 200, loss:[0.72688276]\n"
]
}
],
......@@ -527,9 +525,8 @@
" print(\"iter {}, loss:{}\".format(iteration, loss.numpy()))\n",
"\n",
" loss.backward()\n",
" opt.minimize(loss)\n",
" encoder.clear_gradients()\n",
" atten_decoder.clear_gradients()"
" opt.step()\n",
" opt.clear_grad()"
]
},
{
......@@ -544,43 +541,43 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"i agree with him\n",
"true: 我同意他。\n",
"pred: 我同意他。\n",
"i think i ll take a bath tonight\n",
"true: 我想我今晚會洗澡。\n",
"pred: 我想我今晚會洗澡。\n",
"he asked for a drink of water\n",
"true: 他要了水喝。\n",
"pred: 他喝了一杯水。\n",
"i began running\n",
"true: 我開始跑。\n",
"pred: 我開始跑。\n",
"i m sick\n",
"true: 我生病了。\n",
"pred: 我生病了。\n",
"you had better go to the dentist s\n",
"true: 你最好去看牙醫。\n",
"pred: 你最好去看牙醫。\n",
"we went for a walk in the forest\n",
"true: 我们去了林中散步。\n",
"pred: 我們去公园散步。\n",
"you ve arrived very early\n",
"true: 你來得很早。\n",
"pred: 你去早个。\n",
"he pretended not to be listening\n",
"true: 他裝作沒在聽。\n",
"pred: 他假装聽到它。\n",
"he always wanted to study japanese\n",
"true: 他一直想學日語。\n",
"pred: 他一直想學日語。\n"
"i want to study french\n",
"true: 我要学法语。\n",
"pred: 我要学法语。\n",
"i didn t know that he was there\n",
"true: 我不知道他在那裡。\n",
"pred: 我不知道他在那裡。\n",
"i called tom\n",
"true: 我給湯姆打了電話。\n",
"pred: 我看見湯姆了。\n",
"he is getting along with his employees\n",
"true: 他和他的員工相處。\n",
"pred: 他和他的員工相處。\n",
"we raced toward the fire\n",
"true: 我們急忙跑向火。\n",
"pred: 我們住在美國。\n",
"i ran away in a hurry\n",
"true: 我趕快跑走了。\n",
"pred: 我在班里是最高。\n",
"he cut the envelope open\n",
"true: 他裁開了那個信封。\n",
"pred: 他裁開了信封。\n",
"he s shorter than tom\n",
"true: 他比湯姆矮。\n",
"pred: 他比湯姆矮。\n",
"i ve just started playing tennis\n",
"true: 我剛開始打網球。\n",
"pred: 我剛去打網球。\n",
"i need to go home\n",
"true: 我该回家了。\n",
"pred: 我该回家了。\n"
]
}
],
......@@ -632,13 +629,6 @@
"\n",
"你还可以通过变换网络结构,调整数据集,尝试不同的参数的方式来进一步提升本示例当中的机器翻译的效果。同时,也可以尝试在其他的类似的任务中用飞桨来完成实际的实践。"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册