-
Notifications
You must be signed in to change notification settings - Fork 22
/
chapter6.html
419 lines (350 loc) · 18.3 KB
/
chapter6.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
<!-- Social media -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@OKAI" />
<!-- BB Change this--><meta name="twitter:title" content="Chapter 6: Feedforward Neural Networks in Action" />
<!-- CC Change this--><meta name="twitter:description" content="This chapter explains how the interactive module in Chapter 0 works to recognize handwritten digits." />
<!-- AA Change this--><meta name="twitter:image" content="https://okai.brown.edu/img/share/en/en_6.png" />
<!-- Change this--><meta property="og:url" content="https://okai.brown.edu/chapter6.html" />
<meta property="og:type" content="article" />
<!-- BB Change this--><meta property="og:title" content="Chapter 6: Feedforward Neural Networks in Action" />
<!-- CC Change this--><meta property="og:description" content="This chapter explains how the interactive module in Chapter 0 works to recognize handwritten digits." />
<!-- AA Change this--><meta property="og:image" content="https://okai.brown.edu/img/share/en/en_6.png" />
<!-- ................... -->
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:400,700" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ"
crossorigin="anonymous">
<!-- Bootstrap CSS CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
crossorigin="anonymous">
<!-- Scrollbar Custom CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.css">
<!-- My stylesheet -->
<link rel="stylesheet" href="./css/general.css">
<!-- change to own stylesheet -->
<link rel="stylesheet" href="./css/chapter6.css">
<!-- language annotations -->
<link rel="alternate" hreflang="zh-Hans" href="https://okai.brown.edu/zh/chapter6.html" />
<link rel="alternate" hreflang="en" href="https://okai.brown.edu/chapter6.html" />
<link rel="canonical" href="https://okai.brown.edu/chapter6.html" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-133914635-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-133914635-1');
</script>
<title>Chapter 6 - OKAI</title>
</head>
<body>
<!-- scrollbar -->
<div class="scrollBar" id="myBar"></div>
<!-- navbar place holder -->
<div id="nav-placeholder"></div>
<!-- ######################### -->
<!-- Chapter content beginning -->
<!-- ######################### -->
<!-- landing section -->
<div id="openingText" class="d-flex align-items-center justify-content-center">
<!-- start of row 1 -->
<div class="row align-items-center justify-content-center">
<!-- col 1 -->
<div class="d-none d-md-block col-1 arrowIcon" style="position: absolute; left: 5px;">
<a href="./chapter5.html" data-toggle="tooltip" title="Chapter 5"><i class="fas fa-caret-left fa-2x"></i></a>
</div>
<!-- col 2 -->
<div class="col-10 col-md-4 order-2 order-md-1 text-center">
<div class="text-left">
<p>Chapter 6</p>
<h2>Feedforward Neural Networks in Action</h2>
<p>Are you wondering how the module in chapter 0 works? Harness the knowledge
you have acquired so far and let's take a look at how the interactive
module in Chapter 0 works to recognize handwritten digits. Keep scrolling!
</p>
</div>
</div>
<!-- col 3 -->
<div class="col-md-5 order-1 order-md-2">
<div id="openingLottie" class="openingAnimation mx-auto"></div>
</div>
<!-- col-4 -->
<div class="d-none d-md-block col-1 arrowIcon" style="position: absolute; right: 5px; visibility: visible;">
<a href="./about.html" data-toggle="tooltip" title="About"><i class="fas fa-caret-right fa-2x"></i></a>
</div>
</div>
<!-- end of row 1 -->
<!-- start of row 2 -->
<div class="" style="position: absolute; bottom: 20px;">
<div>
<p class="iconHeight" id="scrollIcon">Scroll</p>
<i class="iconHeight fas fa-angle-down fa-lg"></i>
</div>
<!-- end of row 2 -->
</div>
</div>
<!-- end of landing section -->
<!-- ######## Animation & text beginning ######## -->
<!-- animation divs -->
<div id="mnistLottie" class="animation animLeft upperLayer"></div>
<div id="mnistOutputLottie" class="animation animRight topLayer"></div>
<div id="propLottie" class="animation animLeft threeLayer"></div>
<div id="repeatLottie" class="animation animRight fourLayer"></div>
<div id="codingLottie" class="animation animLeft fiveLayer"></div>
<!-- text begins -->
<!-- mnist animation text section -->
<div id="text1" class="bg-1grey scene">
<div class="text right">
<p>In this chapter, we will explain how to make a practical network that will recognize
handwritten digits, just like the one in Chapter 0. We will be using the MNIST
dataset, a dataset of handwritten images from computer scientist
<strong data-toggle="tooltip" class="highlight" title="Received 2018 Turing Award
along with Yoshua Bengio and Geoffrey Hinton">Yann LeCun</strong>'s website.
</p>
</div>
</div>
<div id="text2" class="bg-1grey scene">
<div class="text right">
<p>
Each of the images from the MNIST dataset is a 28 pixel by 28 pixel image. These
images will be used as training data to teach our feedforward neural network how to
recognize handwritten
digits.
</p>
</div>
</div>
<div id="text3" class="bg-1grey scene">
<div class="text right">
<p>
Each pixel has a value from 0 to 1 to indicate how white the pixel is. 0 is black,
1 is white, and anywhere between them is a shade of gray. These 28 × 28 = 784
pixels are flattened into a single array to be fed into the input layer.
</p>
</div>
</div>
<div id="text4" class="bg-1grey scene">
<div class="text right">
<p>The activations from the input layer are propagated to the 500 nodes in the hidden
layer, which transforms it to a new 500-number representation of the input. For a
multilayer network to work well, we need to break linearity, and thus we use ReLU
as an activation function to achieve that.
</p>
</div>
</div>
<div id="text5" class="bg-1grey scene">
<div class="text right">
<p>
These 500 nodes feed their outputs to a final output layer of 10 nodes. We will
interpret the outputs as being the probability that the input is each of the ten
possible digits.
We use <strong data-toggle="tooltip" class="highlight" title="A hyped-up
version of sigmoid that generates probabilities over a set of categories.">softmax</strong>
activation function on the output layer to do so.
</p>
</div>
</div>
<!-- mnistOutput animation text section -->
<div id="text6" class="scene bg-2grey upperLayer">
<div class="text left">
<p>Finally, the output layer will also have 10 nodes, each corresponding to a digit
from 0 to 9.
</p>
</div>
</div>
<div id="text7" class="scene bg-2grey upperLayer">
<div class="text left">
<p>Because of softmax, each final output node now contains a probability value that
represents how likely the feedforward neural network thinks the input image
represents the corresponding
digit.
</p>
</div>
</div>
<div id="text8" class="scene bg-2grey upperLayer">
<div class="text left">
<p>The highest output value (probability) signals the digit that the model thinks is
the most probable; that digit is the final output classification of the input
handwritten digit.
</p>
</div>
</div>
<!-- prop animation text section -->
<div id="text9" class="scene bg-3grey topLayer">
<div class="text right">
<p>For training, we split the set of images from MNIST into batches of 100. During
training, the model uses the current weights and biases to generate its best guess.
This process is called <strong class="highlight" data-toggle="tooltip" title="The process of making the neural network
generate a prediction based on input">forward
propagation</strong>.
</p>
</div>
</div>
<div id="text10" class="scene bg-3grey topLayer">
<div class="text right">
<p>After seeing the answer and computing the loss, the training algorithm goes back
into the network and updates the weights and biases using gradients to get closer
to the ground truth outputs. This process is called <strong class="highlight"
data-toggle="tooltip" title="The process of adjusting parameters to
improve the performance of neural networks.">backpropagation</strong>.
<p>
</div>
</div>
<!-- repeat animation text section-->
<div id="text11" class="scene threeLayer bg-4grey">
<div class="text left">
<p>
To train the model, we would need to first initialize its parameters (weights and
biases). In this particular case, we will initialize them to random values
clustered around 0, which is usually a good starting point.
</p>
</div>
</div>
<div id="text12" class="scene threeLayer bg-4grey">
<div class="text left">
<p>
To train the network, we are using Stochastic Gradient Descent (SGD) with a
learning rate of 0.7. This learning rate was chosen through experiment, and it
seemed to work best for our network. Experts often try out a few different values
before settling on a reasonable one.
</p>
</div>
</div>
<div id="text13" class="scene threeLayer bg-4grey">
<div class="text left">
<p>
After going over the entire dataset for 2 to 3 times, our model is good enough to
be used. It is able to achieve around 97% accuracy with only 2 runs over the
dataset. On an average laptop, the training takes less than a minute.
</p>
</div>
</div>
<!-- coding animation text section -->
<div id="text14" class="scene fourLayer bg-5grey">
<div class="text right">
<p>
This is the feedforward neural network that we used in our interactive module in
Chapter 0. For those who
want to experiment with the model more in depth, we have written easy-to-understand
code that you can play around with online.<br>
<a class="mt-2 btn btn-warning" id="colabButton" href="https://colab.research.google.com/drive/18bQA1ly8hsX_vjPILBkrHsbqkQKPpsdU"
role="button" target="_blank">
Get Coding
</a>
</p>
</div>
</div>
<!-- ending section -->
<div id="endingText" class="lastScene row align-items-center justify-content-around fiveLayer">
<!-- col 1 -->
<div class="d-none d-md-block col-1 arrowIcon" style="position: absolute; left: 5px;">
<a href="./chapter5.html" data-toggle="tooltip" title="Chapter 5"><i class="fas fa-caret-left fa-2x"></i></a>
</div>
<div class="col-12 col-md-10">
<div class="row justify-content-around">
<div class="col-10 col-md-5 fourLayer align-self-start">
<div class="text-left align-self-start">
<h3><strong>Summary</strong></h3>
<p>In summary, knowledge gained in previous chapters was applied to build a
functional neural network that can recognize handwritten digits. There
are much more powerful things that AI can do. We hope that these
chapters can serve as a starting point for you to explore more in the
world of AI!
</p>
<h3><strong>Further Reading</strong></h3>
<p>
<a href="https://yann.lecun.com/exdb/mnist/" target="_blank">
MNIST Dataset</a>
<br><a href="https://www.deeplearningbook.org/" target="_blank">
Deep Learning: An MIT Press Book</a>
<br><a href="https://playground.tensorflow.org/" target="_blank">
A Neural Network Playground</a>
</p>
</div>
</div>
<div class="col-10 col-md-5 fourLayer align-self-start">
<div class="text-left">
<h3><strong>Glossary</strong></h3>
<p><strong>Softmax</strong>: A hyped-up version of sigmoid that generates
the probabilities of a set of categories.
<br><br>
<strong>Forward Propagation</strong>: The process of making the neural
network generate a prediction based on input.
<br><br>
<strong>Backpropagation</strong>: The process of adjusting parameters
to improve the performance of neural networks.
</p>
</div>
</div>
<!-- mobile nav button groups -->
<div class="col-10 d-md-none fourLayer justify-content-start my-3">
<div class="btn-group d-flex" id="nextButtonGroup" role="group">
<a class="btn btn-warning w-50" href="./chapter5.html"
role="button" id="prevButton">Prev Chapter</a>
<span class="btn-warning btn-separator"></span>
<a class="btn btn-warning w-50" href="./about.html"
role="button" id="nextButton">About Page</a>
</div>
</div>
<!-- end of inner row -->
</div>
<!-- end of outer col-10 -->
</div>
<!-- col-4 -->
<div class="d-none d-md-block col-1 arrowIcon" style="position: absolute; right: 5px; visibility: visible;">
<a href="./about.html" data-toggle="tooltip" title="About"><i class="fas fa-caret-right fa-2x"></i></a>
</div>
<!-- end of ending section -->
</div>
<!-- end of text area -->
<div class="overlay"></div>
<!-- svg goo filter DO NOT DELETE-->
<!-- <svg version="1.1" xmlns="https://www.w3.org/2000/svg" style="height: 0; width: 0; position: absolute; top: -9999px; left: -99990px">
<defs>
<filter color-interpolation-filters="sRGB" id="goo2">
<feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 21 -9" result="cm" />
<feBlend />
</filter>
</defs>
</svg> -->
<!-- Boostrap JavaScript -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"
integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm"
crossorigin="anonymous"></script>
<!-- jQuery Custom Scroller CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.concat.min.js"></script>
<!-- GSAP -->
<script type="text/javascript" src="./js/TweenMax.min.js"></script>
<script type="text/javascript" src="./js/DrawSVGPlugin.min.js"></script>
<script type="text/javascript" src="./js/MorphSVGPlugin.min.js"></script>
<!-- Lottie -->
<script type="text/javascript" src="./js/lottie.js"></script>
<!-- ScrollMagic JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/animation.gsap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5//plugins/debug.addIndicators.js"></script>
<script type="text/javascript" src="./js/main.js"></script>
<!-- change to own js files -->
<script type="text/javascript" src="./js/chapter6.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip({
placement: "top"
});
});
</script>
</body>
</html>