-
Notifications
You must be signed in to change notification settings - Fork 210
/
Lecture 6 _ Training Neural Networks I.srt
3306 lines (2633 loc) · 90.2 KB
/
Lecture 6 _ Training Neural Networks I.srt
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:10,729 --> 00:00:12,896
- Okay, let's get started.
2
00:00:16,381 --> 00:00:21,529
Okay, so today we're going to get into some of
the details about how we train neural networks.
3
00:00:23,166 --> 00:00:28,785
So, some administrative details first.
Assignment 1 is due today, Thursday,
4
00:00:28,785 --> 00:00:36,521
so 11:59 p.m. tonight on Canvas. We're also
going to be releasing Assignment 2 today,
5
00:00:36,521 --> 00:00:40,082
and then your project proposals
are due Tuesday, April 25th.
6
00:00:40,082 --> 00:00:46,591
So you should be really starting to think about
your projects now if you haven't already.
7
00:00:46,591 --> 00:00:54,804
How many people have decided what they want to do for
their project so far? Okay, so some, some people,
8
00:00:54,804 --> 00:01:03,937
so yeah, everyone else, you can go to TA office hours
if you want suggestions and bounce ideas off of TAs.
9
00:01:05,657 --> 00:01:18,121
We also have a list of projects that other people have proposed. Some people usually
affiliated with Stanford, so on Piazza, so you can take a look at those for additional ideas.
10
00:01:19,604 --> 00:01:28,004
And we also have some notes on backprop for a linear layer and
a vector and tensor derivatives that Justin's written up,
11
00:01:28,004 --> 00:01:33,964
so that should help with understanding how exactly
backprop works and for vectors and matrices.
12
00:01:33,964 --> 00:01:40,484
So these are linked to lecture four on the
syllabus and you can go and take a look at those.
13
00:01:45,110 --> 00:01:57,124
Okay, so where we are now. We've talked about how to express a function in terms of a
computational graph, that we can represent any function in terms of a computational graph.
14
00:01:57,124 --> 00:02:03,751
And we've talked more explicitly about neural networks,
which is a type of graph where we have these linear layers
15
00:02:03,751 --> 00:02:08,360
that we stack on top of each other
with nonlinearities in between.
16
00:02:09,456 --> 00:02:13,360
And we've also talked last lecture
about convolutional neural networks,
17
00:02:13,360 --> 00:02:24,936
which are a particular type of network that uses convolutional layers to
preserve the spatial structure throughout all the the hierarchy of the network.
18
00:02:24,936 --> 00:02:38,056
And so we saw exactly how a convolution layer looked, where each activation map in the convolutional
layer output is produced by sliding a filter of weights over all of the spatial locations in the input.
19
00:02:38,056 --> 00:02:45,456
And we also saw that usually we can have many filters per
layer, each of which produces a separate activation map.
20
00:02:45,456 --> 00:02:50,655
And so what we can get is from an input right, with a
certain depth, we'll get an activation map output,
21
00:02:50,655 --> 00:02:58,771
which has some spatial dimension that's preserved, as well as the
depth is the total number of filters that we have in that layer.
22
00:02:59,695 --> 00:03:05,895
And so what we want to do is we want to learn the
values of all of these weights or parameters,
23
00:03:05,895 --> 00:03:12,507
and we saw that we can learn our network parameters through optimization,
which we talked about little bit earlier in the course, right?
24
00:03:12,507 --> 00:03:17,254
And so we want to get to a point in the
loss landscape that produces a low loss,
25
00:03:17,254 --> 00:03:23,053
and we can do this by taking steps
in the direction of the negative gradient.
26
00:03:23,053 --> 00:03:27,614
And so the whole process we actually call
a Mini-batch Stochastic Gradient Descent
27
00:03:27,614 --> 00:03:38,585
where the steps are that we continuously, we sample a batch of data. We forward prop
it through our computational graph or our neural network. We get the loss at the end.
28
00:03:38,585 --> 00:03:41,960
We backprop through our network
to calculate the gradients.
29
00:03:41,960 --> 00:03:47,986
And then we update the parameters or the
weights in our network using this gradient.
30
00:03:49,980 --> 00:03:58,321
Okay, so now for the next couple of lectures we're going to talk
about some of the details involved in training neural networks.
31
00:03:58,321 --> 00:04:02,441
And so this involves things like how do we
set up our neural network at the beginning,
32
00:04:02,441 --> 00:04:11,015
which activation functions that we choose, how do we preprocess the
data, weight initialization, regularization, gradient checking.
33
00:04:11,015 --> 00:04:16,118
We'll also talk about training dynamics. So,
how do we babysit the learning process?
34
00:04:16,118 --> 00:04:21,294
How do we choose how we do parameter
updates, specific perimeter update rules,
35
00:04:21,294 --> 00:04:26,241
and how do we do hyperparameter optimization
to choose the best hyperparameters?
36
00:04:26,241 --> 00:04:28,281
And then we'll also talk about evaluation
37
00:04:28,281 --> 00:04:29,948
and model ensembles.
38
00:04:33,000 --> 00:04:41,015
So today in the first part, I will talk about activation functions,
data preprocessing, weight initialization, batch normalization,
39
00:04:41,015 --> 00:04:45,412
babysitting the learning process,
and hyperparameter optimization.
40
00:04:47,348 --> 00:04:50,348
Okay, so first activation functions.
41
00:04:51,708 --> 00:04:55,095
So, we saw earlier how out
of any particular layer,
42
00:04:55,095 --> 00:05:01,481
we have the data coming in. We multiply by our weight
in you know, fully connected or a convolutional layer.
43
00:05:01,481 --> 00:05:06,388
And then we'll pass this through
an activation function or nonlinearity.
44
00:05:06,388 --> 00:05:08,027
And we saw some examples of this.
45
00:05:08,027 --> 00:05:13,295
We used sigmoid previously in some of our
examples. We also saw the ReLU nonlinearity.
46
00:05:13,295 --> 00:05:20,479
And so today we'll talk more about different choices for
these different nonlinearities and trade-offs between them.
47
00:05:22,228 --> 00:05:27,241
So first, the sigmoid, which we've seen before, and
probably the one we're most comfortable with, right?
48
00:05:27,241 --> 00:05:32,572
So the sigmoid function is as we have up
here, one over one plus e to the negative x.
49
00:05:32,572 --> 00:05:45,201
And what this does is it takes each number that's input into the sigmoid nonlinearity, so each
element, and the elementwise squashes these into this range [0,1] right, using this function here.
50
00:05:45,201 --> 00:05:50,427
And so, if you get very high values as input,
then output is going to be something near one.
51
00:05:50,427 --> 00:05:55,321
If you get very low values, or, I'm sorry, very
negative values, it's going to be near zero.
52
00:05:55,321 --> 00:06:02,481
And then we have this regime near zero that it's in a
linear regime. It looks a bit like a linear function.
53
00:06:02,481 --> 00:06:05,374
And so this is been historically popular,
54
00:06:05,374 --> 00:06:11,530
because sigmoids, in a sense, you can interpret them as
a kind of a saturating firing rate of a neuron, right?
55
00:06:11,530 --> 00:06:15,455
So if it's something between zero and one,
you could think of it as a firing rate.
56
00:06:15,455 --> 00:06:23,588
And we'll talk later about other nonlinearities, like ReLUs that,
in practice, actually turned out to be more biologically plausible,
57
00:06:23,588 --> 00:06:27,402
but this does have a kind of
interpretation that you could make.
58
00:06:30,015 --> 00:06:36,492
So if we look at this nonlinearity more carefully, there's
several problems that there actually are with this.
59
00:06:36,492 --> 00:06:44,065
So the first is that saturated neurons can kill off
the gradient. And so what exactly does this mean?
60
00:06:44,988 --> 00:06:48,801
So if we look at a sigmoid gate right,
a node in our computational graph,
61
00:06:48,801 --> 00:06:54,566
and we have our data X as input into it, and then we
have the output of the sigmoid gate coming out of it,
62
00:06:54,566 --> 00:06:59,236
what does the gradient flow look like
as we're coming back?
63
00:06:59,236 --> 00:07:08,441
We have dL over d sigma right? The upstream gradient coming
down, and then we're going to multiply this by dSigma over dX.
64
00:07:08,441 --> 00:07:11,081
This will be the gradient
of a local sigmoid function.
65
00:07:11,081 --> 00:07:16,495
And we're going to chain these together for
our downstream gradient that we pass back.
66
00:07:16,495 --> 00:07:24,708
So who can tell me what happens when X is equal to -10?
It's very negative. What does is gradient look like?
67
00:07:24,708 --> 00:07:28,868
Zero, yeah, so that's right.
So the gradient become zero
68
00:07:28,868 --> 00:07:37,348
and that's because in this negative, very negative region of
the sigmoid, it's essentially flat, so the gradient is zero,
69
00:07:37,348 --> 00:07:40,001
and we chain any upstream
gradient coming down.
70
00:07:40,001 --> 00:07:46,501
We multiply by basically something near zero, and we're going to
get a very small gradient that's flowing back downwards, right?
71
00:07:46,501 --> 00:07:55,381
So, in a sense, after the chain rule, this kills the gradient flow and
you're going to have a zero gradient passed down to downstream nodes.
72
00:07:58,869 --> 00:08:10,015
And so what happens when X is equal to zero? So there it's,
yeah, it's fine in this regime. So, in this regime near zero,
73
00:08:10,015 --> 00:08:15,135
you're going to get a reasonable gradient
here, and then it'll be fine for backprop.
74
00:08:15,135 --> 00:08:20,055
And then what about X equals 10?
Zero, right.
75
00:08:20,055 --> 00:08:31,108
So again, so when X is equal to a very negative or X is equal to large positive numbers, then
these are all regions where the sigmoid function is flat, and it's going to kill off the gradient
76
00:08:31,108 --> 00:08:35,275
and you're not going to get
a gradient flow coming back.
77
00:08:37,055 --> 00:08:42,454
Okay, so a second problem is that
the sigmoid outputs are not zero centered.
78
00:08:42,454 --> 00:08:46,415
And so let's take a look
at why this is a problem.
79
00:08:46,415 --> 00:08:51,892
So, consider what happens when
the input to a neuron is always positive.
80
00:08:51,892 --> 00:08:54,948
So in this case, all of our Xs
we're going to say is positive.
81
00:08:54,948 --> 00:09:04,348
It's going to be multiplied by some weight, W, and then
we're going to run it through our activation function.
82
00:09:04,348 --> 00:09:08,015
So what can we say about
the gradients on W?
83
00:09:12,375 --> 00:09:18,135
So think about what the local gradient is
going to be, right, for this linear layer.
84
00:09:18,135 --> 00:09:24,214
We have DL over whatever the activation
function, the loss coming down,
85
00:09:24,214 --> 00:09:29,834
and then we have our local gradient,
which is going to be basically X, right?
86
00:09:29,834 --> 00:09:34,001
And so what does this mean,
if all of X is positive?
87
00:09:36,253 --> 00:09:44,401
Okay, so I heard it's always going to be positive. So that's almost right. It's
always going to be either positive, or all positive or all negative, right?
88
00:09:44,401 --> 00:09:53,588
So, our upstream gradient coming down is DL over our loss. L is going
to be DL over DF. and this is going to be either positive or negative.
89
00:09:53,588 --> 00:09:55,815
It's some arbitrary gradient coming down.
90
00:09:55,815 --> 00:10:06,619
And then our local gradient that we multiply this by is, if we're going to
find the gradients on W, is going to be DF over DW, which is going to be X.
91
00:10:07,880 --> 00:10:20,800
And if X is always positive then the gradients on W, which is multiplying these two
together, are going to always be the sign of the upstream gradient coming down.
92
00:10:20,800 --> 00:10:28,520
And so what this means is that all the gradients of W, since they're always
either positive or negative, they're always going to move in the same direction.
93
00:10:28,520 --> 00:10:42,467
You're either going to increase all of the, when you do a parameter update, you're going to either increase
all of the values of W by a positive amount, or differing positive amounts, or you will decrease them all.
94
00:10:42,467 --> 00:10:48,867
And so the problem with this is that, this
gives very inefficient gradient updates.
95
00:10:48,867 --> 00:10:59,507
So, if you look at on the right here, we have an example of a case
where, let's say W is two-dimensional, so we have our two axes for W,
96
00:10:59,507 --> 00:11:04,796
and if we say that we can only have
all positive or all negative updates,
97
00:11:04,796 --> 00:11:12,400
then we have these two quadrants, and, are the two places
where the axis are either all positive or negative,
98
00:11:12,400 --> 00:11:17,213
and these are the only directions in which
we're allowed to make a gradient update.
99
00:11:17,213 --> 00:11:25,399
And so in the case where, let's say our hypothetical
optimal W is actually this blue vector here, right,
100
00:11:25,399 --> 00:11:30,773
and we're starting off at you know some point, or at
the top of the the the beginning of the red arrows,
101
00:11:30,773 --> 00:11:38,946
we can't just directly take a gradient update in this direction,
because this is not in one of those two allowed gradient directions.
102
00:11:38,946 --> 00:11:43,479
And so what we're going to have to do, is we'll
have to take a sequence of gradient updates.
103
00:11:43,479 --> 00:11:51,953
For example, in these red arrow directions that are each in
allowed directions, in order to finally get to this optimal W.
104
00:11:53,039 --> 00:11:58,479
And so this is why also, in general,
we want a zero mean data.
105
00:11:58,479 --> 00:12:11,893
So, we want our input X to be zero meaned, so that we actually have positive and negative values and
we don't get into this problem of the gradient updates. They'll be all moving in the same direction.
106
00:12:11,893 --> 00:12:17,819
So is this clear? Any questions
on this point? Okay.
107
00:12:21,453 --> 00:12:24,930
Okay, so we've talked about these two
main problems of the sigmoid.
108
00:12:24,930 --> 00:12:30,586
The saturated neurons can kill the gradients if
we're too positive or too negative of an input.
109
00:12:30,586 --> 00:12:36,586
They're also not zero-centered and so we get
these, this inefficient kind of gradient update.
110
00:12:36,586 --> 00:12:43,146
And then a third problem, we have an exponential function
in here, so this is a little bit computationally expensive.
111
00:12:43,146 --> 00:12:46,837
In the grand scheme of your network,
this is usually not the main problem,
112
00:12:46,837 --> 00:12:51,186
because we have all these convolutions and
dot products that are a lot more expensive,
113
00:12:51,186 --> 00:12:55,103
but this is just a minor
point also to observe.
114
00:12:58,986 --> 00:13:03,166
So now we can look at a second
activation function here at tanh.
115
00:13:03,166 --> 00:13:10,999
And so this looks very similar to the sigmoid, but the
difference is that now it's squashing to the range [-1, 1].
116
00:13:10,999 --> 00:13:15,573
So here, the main difference
is that it's now zero-centered,
117
00:13:15,573 --> 00:13:21,306
so we've gotten rid of the second problem that we had. It
still kills the gradients, however, when it's saturated.
118
00:13:21,306 --> 00:13:29,264
So, you still have these regimes where the gradient is
essentially flat and you're going to kill the gradient flow.
119
00:13:29,264 --> 00:13:34,009
So this is a bit better than the sigmoid,
but it still has some problems.
120
00:13:36,586 --> 00:13:40,104
Okay, so now let's look at
the ReLU activation function.
121
00:13:40,104 --> 00:13:47,573
And this is one that we saw in our examples last lecture
when we were talking about the convolutional neural network.
122
00:13:47,573 --> 00:13:53,279
And we saw that we interspersed ReLU nonlinearities
between many of the convolutional layers.
123
00:13:53,279 --> 00:13:58,253
And so, this function is f of
x equals max of zero and x.
124
00:13:58,253 --> 00:14:06,573
So it takes an elementwise operation on your input and basically
if your input is negative, it's going to put it to zero.
125
00:14:06,573 --> 00:14:13,264
And then if it's positive, it's going to
be just passed through. It's the identity.
126
00:14:13,264 --> 00:14:22,892
And so this is one that's pretty commonly used, and if we look at this one and look
at and think about the problems that we saw earlier with the sigmoid and the tanh,
127
00:14:22,892 --> 00:14:26,746
we can see that it doesn't saturate
in the positive region.
128
00:14:26,746 --> 00:14:34,465
So there's whole half of our input space where it's
not going to saturate, so this is a big advantage.
129
00:14:34,465 --> 00:14:36,959
So this is also
computationally very efficient.
130
00:14:36,959 --> 00:14:42,466
We saw earlier that the sigmoid
has this E exponential in it.
131
00:14:42,466 --> 00:14:48,968
And so the ReLU is just this simple max
and there's, it's extremely fast.
132
00:14:48,968 --> 00:14:57,063
And in practice, using this ReLU, it converges much faster
than the sigmoid and the tanh, so about six times faster.
133
00:14:57,063 --> 00:15:01,090
And it's also turned out to be more
biologically plausible than the sigmoid.
134
00:15:01,090 --> 00:15:11,450
So if you look at a neuron and you look at what the inputs look like, and you look at
what the outputs look like, and you try to measure this in neuroscience experiments,
135
00:15:11,450 --> 00:15:18,303
you'll see that this one is actually a closer
approximation to what's happening than sigmoids.
136
00:15:18,303 --> 00:15:33,798
And so ReLUs were starting to be used a lot around 2012 when we had AlexNet, the first major convolutional neural
network that was able to do well on ImageNet and large-scale data. They used the ReLU in their experiments.
137
00:15:36,775 --> 00:15:42,082
So a problem however, with the ReLU, is that
it's still, it's not not zero-centered anymore.
138
00:15:42,082 --> 00:15:49,228
So we saw that the sigmoid was not zero-centered.
Tanh fixed this and now ReLU has this problem again.
139
00:15:49,228 --> 00:15:52,122
And so that's one of
the issues of the ReLU.
140
00:15:52,122 --> 00:15:55,357
And then we also have
this further annoyance of,
141
00:15:55,357 --> 00:16:04,222
again we saw that in the positive half of the inputs, we don't
have saturation, but this is not the case of the negative half.
142
00:16:04,222 --> 00:16:06,882
Right, so just thinking about this
a little bit more precisely.
143
00:16:06,882 --> 00:16:11,255
So what's happening here
when X equals negative 10?
144
00:16:11,255 --> 00:16:12,855
So zero gradient, that's right.
145
00:16:12,855 --> 00:16:16,522
What happens when X is
equal to positive 10?
146
00:16:17,455 --> 00:16:20,175
It's good, right.
So, we're in the linear regime.
147
00:16:20,175 --> 00:16:30,442
And then what happens when X is equal to zero? Yes, it undefined
here, but in practice, we'll say, you know, zero, right.
148
00:16:30,442 --> 00:16:35,074
And so basically, it's killing the
gradient in half of the regime.
149
00:16:37,948 --> 00:16:45,708
And so we can get this phenomenon of basically dead
ReLUs, when we're in this bad part of the regime.
150
00:16:45,708 --> 00:16:51,212
And so there's, you can look at this in,
as coming from several potential reasons.
151
00:16:51,212 --> 00:16:57,192
And so if we look at our data cloud here,
this is all of our training data,
152
00:16:59,033 --> 00:17:09,092
then if we look at where the ReLUs can fall, so the ReLUs can be, each of
these is basically the half of the plane where it's going to activate.
153
00:17:11,948 --> 00:17:15,640
And so each of these is the plane
that defines each of these ReLUs,
154
00:17:15,640 --> 00:17:21,201
and we can see that you can have these dead
ReLUs that are basically off of the data cloud.
155
00:17:21,201 --> 00:17:26,588
And in this case, it will never activate and
never update, as compared to an active ReLU
156
00:17:26,588 --> 00:17:31,732
where some of the data is going to be positive
and passed through and some won't be.
157
00:17:31,732 --> 00:17:33,480
And so there's several reasons for this.
158
00:17:33,480 --> 00:17:37,201
The first is that it can happen
when you have bad initialization.
159
00:17:37,201 --> 00:17:45,015
So if you have weights that happen to be unlucky and they happen to be
off the data cloud, so they happen to specify this bad ReLU over here.
160
00:17:45,015 --> 00:17:55,069
Then they're never going to get a data input that causes it to activate,
and so they're never going to get good gradient flow coming back.
161
00:17:56,108 --> 00:17:59,321
And so it'll just never
update and never activate.
162
00:17:59,321 --> 00:18:03,880
What's the more common case is
when your learning rate is too high.
163
00:18:03,880 --> 00:18:11,561
And so this case you started off with an okay ReLU, but because
you're making these huge updates, the weights jump around
164
00:18:11,561 --> 00:18:18,028
and then your ReLU unit in a sense, gets knocked off of
the data manifold. And so this happens through training.
165
00:18:18,028 --> 00:18:22,975
So it was fine at the beginning and then
at some point, it became bad and it died.
166
00:18:22,975 --> 00:18:24,108
And so if in practice,
167
00:18:24,108 --> 00:18:33,361
if you freeze a network that you've trained and you pass the data through, you
can see it actually is much as 10 to 20% of the network is these dead ReLUs.
168
00:18:33,361 --> 00:18:40,001
And so you know that's a problem, but also most networks
do have this type of problem when you use ReLUs.
169
00:18:40,001 --> 00:18:49,467
Some of them will be dead, and in practice, people look into this, and
it's a research problem, but it's still doing okay for training networks.
170
00:18:49,467 --> 00:18:51,268
Yeah, is there a question?
171
00:18:51,268 --> 00:18:54,851
[student speaking off mic]
172
00:19:01,908 --> 00:19:05,335
Right. So the question is, yeah, so the
data cloud is just your training data.
173
00:19:05,335 --> 00:19:08,918
[student speaking off mic]
174
00:19:17,641 --> 00:19:25,708
Okay, so the question is when, how do you tell when the ReLU
is going to be dead or not, with respect to the data cloud?
175
00:19:25,708 --> 00:19:30,988
And so if you look at, this is an example
of like a simple two-dimensional case.
176
00:19:30,988 --> 00:19:42,278
And so our ReLU, we're going to get our input to the ReLU, which is going
to be a basically you know, W1 X1 plus W2 X2, and it we apply this,
177
00:19:42,278 --> 00:19:46,080
so that that defines this this
separating hyperplane here,
178
00:19:46,080 --> 00:19:51,453
and then we're going to take half of it that's going to
be positive, and half of it's going to be killed off,
179
00:19:51,453 --> 00:20:03,789
and so yes, so you, you know you just, it's whatever the weights happened to be, and
where the data happens to be is where these, where these hyperplanes fall, and so,
180
00:20:05,560 --> 00:20:14,329
so yeah so just throughout the course of training, some of your
ReLUs will be in different places, with respect to the data cloud.
181
00:20:16,480 --> 00:20:18,050
Oh, question.
182
00:20:18,050 --> 00:20:21,633
[student speaking off mic]
183
00:20:23,380 --> 00:20:33,478
Yeah. So okay, so the question is for the sigmoid we talked about two
drawbacks, and one of them was that the neurons can get saturated,
184
00:20:37,045 --> 00:20:40,500
so let's go back to the sigmoid here,
185
00:20:40,500 --> 00:20:45,820
and the question was this is not the case,
when all of your inputs are positive.
186
00:20:45,820 --> 00:20:51,971
So when all of your inputs are positive, they're all
going to be coming in in this zero plus region here,
187
00:20:51,971 --> 00:20:54,464
and so you can still
get a saturating neuron,
188
00:20:54,464 --> 00:21:00,544
because you see up in this positive
region, it also plateaus at one,
189
00:21:00,544 --> 00:21:08,846
and so when it's when you have large positive values as input you're also
going to get the zero gradient, because you have you have a flat slope here.
190
00:21:10,715 --> 00:21:11,548
Okay.
191
00:21:16,355 --> 00:21:24,528
Okay, so in practice people also like to
initialize ReLUs with slightly positive biases,
192
00:21:24,528 --> 00:21:30,721
in order to increase the likelihood of it being
active at initialization and to get some updates.
193
00:21:30,721 --> 00:21:40,430
Right and so this basically just biases towards more ReLUs firing at the
beginning, and in practice some say that it helps. Some say that it doesn't.
194
00:21:40,430 --> 00:21:48,072
Generally people don't always use this. It's yeah, a lot
of times people just initialize it with zero biases still.
195
00:21:49,483 --> 00:21:54,777
Okay, so now we can look at some modifications
on the ReLU that have come out since then,
196
00:21:54,777 --> 00:21:57,768
and so one example is this leaky ReLU.
197
00:21:57,768 --> 00:22:04,429
And so this looks very similar to the original ReLU, and the only
difference is that now instead of being flat in the negative regime,
198
00:22:04,429 --> 00:22:11,955
we're going to give a slight negative slope here And so this
solves a lot of the problems that we mentioned earlier.
199
00:22:11,955 --> 00:22:17,142
Right here we don't have any saturating
regime, even in the negative space.
200
00:22:17,142 --> 00:22:23,968
It's still very computationally efficient. It still converges
faster than sigmoid and tanh, very similar to a ReLU.
201
00:22:23,968 --> 00:22:27,218
And it doesn't have this dying problem.
202
00:22:28,923 --> 00:22:35,380
And there's also another example
is the parametric rectifier, so PReLU.
203
00:22:35,380 --> 00:22:42,195
And so in this case it's just like a leaky ReLU where
we again have this sloped region in the negative space,
204
00:22:42,195 --> 00:22:47,088
but now this slope in the negative regime
is determined through this alpha parameter,