Skip to content

Commit eeefed5

Browse files
authored
Update 3_neural_networks_tutorial.ipynb
1 parent 39bca9f commit eeefed5

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

chapter1/3_neural_networks_tutorial.ipynb

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 2,
54+
"execution_count": 1,
5555
"metadata": {},
5656
"outputs": [
5757
{
@@ -124,7 +124,7 @@
124124
},
125125
{
126126
"cell_type": "code",
127-
"execution_count": 4,
127+
"execution_count": 2,
128128
"metadata": {},
129129
"outputs": [
130130
{
@@ -153,15 +153,15 @@
153153
},
154154
{
155155
"cell_type": "code",
156-
"execution_count": 5,
156+
"execution_count": 6,
157157
"metadata": {},
158158
"outputs": [
159159
{
160160
"name": "stdout",
161161
"output_type": "stream",
162162
"text": [
163-
"tensor([[-0.0204, -0.0268, -0.0829, 0.1420, -0.0192, 0.1848, 0.0723, -0.0393,\n",
164-
" -0.0275, 0.0867]], grad_fn=<ThAddmmBackward>)\n"
163+
"tensor([[ 0.1120, 0.0713, 0.1014, -0.0696, -0.1210, 0.0084, -0.0206, 0.1366,\n",
164+
" -0.0455, -0.0036]], grad_fn=<AddmmBackward>)\n"
165165
]
166166
}
167167
],
@@ -181,7 +181,7 @@
181181
},
182182
{
183183
"cell_type": "code",
184-
"execution_count": 6,
184+
"execution_count": 7,
185185
"metadata": {},
186186
"outputs": [],
187187
"source": [
@@ -232,14 +232,14 @@
232232
},
233233
{
234234
"cell_type": "code",
235-
"execution_count": 7,
235+
"execution_count": 8,
236236
"metadata": {},
237237
"outputs": [
238238
{
239239
"name": "stdout",
240240
"output_type": "stream",
241241
"text": [
242-
"tensor(1.3172, grad_fn=<MseLossBackward>)\n"
242+
"tensor(0.8109, grad_fn=<MseLossBackward>)\n"
243243
]
244244
}
245245
],
@@ -257,9 +257,8 @@
257257
"cell_type": "markdown",
258258
"metadata": {},
259259
"source": [
260-
"Now, if you follow ``loss`` in the backward direction, using its\n",
261-
"``.grad_fn`` attribute, you will see a graph of computations that looks\n",
262-
"like this:\n",
260+
"现在,如果在反向过程中跟随``loss`` , 使用它的\n",
261+
"``.grad_fn`` 属性,将看到如下所示的计算图。\n",
263262
"\n",
264263
"::\n",
265264
"\n",
@@ -268,19 +267,29 @@
268267
" -> MSELoss\n",
269268
" -> loss\n",
270269
"\n",
271-
"So, when we call ``loss.backward()``, the whole graph is differentiated\n",
272-
"w.r.t. the loss, and all Tensors in the graph that has ``requires_grad=True``\n",
273-
"will have their ``.grad`` Tensor accumulated with the gradient.\n",
270+
"所以,当我们调用 ``loss.backward()``时,整张计算图都会\n",
271+
"根据loss进行微分,而且图中所有设置为``requires_grad=True``的张量\n",
272+
"将会拥有一个随着梯度累积的``.grad`` 张量。\n",
274273
"\n",
275-
"For illustration, let us follow a few steps backward:\n",
274+
"为了说明,让我们向后退几步:\n",
276275
"\n"
277276
]
278277
},
279278
{
280279
"cell_type": "code",
281-
"execution_count": null,
280+
"execution_count": 9,
282281
"metadata": {},
283-
"outputs": [],
282+
"outputs": [
283+
{
284+
"name": "stdout",
285+
"output_type": "stream",
286+
"text": [
287+
"<MseLossBackward object at 0x7f3b49fe2470>\n",
288+
"<AddmmBackward object at 0x7f3bb05f17f0>\n",
289+
"<AccumulateGrad object at 0x7f3b4a3c34e0>\n"
290+
]
291+
}
292+
],
284293
"source": [
285294
"print(loss.grad_fn) # MSELoss\n",
286295
"print(loss.grad_fn.next_functions[0][0]) # Linear\n",
@@ -304,7 +313,7 @@
304313
},
305314
{
306315
"cell_type": "code",
307-
"execution_count": 8,
316+
"execution_count": 10,
308317
"metadata": {},
309318
"outputs": [
310319
{
@@ -314,7 +323,7 @@
314323
"conv1.bias.grad before backward\n",
315324
"tensor([0., 0., 0., 0., 0., 0.])\n",
316325
"conv1.bias.grad after backward\n",
317-
"tensor([ 0.0074, -0.0249, -0.0107, 0.0326, -0.0017, -0.0059])\n"
326+
"tensor([ 0.0051, 0.0042, 0.0026, 0.0152, -0.0040, -0.0036])\n"
318327
]
319328
}
320329
],
@@ -364,7 +373,7 @@
364373
},
365374
{
366375
"cell_type": "code",
367-
"execution_count": 9,
376+
"execution_count": 11,
368377
"metadata": {},
369378
"outputs": [],
370379
"source": [
@@ -385,11 +394,10 @@
385394
"cell_type": "markdown",
386395
"metadata": {},
387396
"source": [
388-
".. Note::\n",
397+
".. 注意::\n",
389398
" \n",
390-
" Observe how gradient buffers had to be manually set to zero using\n",
391-
" ``optimizer.zero_grad()``. This is because gradients are accumulated\n",
392-
" as explained in `Backprop`_ section.\n",
399+
" 观察如何使用``optimizer.zero_grad()``手动将梯度缓冲区设置为零。\n",
400+
" 这是因为梯度是按Backprop部分中的说明累积的。\n",
393401
"\n"
394402
]
395403
},
@@ -403,9 +411,9 @@
403411
],
404412
"metadata": {
405413
"kernelspec": {
406-
"display_name": "Pytorch for Deeplearning",
414+
"display_name": "Python 3",
407415
"language": "python",
408-
"name": "pytorch"
416+
"name": "python3"
409417
},
410418
"language_info": {
411419
"codemirror_mode": {
@@ -417,7 +425,7 @@
417425
"name": "python",
418426
"nbconvert_exporter": "python",
419427
"pygments_lexer": "ipython3",
420-
"version": "3.6.7"
428+
"version": "3.7.3"
421429
}
422430
},
423431
"nbformat": 4,

0 commit comments

Comments
 (0)