|
12 | 12 | {
|
13 | 13 | "cell_type": "code",
|
14 | 14 | "execution_count": null,
|
15 |
| - "metadata": {}, |
| 15 | + "metadata": { |
| 16 | + "collapsed": true |
| 17 | + }, |
16 | 18 | "outputs": [],
|
17 | 19 | "source": [
|
18 | 20 | "# Import necessary packages\n",
|
|
45 | 47 | {
|
46 | 48 | "cell_type": "code",
|
47 | 49 | "execution_count": null,
|
48 |
| - "metadata": {}, |
| 50 | + "metadata": { |
| 51 | + "collapsed": true |
| 52 | + }, |
49 | 53 | "outputs": [],
|
50 | 54 | "source": [
|
51 | 55 | "### Run this cell\n",
|
|
79 | 83 | {
|
80 | 84 | "cell_type": "code",
|
81 | 85 | "execution_count": null,
|
82 |
| - "metadata": {}, |
| 86 | + "metadata": { |
| 87 | + "collapsed": true |
| 88 | + }, |
83 | 89 | "outputs": [],
|
84 | 90 | "source": [
|
85 | 91 | "dataiter = iter(trainloader)\n",
|
|
99 | 105 | {
|
100 | 106 | "cell_type": "code",
|
101 | 107 | "execution_count": null,
|
102 |
| - "metadata": {}, |
| 108 | + "metadata": { |
| 109 | + "collapsed": true |
| 110 | + }, |
103 | 111 | "outputs": [],
|
104 | 112 | "source": [
|
105 | 113 | "plt.imshow(images[1].numpy().squeeze(), cmap='Greys_r');"
|
|
121 | 129 | {
|
122 | 130 | "cell_type": "code",
|
123 | 131 | "execution_count": null,
|
124 |
| - "metadata": {}, |
| 132 | + "metadata": { |
| 133 | + "collapsed": true |
| 134 | + }, |
125 | 135 | "outputs": [],
|
126 | 136 | "source": [
|
127 | 137 | "## Your solution\n",
|
|
153 | 163 | {
|
154 | 164 | "cell_type": "code",
|
155 | 165 | "execution_count": null,
|
156 |
| - "metadata": {}, |
| 166 | + "metadata": { |
| 167 | + "collapsed": true |
| 168 | + }, |
157 | 169 | "outputs": [],
|
158 | 170 | "source": [
|
159 | 171 | "def softmax(x):\n",
|
|
180 | 192 | {
|
181 | 193 | "cell_type": "code",
|
182 | 194 | "execution_count": null,
|
183 |
| - "metadata": {}, |
| 195 | + "metadata": { |
| 196 | + "collapsed": true |
| 197 | + }, |
184 | 198 | "outputs": [],
|
185 | 199 | "source": [
|
186 | 200 | "from torch import nn"
|
|
189 | 203 | {
|
190 | 204 | "cell_type": "code",
|
191 | 205 | "execution_count": null,
|
192 |
| - "metadata": {}, |
| 206 | + "metadata": { |
| 207 | + "collapsed": true |
| 208 | + }, |
193 | 209 | "outputs": [],
|
194 | 210 | "source": [
|
195 | 211 | "class Network(nn.Module):\n",
|
|
231 | 247 | "self.hidden = nn.Linear(784, 256)\n",
|
232 | 248 | "```\n",
|
233 | 249 | "\n",
|
234 |
| - "This line creates a module for a linear transformation, $x\\mathbf{W} + b$, with 784 inputs and 256 outputs and assigns it to `self.hidden`. The module automatically creates the weight and bias tensors which we'll use in the `forward` method. You can access the weight and bias tensors once the network once it's create at `net.hidden.weight` and `net.hidden.bias`.\n", |
| 250 | + "This line creates a module for a linear transformation, $x\\mathbf{W} + b$, with 784 inputs and 256 outputs and assigns it to `self.hidden`. The module automatically creates the weight and bias tensors which we'll use in the `forward` method. You can access the weight and bias tensors once the network (`net`) is created with `net.hidden.weight` and `net.hidden.bias`.\n", |
235 | 251 | "\n",
|
236 | 252 | "```python\n",
|
237 | 253 | "self.output = nn.Linear(256, 10)\n",
|
|
267 | 283 | {
|
268 | 284 | "cell_type": "code",
|
269 | 285 | "execution_count": null,
|
270 |
| - "metadata": {}, |
| 286 | + "metadata": { |
| 287 | + "collapsed": true |
| 288 | + }, |
271 | 289 | "outputs": [],
|
272 | 290 | "source": [
|
273 | 291 | "# Create the network and look at it's text representation\n",
|
|
285 | 303 | {
|
286 | 304 | "cell_type": "code",
|
287 | 305 | "execution_count": null,
|
288 |
| - "metadata": {}, |
| 306 | + "metadata": { |
| 307 | + "collapsed": true |
| 308 | + }, |
289 | 309 | "outputs": [],
|
290 | 310 | "source": [
|
291 | 311 | "import torch.nn.functional as F\n",
|
|
335 | 355 | "cell_type": "code",
|
336 | 356 | "execution_count": null,
|
337 | 357 | "metadata": {
|
| 358 | + "collapsed": true, |
338 | 359 | "scrolled": true
|
339 | 360 | },
|
340 | 361 | "outputs": [],
|
|
354 | 375 | {
|
355 | 376 | "cell_type": "code",
|
356 | 377 | "execution_count": null,
|
357 |
| - "metadata": {}, |
| 378 | + "metadata": { |
| 379 | + "collapsed": true |
| 380 | + }, |
358 | 381 | "outputs": [],
|
359 | 382 | "source": [
|
360 | 383 | "print(model.fc1.weight)\n",
|
|
371 | 394 | {
|
372 | 395 | "cell_type": "code",
|
373 | 396 | "execution_count": null,
|
374 |
| - "metadata": {}, |
| 397 | + "metadata": { |
| 398 | + "collapsed": true |
| 399 | + }, |
375 | 400 | "outputs": [],
|
376 | 401 | "source": [
|
377 | 402 | "# Set biases to all zeros\n",
|
|
381 | 406 | {
|
382 | 407 | "cell_type": "code",
|
383 | 408 | "execution_count": null,
|
384 |
| - "metadata": {}, |
| 409 | + "metadata": { |
| 410 | + "collapsed": true |
| 411 | + }, |
385 | 412 | "outputs": [],
|
386 | 413 | "source": [
|
387 | 414 | "# sample from random normal with standard dev = 0.01\n",
|
|
400 | 427 | {
|
401 | 428 | "cell_type": "code",
|
402 | 429 | "execution_count": null,
|
403 |
| - "metadata": {}, |
| 430 | + "metadata": { |
| 431 | + "collapsed": true |
| 432 | + }, |
404 | 433 | "outputs": [],
|
405 | 434 | "source": [
|
406 | 435 | "# Grab some data \n",
|
|
433 | 462 | {
|
434 | 463 | "cell_type": "code",
|
435 | 464 | "execution_count": null,
|
436 |
| - "metadata": {}, |
| 465 | + "metadata": { |
| 466 | + "collapsed": true |
| 467 | + }, |
437 | 468 | "outputs": [],
|
438 | 469 | "source": [
|
439 | 470 | "# Hyperparameters for our network\n",
|
|
469 | 500 | {
|
470 | 501 | "cell_type": "code",
|
471 | 502 | "execution_count": null,
|
472 |
| - "metadata": {}, |
| 503 | + "metadata": { |
| 504 | + "collapsed": true |
| 505 | + }, |
473 | 506 | "outputs": [],
|
474 | 507 | "source": [
|
475 | 508 | "print(model[0])\n",
|
|
486 | 519 | {
|
487 | 520 | "cell_type": "code",
|
488 | 521 | "execution_count": null,
|
489 |
| - "metadata": {}, |
| 522 | + "metadata": { |
| 523 | + "collapsed": true |
| 524 | + }, |
490 | 525 | "outputs": [],
|
491 | 526 | "source": [
|
492 | 527 | "from collections import OrderedDict\n",
|
|
510 | 545 | {
|
511 | 546 | "cell_type": "code",
|
512 | 547 | "execution_count": null,
|
513 |
| - "metadata": {}, |
| 548 | + "metadata": { |
| 549 | + "collapsed": true |
| 550 | + }, |
514 | 551 | "outputs": [],
|
515 | 552 | "source": [
|
516 | 553 | "print(model[0])\n",
|
|
527 | 564 | ],
|
528 | 565 | "metadata": {
|
529 | 566 | "kernelspec": {
|
530 |
| - "display_name": "Python 3", |
| 567 | + "display_name": "Python [default]", |
531 | 568 | "language": "python",
|
532 | 569 | "name": "python3"
|
533 | 570 | },
|
|
541 | 578 | "name": "python",
|
542 | 579 | "nbconvert_exporter": "python",
|
543 | 580 | "pygments_lexer": "ipython3",
|
544 |
| - "version": "3.6.6" |
| 581 | + "version": "3.6.4" |
545 | 582 | }
|
546 | 583 | },
|
547 | 584 | "nbformat": 4,
|
|
0 commit comments