Skip to content

Commit 9c8fef3

Browse files
committed
rebuild
1 parent dd6a310 commit 9c8fef3

27 files changed

+664
-664
lines changed

_downloads/advanced_tutorial.ipynb

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

_downloads/deep_learning_tutorial.ipynb

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

_downloads/dynamic_net.ipynb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
{
22
"metadata": {
33
"kernelspec": {
4+
"name": "python3",
45
"language": "python",
5-
"display_name": "Python 3",
6-
"name": "python3"
6+
"display_name": "Python 3"
77
},
88
"language_info": {
99
"version": "3.5.2",
10-
"pygments_lexer": "ipython3",
11-
"name": "python",
12-
"nbconvert_exporter": "python",
13-
"mimetype": "text/x-python",
1410
"file_extension": ".py",
11+
"nbconvert_exporter": "python",
1512
"codemirror_mode": {
16-
"version": 3,
17-
"name": "ipython"
18-
}
13+
"name": "ipython",
14+
"version": 3
15+
},
16+
"mimetype": "text/x-python",
17+
"name": "python",
18+
"pygments_lexer": "ipython3"
1919
}
2020
},
2121
"nbformat": 4,
2222
"cells": [
2323
{
24-
"outputs": [],
24+
"cell_type": "code",
2525
"metadata": {
2626
"collapsed": false
2727
},
28+
"outputs": [],
29+
"execution_count": null,
2830
"source": [
2931
"%matplotlib inline"
30-
],
31-
"execution_count": null,
32-
"cell_type": "code"
32+
]
3333
},
3434
{
35+
"cell_type": "markdown",
3536
"metadata": {},
3637
"source": [
3738
"\nPyTorch: Control Flow + Weight Sharing\n--------------------------------------\n\nTo showcase the power of PyTorch dynamic graphs, we will implement a very strange\nmodel: a fully-connected ReLU network that on each forward pass randomly chooses\na number between 1 and 4 and has that many hidden layers, reusing the same\nweights multiple times to compute the innermost hidden layers.\n\n"
38-
],
39-
"cell_type": "markdown"
39+
]
4040
},
4141
{
42-
"outputs": [],
42+
"cell_type": "code",
4343
"metadata": {
4444
"collapsed": false
4545
},
46+
"outputs": [],
47+
"execution_count": null,
4648
"source": [
4749
"import random\nimport torch\nfrom torch.autograd import Variable\n\nclass DynamicNet(torch.nn.Module):\n def __init__(self, D_in, H, D_out):\n \"\"\"\n In the constructor we construct three nn.Linear instances that we will use\n in the forward pass.\n \"\"\"\n super(DynamicNet, self).__init__()\n self.input_linear = torch.nn.Linear(D_in, H)\n self.middle_linear = torch.nn.Linear(H, H)\n self.output_linear = torch.nn.Linear(H, D_out)\n\n def forward(self, x):\n \"\"\"\n For the forward pass of the model, we randomly choose either 0, 1, 2, or 3\n and reuse the middle_linear Module that many times to compute hidden layer\n representations.\n\n Since each forward pass builds a dynamic computation graph, we can use normal\n Python control-flow operators like loops or conditional statements when\n defining the forward pass of the model.\n\n Here we also see that it is perfectly safe to reuse the same Module many\n times when defining a computational graph. This is a big improvement from Lua\n Torch, where each Module could be used only once.\n \"\"\"\n h_relu = self.input_linear(x).clamp(min=0)\n for _ in range(random.randint(0, 3)):\n h_relu = self.middle_linear(h_relu).clamp(min=0)\n y_pred = self.output_linear(h_relu)\n return y_pred\n\n\n# N is batch size; D_in is input dimension;\n# H is hidden dimension; D_out is output dimension.\nN, D_in, H, D_out = 64, 1000, 100, 10\n\n# Create random Tensors to hold inputs and outputs, and wrap them in Variables\nx = Variable(torch.randn(N, D_in))\ny = Variable(torch.randn(N, D_out), requires_grad=False)\n\n# Construct our model by instantiating the class defined above\nmodel = DynamicNet(D_in, H, D_out)\n\n# Construct our loss function and an Optimizer. Training this strange model with\n# vanilla stochastic gradient descent is tough, so we use momentum\ncriterion = torch.nn.MSELoss(size_average=False)\noptimizer = torch.optim.SGD(model.parameters(), lr=1e-4, momentum=0.9)\nfor t in range(500):\n # Forward pass: Compute predicted y by passing x to the model\n y_pred = model(x)\n\n # Compute and print loss\n loss = criterion(y_pred, y)\n print(t, loss.data[0])\n\n # Zero gradients, perform a backward pass, and update the weights.\n optimizer.zero_grad()\n loss.backward()\n optimizer.step()"
48-
],
49-
"execution_count": null,
50-
"cell_type": "code"
50+
]
5151
}
5252
],
5353
"nbformat_minor": 0

0 commit comments

Comments
 (0)