Skip to content

Commit 94de252

Browse files
committed
rebuild
1 parent e473150 commit 94de252

137 files changed

Lines changed: 4177 additions & 3935 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎_downloads/advanced_tutorial.ipynb‎

Lines changed: 62 additions & 62 deletions
Large diffs are not rendered by default.

‎_downloads/autograd_tutorial.ipynb‎

Lines changed: 102 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,205 +1,205 @@
11
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"kernelspec": {
6+
"display_name": "Python 3",
7+
"language": "python",
8+
"name": "python3"
9+
},
10+
"language_info": {
11+
"file_extension": ".py",
12+
"mimetype": "text/x-python",
13+
"name": "python",
14+
"pygments_lexer": "ipython3",
15+
"version": "3.5.2",
16+
"codemirror_mode": {
17+
"version": 3,
18+
"name": "ipython"
19+
},
20+
"nbconvert_exporter": "python"
21+
}
22+
},
223
"cells": [
324
{
4-
"cell_type": "code",
525
"execution_count": null,
26+
"source": [
27+
"%matplotlib inline"
28+
],
29+
"outputs": [],
630
"metadata": {
731
"collapsed": false
832
},
9-
"outputs": [],
10-
"source": [
11-
"%matplotlib inline"
12-
]
33+
"cell_type": "code"
1334
},
1435
{
15-
"cell_type": "markdown",
16-
"metadata": {},
1736
"source": [
1837
"\nAutograd: automatic differentiation\n===================================\n\nCentral to all neural networks in PyTorch is the ``autograd`` package.\nLet\u2019s first briefly visit this, and we will then go to training our\nfirst neural network.\n\n\nThe ``autograd`` package provides automatic differentiation for all operations\non Tensors. It is a define-by-run framework, which means that your backprop is\ndefined by how your code is run, and that every single iteration can be\ndifferent.\n\nLet us see this in more simple terms with some examples.\n\nVariable\n--------\n\n``autograd.Variable`` is the central class of the package. It wraps a\nTensor, and supports nearly all of operations defined on it. Once you\nfinish your computation you can call ``.backward()`` and have all the\ngradients computed automatically.\n\nYou can access the raw tensor through the ``.data`` attribute, while the\ngradient w.r.t. this variable is accumulated into ``.grad``.\n\n.. figure:: /_static/img/Variable.png\n :alt: Variable\n\n Variable\n\nThere\u2019s one more class which is very important for autograd\nimplementation - a ``Function``.\n\n``Variable`` and ``Function`` are interconnected and build up an acyclic\ngraph, that encodes a complete history of computation. Each variable has\na ``.grad_fn`` attribute that references a ``Function`` that has created\nthe ``Variable`` (except for Variables created by the user - their\n``grad_fn is None``).\n\nIf you want to compute the derivatives, you can call ``.backward()`` on\na ``Variable``. If ``Variable`` is a scalar (i.e. it holds a one element\ndata), you don\u2019t need to specify any arguments to ``backward()``,\nhowever if it has more elements, you need to specify a ``grad_output``\nargument that is a tensor of matching shape.\n\n"
19-
]
38+
],
39+
"metadata": {},
40+
"cell_type": "markdown"
2041
},
2142
{
22-
"cell_type": "code",
2343
"execution_count": null,
44+
"source": [
45+
"import torch\nfrom torch.autograd import Variable"
46+
],
47+
"outputs": [],
2448
"metadata": {
2549
"collapsed": false
2650
},
27-
"outputs": [],
28-
"source": [
29-
"import torch\nfrom torch.autograd import Variable"
30-
]
51+
"cell_type": "code"
3152
},
3253
{
33-
"cell_type": "markdown",
34-
"metadata": {},
3554
"source": [
3655
"Create a variable:\n\n"
37-
]
56+
],
57+
"metadata": {},
58+
"cell_type": "markdown"
3859
},
3960
{
40-
"cell_type": "code",
4161
"execution_count": null,
62+
"source": [
63+
"x = Variable(torch.ones(2, 2), requires_grad=True)\nprint(x)"
64+
],
65+
"outputs": [],
4266
"metadata": {
4367
"collapsed": false
4468
},
45-
"outputs": [],
46-
"source": [
47-
"x = Variable(torch.ones(2, 2), requires_grad=True)\nprint(x)"
48-
]
69+
"cell_type": "code"
4970
},
5071
{
51-
"cell_type": "markdown",
52-
"metadata": {},
5372
"source": [
5473
"Do an operation of variable:\n\n"
55-
]
74+
],
75+
"metadata": {},
76+
"cell_type": "markdown"
5677
},
5778
{
58-
"cell_type": "code",
5979
"execution_count": null,
80+
"source": [
81+
"y = x + 2\nprint(y)"
82+
],
83+
"outputs": [],
6084
"metadata": {
6185
"collapsed": false
6286
},
63-
"outputs": [],
64-
"source": [
65-
"y = x + 2\nprint(y)"
66-
]
87+
"cell_type": "code"
6788
},
6889
{
69-
"cell_type": "markdown",
70-
"metadata": {},
7190
"source": [
7291
"``y`` was created as a result of an operation, so it has a ``grad_fn``.\n\n"
73-
]
92+
],
93+
"metadata": {},
94+
"cell_type": "markdown"
7495
},
7596
{
76-
"cell_type": "code",
7797
"execution_count": null,
98+
"source": [
99+
"print(y.grad_fn)"
100+
],
101+
"outputs": [],
78102
"metadata": {
79103
"collapsed": false
80104
},
81-
"outputs": [],
82-
"source": [
83-
"print(y.grad_fn)"
84-
]
105+
"cell_type": "code"
85106
},
86107
{
87-
"cell_type": "markdown",
88-
"metadata": {},
89108
"source": [
90109
"Do more operations on y\n\n"
91-
]
110+
],
111+
"metadata": {},
112+
"cell_type": "markdown"
92113
},
93114
{
94-
"cell_type": "code",
95115
"execution_count": null,
116+
"source": [
117+
"z = y * y * 3\nout = z.mean()\n\nprint(z, out)"
118+
],
119+
"outputs": [],
96120
"metadata": {
97121
"collapsed": false
98122
},
99-
"outputs": [],
100-
"source": [
101-
"z = y * y * 3\nout = z.mean()\n\nprint(z, out)"
102-
]
123+
"cell_type": "code"
103124
},
104125
{
105-
"cell_type": "markdown",
106-
"metadata": {},
107126
"source": [
108127
"Gradients\n---------\nlet's backprop now\n``out.backward()`` is equivalent to doing ``out.backward(torch.Tensor([1.0]))``\n\n"
109-
]
128+
],
129+
"metadata": {},
130+
"cell_type": "markdown"
110131
},
111132
{
112-
"cell_type": "code",
113133
"execution_count": null,
134+
"source": [
135+
"out.backward()"
136+
],
137+
"outputs": [],
114138
"metadata": {
115139
"collapsed": false
116140
},
117-
"outputs": [],
118-
"source": [
119-
"out.backward()"
120-
]
141+
"cell_type": "code"
121142
},
122143
{
123-
"cell_type": "markdown",
124-
"metadata": {},
125144
"source": [
126145
"print gradients d(out)/dx\n\n\n"
127-
]
146+
],
147+
"metadata": {},
148+
"cell_type": "markdown"
128149
},
129150
{
130-
"cell_type": "code",
131151
"execution_count": null,
152+
"source": [
153+
"print(x.grad)"
154+
],
155+
"outputs": [],
132156
"metadata": {
133157
"collapsed": false
134158
},
135-
"outputs": [],
136-
"source": [
137-
"print(x.grad)"
138-
]
159+
"cell_type": "code"
139160
},
140161
{
141-
"cell_type": "markdown",
142-
"metadata": {},
143162
"source": [
144163
"You should have got a matrix of ``4.5``. Let\u2019s call the ``out``\n*Variable* \u201c$o$\u201d.\nWe have that $o = \\frac{1}{4}\\sum_i z_i$,\n$z_i = 3(x_i+2)^2$ and $z_i\\bigr\\rvert_{x_i=1} = 27$.\nTherefore,\n$\\frac{\\partial o}{\\partial x_i} = \\frac{3}{2}(x_i+2)$, hence\n$\\frac{\\partial o}{\\partial x_i}\\bigr\\rvert_{x_i=1} = \\frac{9}{2} = 4.5$.\n\n"
145-
]
164+
],
165+
"metadata": {},
166+
"cell_type": "markdown"
146167
},
147168
{
148-
"cell_type": "markdown",
149-
"metadata": {},
150169
"source": [
151170
"You can do many crazy things with autograd!\n\n"
152-
]
171+
],
172+
"metadata": {},
173+
"cell_type": "markdown"
153174
},
154175
{
155-
"cell_type": "code",
156176
"execution_count": null,
177+
"source": [
178+
"x = torch.randn(3)\nx = Variable(x, requires_grad=True)\n\ny = x * 2\nwhile y.data.norm() < 1000:\n y = y * 2\n\nprint(y)"
179+
],
180+
"outputs": [],
157181
"metadata": {
158182
"collapsed": false
159183
},
160-
"outputs": [],
161-
"source": [
162-
"x = torch.randn(3)\nx = Variable(x, requires_grad=True)\n\ny = x * 2\nwhile y.data.norm() < 1000:\n y = y * 2\n\nprint(y)"
163-
]
184+
"cell_type": "code"
164185
},
165186
{
166-
"cell_type": "code",
167187
"execution_count": null,
188+
"source": [
189+
"gradients = torch.FloatTensor([0.1, 1.0, 0.0001])\ny.backward(gradients)\n\nprint(x.grad)"
190+
],
191+
"outputs": [],
168192
"metadata": {
169193
"collapsed": false
170194
},
171-
"outputs": [],
172-
"source": [
173-
"gradients = torch.FloatTensor([0.1, 1.0, 0.0001])\ny.backward(gradients)\n\nprint(x.grad)"
174-
]
195+
"cell_type": "code"
175196
},
176197
{
177-
"cell_type": "markdown",
178-
"metadata": {},
179198
"source": [
180199
"**Read Later:**\n\nDocumentation of ``Variable`` and ``Function`` is at\nhttp://pytorch.org/docs/autograd\n\n"
181-
]
182-
}
183-
],
184-
"metadata": {
185-
"kernelspec": {
186-
"display_name": "Python 3",
187-
"language": "python",
188-
"name": "python3"
189-
},
190-
"language_info": {
191-
"codemirror_mode": {
192-
"name": "ipython",
193-
"version": 3
194-
},
195-
"file_extension": ".py",
196-
"mimetype": "text/x-python",
197-
"name": "python",
198-
"nbconvert_exporter": "python",
199-
"pygments_lexer": "ipython3",
200-
"version": "3.6.1"
200+
],
201+
"metadata": {},
202+
"cell_type": "markdown"
201203
}
202-
},
203-
"nbformat": 4,
204-
"nbformat_minor": 0
204+
]
205205
}

0 commit comments

Comments
 (0)