-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnn_slides_4.tex
executable file
·1456 lines (1113 loc) · 54.8 KB
/
nn_slides_4.tex
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
%!TEX TS-program = xelatex
\documentclass[notes,12pt, aspectratio=169]{beamer}
\usepackage{amsmath,amsfonts,amssymb,amsthm,mathtools} % пакеты для математики
\usepackage{minted}
\usepackage[english, russian]{babel} % выбор языка для документа
\usepackage[utf8]{inputenc} % задание utf8 кодировки исходного tex файла
\usepackage[X2,T2A]{fontenc} % кодировка
\usepackage{fontspec} % пакет для подгрузки шрифтов
\setmainfont{Helvetica} % задаёт основной шрифт документа
% why do we need \newfontfamily:
% http://tex.stackexchange.com/questions/91507/
\newfontfamily{\cyrillicfonttt}{Helvetica}
\newfontfamily{\cyrillicfont}{Helvetica}
\newfontfamily{\cyrillicfontsf}{Helvetica}
\usepackage{unicode-math} % пакет для установки математического шрифта
% \setmathfont{Neo Euler} % шрифт для математики
\usepackage{polyglossia} % Пакет, который позволяет подгружать русские буквы
\setdefaultlanguage{russian} % Основной язык документа
\setotherlanguage{english} % Второстепенный язык документа
% Шрифт для кода
\setmonofont[Scale=0.85]{Monaco}
\usepackage{verbments}
\usepackage{pgfpages}
% These slides also contain speaker notes. You can print just the slides,
% just the notes, or both, depending on the setting below. Comment out the want
% you want.
%\setbeameroption{hide notes} % Only slide
%\setbeameroption{show only notes} % Only notes
%\setbeameroption{show notes on second screen=right} % Both
\usepackage{array}
\usepackage{tikz}
\usepackage{verbatim}
\setbeamertemplate{note page}{\pagecolor{yellow!5}\insertnote}
\usetikzlibrary{positioning}
\usetikzlibrary{snakes}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{matrix,shapes,arrows,fit,tikzmark}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{multimedia}
\usepackage{multirow}
\usepackage{dcolumn}
\usepackage{bbm}
\newcolumntype{d}[0]{D{.}{.}{5}}
\usepackage{changepage}
\usepackage{appendixnumberbeamer}
\newcommand{\beginbackup}{
\newcounter{framenumbervorappendix}
\setcounter{framenumbervorappendix}{\value{framenumber}}
\setbeamertemplate{footline}
{
\leavevmode%
\hline
box{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,right]{footlinecolor}%
% \insertframenumber \hspace*{2ex}
\end{beamercolorbox}}%
\vskip0pt%
}
}
\newcommand{\backupend}{
\addtocounter{framenumbervorappendix}{-\value{framenumber}}
\addtocounter{framenumber}{\value{framenumbervorappendix}}
}
% для имитации питоновского синтаксиса
\newcommand{\pgr}[1]{{\color{green} \textbf{#1}}}
%%%%%%%%%% Работа с картинками %%%%%%%%%
\usepackage{graphicx} % Для вставки рисунков
\usepackage{graphics}
\graphicspath{{images/}} % можно указать папки с картинками
\usepackage{wrapfig} % Обтекание рисунков и таблиц текстом
\usepackage[space]{grffile}
\usepackage{booktabs}
% These are my colors -- there are many like them, but these ones are mine.
\definecolor{blue}{RGB}{0,114,178}
\definecolor{red}{RGB}{213,94,0}
\definecolor{yellow}{RGB}{240,228,66}
\definecolor{green}{RGB}{0,128, 0}
\definecolor{amethyst}{rgb}{0.6, 0.4, 0.8}
\definecolor{junglegreen}{rgb}{0.16, 0.67, 0.53}
\hypersetup{
colorlinks=true,
linkbordercolor = {white},
linkcolor = {blue},
urlcolor= {blue}
}
%% I use a beige off white for my background
\definecolor{MyBackground}{RGB}{255,253,218}
%% Uncomment this if you want to change the background color to something else
%\setbeamercolor{background canvas}{bg=MyBackground}
%% Change the bg color to adjust your transition slide background color!
\newenvironment{transitionframe}{
\setbeamercolor{background canvas}{bg=yellow}
\begin{frame}}{
\end{frame}
}
\setbeamercolor{frametitle}{fg=blue}
\setbeamercolor{title}{fg=black}
\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{itemize items}{-}
\setbeamercolor{itemize item}{fg=blue}
\setbeamercolor{itemize subitem}{fg=blue}
\setbeamercolor{enumerate item}{fg=blue}
\setbeamercolor{enumerate subitem}{fg=blue}
\setbeamercolor{button}{bg=MyBackground,fg=blue,}
% If you like road maps, rather than having clutter at the top, have a roadmap show up at the end of each section
% (and after your introduction)
% Uncomment this is if you want the roadmap!
% \AtBeginSection[]
% {
% \begin{frame}
% \frametitle{Roadmap of Talk}
% \tableofcontents[currentsection]
% \end{frame}
% }
\setbeamercolor{section in toc}{fg=blue}
\setbeamercolor{subsection in toc}{fg=red}
\setbeamersize{text margin left=1em,text margin right=1em}
% списки, которые растягиваются на всю величину слайда
\newenvironment{wideitemize}{\itemize\addtolength{\itemsep}{10pt}}{\enditemize}
\usepackage{xcolor}
% Syntax: \colorboxed[<color model>]{<color specification>}{<math formula>}
\newcommand*{\colorboxed}{}
\def\colorboxed#1#{%
\colorboxedAux{#1}%
}
\newcommand*{\colorboxedAux}[3]{%
% #1: optional argument for color model
% #2: color specification
% #3: formula
\begingroup
\colorlet{cb@saved}{.}%
\color#1{#2}%
\boxed{%
\color{cb@saved}%
#3%
}%
\endgroup
}
\usepackage{pgfplots}
\usepackage{tikz}
\DeclareMathOperator{\logloss}{logloss}
\title[]{\textcolor{blue}{Глубокое обучение и вообще}}
\author{Ульянкин Филипп}
\date{ }
\usepackage{ulem}
\begin{document}
%%% TIKZ STUFF
\tikzset{
every picture/.style={remember picture,baseline},
every node/.style={anchor=base,align=center,outer sep=1.5pt},
every path/.style={thick},
}
\newcommand\marktopleft[1]{%
\tikz[overlay,remember picture]
\node (marker-#1-a) at (-.3em,.3em) {};%
}
\newcommand\markbottomright[2]{%
\tikz[overlay,remember picture]
\node (marker-#1-b) at (0em,0em) {};%
}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{mybox} =[draw=black, very thick, rectangle, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[draw=black,fill=red, text=white]
%%%% END TIKZ STUFF
% Title Slide
\begin{frame}
\maketitle
\centering \textbf{\color{blue} Посиделка 4:} Алгоритм обратного распространения ошибки
\end{frame}
\begin{frame}{Agenda}
\begin{wideitemize}
\item Алгоритм обратного распространения ошибки
\end{wideitemize}
\end{frame}
\begin{transitionframe}
\begin{center}
{\Huge Как обучить нейросеть?} \\ \mbox{ } \\
\begin{tikzpicture}
\node[inner sep=0pt] (russell) at (0,0)
{\includegraphics[scale = 0.15]{ml.png}};
\node[] at (0,-0.6) {Ты необучаем!};
\end{tikzpicture}
\end{center}
\end{transitionframe}
\begin{frame}{Нейросеть — сложная функция}
\begin{wideitemize}
\item Прямое распространение ошибки (forward propagation):
\[ X \Rightarrow X \cdot W_1 \Rightarrow f(X \cdot W_1) \Rightarrow f(X \cdot W_1) \cdot W_2 \Rightarrow \ldots \Rightarrow \hat{y} \]
\item Считаем потери:
\[Loss = \frac{1}{2} (y - \hat y)^2\]
\item Все слои обычно дифференцируемы, поэтому можно посчитать производные по всем параметрам
\item Для обучения можно использовать градиентный спуск
\end{wideitemize}
\end{frame}
\begin{frame}{Как обучить нейросеть?}
\[ L(W_1, W_2) = \frac{1}{2} \cdot (y - f(X \cdot W_1) \cdot W_2)^2\]
\begin{center}
\alert{Секрет успеха в умении брать производную}
\end{center}
\pause
\[ \boxed{ f(g(x))' = f'(g(x)) \cdot g'(x) } \]
\pause
\begin{equation*}
\begin{aligned}
\frac{\partial L}{\partial W_2} &= { \only<2>{ \color{red}} - (y - f(X \cdot W_1) \cdot W_2) } \cdot f(X \cdot W_1) \\
\frac{\partial L}{\partial W_1} &= { \only<2>{ \color{red}} - (y - f(X \cdot W_1) \cdot W_2) } \cdot W_2 \cdot f'(X \cdot W_1) \cdot X
\end{aligned}
\end{equation*}
\vfill
\pause
\alert{Дважды ищем одно и то же $\Rightarrow$ оптимизация поиска производных даст нам алгоритм обратного распространения ошибки (back-propagation)}
\end{frame}
\begin{frame}{Back-propagation}
\begin{center}
\includegraphics[width=.8\linewidth]{backpropagation.png}
\end{center}
\end{frame}
\begin{frame}{Цепное правило}
\begin{wideitemize}
\item Возьмём сложную функцию:
\begin{equation*}
\begin{aligned}
& z_1 = z_1(x_1, x_2) \\ & z_2 = z_2(x_1, x_2) \\ & y = y(z_1, z_2)
\end{aligned}
\end{equation*}
\item Производную такой функции можно найти по цепному правилу:
$$
\frac{\partial y}{\partial x_1} = {\color{amethyst} \frac{\partial y}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{junglegreen} \frac{\partial y}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}}
$$
\end{wideitemize}
\end{frame}
\begin{frame}{Как считать производные?}
\begin{columns}
\begin{column}{0.6\textwidth}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$z_\x$};
% Output
\node at (6, -2.25) [place] (fourth){$y$};
\draw [->, red] (first_1) to (second_1);
\draw [->, green] (first_1) to (second_2);
\draw [->] (first_2) to (second_1);
\draw [->] (first_2) to (second_2);
\draw [->, amethyst] (second_1) to (fourth);
\draw [->, junglegreen] (second_2) to (fourth);
\end{tikzpicture}
\vfill
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (second_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (first_\x){$z_\x$};
% Output
\node at (6, -2.25) [place] (fourth){$y$};
\draw [->, dashed, red] (first_1) to (second_1) node[right=1.cm] {$\frac{\partial z_1}{\partial x_1}$} ;
\draw [->, dashed] (first_1) to (second_2) node[right=1.cm,above] {$\frac{\partial z_1}{\partial x_2}$} ;
\draw [->, dashed, green] (first_2) to (second_1) node[right=2.3cm, below] {$\frac{\partial z_2}{\partial x_1}$} ;
\draw [->, dashed] (first_2) to (second_2) node[right=1.2cm] {$\frac{\partial z_2}{\partial x_2}$} ;
\draw [->, dashed, amethyst] (fourth) to (first_1) node[right=1.cm] {$\frac{\partial y}{\partial z_1}$} ;
\draw [->, dashed, junglegreen] (fourth) to (first_2) node[right=1.cm] {$\frac{\partial y}{\partial z_2}$} ;
\end{tikzpicture}
\end{center}
\end{column}
\begin{column}{0.4\textwidth}
\textbf{Граф вычислений: }
\begin{equation*}
\begin{aligned}
& z_1 = z_1(x_1, x_2)\\
& z_2 = z_2(x_1, x_2) \\
& y = y(z_1, z_2)
\end{aligned}
\end{equation*}
\vfill
\only<1>{
\alert{Из него можно построить граф производных, каждому ребру будет приписана производная}}
\only<2>{\textbf{Можно догадаться как работает цепное правило:}
\[\frac{\partial y}{\partial x_1} = {\color{amethyst} \frac{\partial y}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{junglegreen} \frac{\partial y}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \]
}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{Пойдём глубже}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$z_\x$};
% Hidden 2
\foreach \x in {1,...,2}
\node at (6, -\x*1.5) [place] (third_\x){$h_\x$};
% Output
\node at (9, -2.25) [place] (fourth){$y$};
\draw [->, red] (first_1) to (second_1);
\draw [->, green] (first_1) to (second_2);
\draw [->, red] (first_2) to (second_1);
\draw [->, green] (first_2) to (second_2);
\draw [->, amethyst] (second_1) to (third_1);
\draw [->, junglegreen] (second_1) to (third_2);
\draw [->, amethyst] (second_2) to (third_1);
\draw [->, junglegreen] (second_2) to (third_2);
\draw [->, blue] (third_1) to (fourth);
\draw [->, blue] (third_2) to (fourth);
\end{tikzpicture}
\end{center}
\only<1>{
\begin{equation*}
\begin{aligned}
z_1 = z_1({\color{red} x_1, x_2}) & \quad h_1 = h_1({\color{amethyst} z_1, z_2}) & \quad y = y({\color{blue} h_1, h_2}) \\
z_2 = z_2({\color{green} x_1, x_2}) & \quad h_2 = h_2({\color{junglegreen} z_1, z_2}) &
\end{aligned}
\end{equation*} }
\only<2>{
\[ \frac{\partial y}{\partial x_1} = ? \]
}
\only<3>{
\[ \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot \frac{\partial h_1}{\partial x_1} + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot \frac{\partial h_2}{\partial x_1} \]
}
\only<4>{
\[ \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot \boxed{ \frac{\partial h_1}{\partial x_1} } + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot \boxed{ \frac{\partial h_2}{\partial x_1} } \]
}
\only<5>{
\[ \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot \underbrace{ \boxed{ \frac{\partial h_1}{\partial x_1} } }_{ {\color{amethyst} \frac{\partial h_1}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{amethyst} \frac{\partial h_1}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} } + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot \underbrace{\boxed{ \frac{\partial h_2}{\partial x_1} } }_{ {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} } \]
}
\only<6>{
\[ \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot \left( {\color{amethyst} \frac{\partial h_1}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{amethyst} \frac{\partial h_1}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \right) + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot \left( {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \right) \]
}
\only<7>{
\[ \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} \]
}
\end{frame}
\begin{frame}{Пойдём глубже}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$z_\x$};
% Hidden 2
\foreach \x in {1,...,2}
\node at (6, -\x*1.5) [place] (third_\x){$h_\x$};
% Output
\node at (9, -2.25) [place] (fourth){$y$};
\draw [->, dashed, red] (second_1) to (first_1);
\draw [->, dashed, green] (second_2) to (first_1);
\draw [->, dashed, red] (second_1) to (first_2);
\draw [->, dashed, green] (second_2) to (first_2);
\draw [->, dashed, amethyst] (third_1) to (second_1);
\draw [->, dashed, junglegreen] (third_2) to (second_1);
\draw [->, dashed, amethyst] (third_1) to (second_2);
\draw [->, dashed, junglegreen] (third_2) to (second_2);
\draw [->, dashed, blue] (fourth) to (third_1);
\draw [->, dashed, blue] (fourth) to (third_2);
\only<2>{
\draw [->, dashed, ultra thick, blue] (fourth) to (third_1);
\draw [->, dashed, ultra thick, amethyst] (third_1) to (second_1);
\draw [->, dashed, ultra thick, red] (second_1) to (first_1);
}
\only<3>{
\draw [->, dashed, ultra thick, blue] (fourth) to (third_1);
\draw [->, dashed, ultra thick, amethyst] (third_1) to (second_2);
\draw [->, dashed, ultra thick, green] (second_2) to (first_1);
}
\only<4>{
\draw [->, dashed, ultra thick, blue] (fourth) to (third_2);
\draw [->, dashed, ultra thick, junglegreen] (third_2) to (second_1);
\draw [->, dashed, ultra thick, red] (second_1) to (first_1);
}
\only<5>{
\draw [->, dashed, ultra thick, blue] (fourth) to (third_2);
\draw [->, dashed, ultra thick, junglegreen] (third_2) to (second_2);
\draw [->, dashed, ultra thick, green] (second_2) to (first_1);
}
\end{tikzpicture}
\end{center}
\only<1>{
\[
\frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}}
\]
}
\only<2>{
\[
\frac{\partial y}{\partial x_1} = \boxed{ {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} } + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}}
\]
}
\only<3>{
\[
\frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + \boxed{ {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} } + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}}
\]
}
\only<4>{
\[
\frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + \boxed{ {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} } + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}}
\]
}
\only<5>{
\[
\frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + \boxed{ {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} }
\]
}
\end{frame}
\begin{frame}{Алгоритм поиска производной в графе}
\begin{wideitemize}
\item Как посчитать производную $a$ по $b$?
\item Находим непосещённый путь из $a$ в $b$
\item Перемножаем значения на рёбрах пути
\item Добавляем в сумму
\end{wideitemize}
\vspace{-1.5cm}
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (second_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (first_\x){$z_\x$};
% Output
\node at (6, -2.25) [place] (fourth){$y$};
\draw [->, dashed, red] (first_1) to (second_1) node[right=1.cm] {$\frac{\partial z_1}{\partial x_1}$} ;
\draw [->, dashed] (first_1) to (second_2);
\draw [->, dashed, green] (first_2) to (second_1) node[right=2.3cm, below] {$\frac{\partial z_2}{\partial x_1}$} ;
\draw [->, dashed] (first_2) to (second_2);
\draw [->, dashed, amethyst] (fourth) to (first_1) node[right=1.cm] {$\frac{\partial y}{\partial z_1}$} ;
\draw [->, dashed, junglegreen] (fourth) to (first_2) node[right=1.cm] {$\frac{\partial y}{\partial z_2}$} ;
\end{tikzpicture}
\end{center}
\end{column}
\begin{column}{0.4\textwidth}
\[
\frac{\partial y}{\partial x_1} = {\color{amethyst} \frac{\partial y}{\partial z_1} } \cdot {\color{red} \frac{\partial z_1}{\partial x_1} } + {\color{ junglegreen} \frac{\partial y}{\partial z_2} } \cdot {\color{green} \frac{\partial z_2}{\partial x_1 } }
\]
\end{column}
\end{columns}
\end{frame}
\begin{frame}{На примере одного нейрона}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% weights
\draw node at (1, -0.5) [place] (param_1) {$w_1$};
\draw node at (1, -4) [place] (param_2) {$w_2$};
% product
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$\cdot$};
% sum
\node at (5, -2.25) [place] (sum){$s$};
\node at (7, -2.25) [place] (activ){$f$};
\node at (9, -2.25) [place] (out){$z$};
\node at (11, -2.75) [place] (loss){$L$};
\node at (9, -3.25) [place] (target){$y$};
\draw [->] (first_1) to (second_1);
\draw [->] (first_2) to (second_2);
\draw [->] (param_1) to (second_1);
\draw [->] (param_2) to (second_2);
\draw [->] (second_1) to (sum);
\draw [->] (second_2) to (sum);
\draw [->] (sum) to (activ);
\draw [->] (activ) to (out);
\draw [->] (out) to (loss);
\draw [->] (target) to (loss);
\end{tikzpicture}
\begin{equation*}
z = f(s) = f(w_1 \cdot x_1 + w_2 \cdot x_2)
\end{equation*}
\alert{ Для SGD нам нужны $\frac{\partial L}{\partial w_1}$ и $\frac{\partial L}{\partial w_2}$ }
\end{center}
\end{frame}
\begin{frame}{Граф производных}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% weights
\draw node at (1, -0.5) [place] (param_1) {$w_1$};
\draw node at (1, -4) [place] (param_2) {$w_2$};
% product
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$\cdot$};
% sum
\node at (5, -2.25) [place] (sum){$s$};
\node at (7, -2.25) [place] (activ){$f$};
\node at (9, -2.25) [place] (out){$z$};
\node at (11, -2.75) [place] (loss){$L$};
\node at (9, -3.25) [place] (target){$y$};
\only<1>{
\draw [->, dashed, red] (second_1) to (first_1) node[below right=2.mm] {$w_1$} ;
\draw [->, dashed, red] (second_2) to (first_2) node[above right=2.mm] {$w_2$} ;
\draw [->, dashed, red] (second_1) to (param_1) node[right=1.cm] {$x_1$} ;
\draw [->, dashed, red] (second_2) to (param_2) node[right=1.cm] {$x_2$} ;
\draw [->, dashed, red] (sum) to (second_1) node[right=8.mm] {$1$} ;
\draw [->, dashed, red] (sum) to (second_2) node[right=8.mm] {$1$} ;
\draw [->, dashed, red] (activ) to (sum) node[right=6.mm] {$\frac{\partial f}{\partial s}$} ;
\draw [->, dashed, red] (out) to (activ) node[right=7.mm] {$1$} ;
\draw [->, dashed] (loss) to (out) node[right=7.mm] {$\frac{\partial L}{\partial z}$} ;
\draw [->, dashed] (loss) to (target) ;
}
\only<2>{
\draw [->, dashed, red] (second_1) to (first_1) node[below right=2.mm] {$w_1$} ;
\draw [->, dashed, red] (second_2) to (first_2) node[above right=2.mm] {$w_2$} ;
\draw [->, dashed, amethyst, ultra thick] (second_1) to (param_1) node[right=1.cm] {$x_1$} ;
\draw [->, dashed, red] (second_2) to (param_2) node[right=1.cm] {$x_2$} ;
\draw [->, dashed, amethyst, ultra thick] (sum) to (second_1) node[right=8.mm] {$1$} ;
\draw [->, dashed, red] (sum) to (second_2) node[right=8.mm] {$1$} ;
\draw [->, dashed, amethyst, ultra thick] (activ) to (sum) node[right=6.mm] {$\frac{\partial f}{\partial s}$} ;
\draw [->, dashed, amethyst, ultra thick] (out) to (activ) node[right=7.mm] {$1$} ;
\draw [->, dashed, amethyst, ultra thick] (loss) to (out) node[right=7.mm] {$\frac{\partial L}{\partial z}$} ;
\draw [->, dashed] (loss) to (target) ;
}
\only<3>{
\draw [->, dashed, red] (second_1) to (first_1) node[below right=2.mm] {$w_1$} ;
\draw [->, dashed, red] (second_2) to (first_2) node[above right=2.mm] {$w_2$} ;
\draw [->, dashed, red] (second_1) to (param_1) node[right=1.cm] {$x_1$} ;
\draw [->, dashed, amethyst, ultra thick] (second_2) to (param_2) node[right=1.cm] {$x_2$} ;
\draw [->, dashed, red] (sum) to (second_1) node[right=8.mm] {$1$} ;
\draw [->, dashed, amethyst, ultra thick] (sum) to (second_2) node[right=8.mm] {$1$} ;
\draw [->, dashed, amethyst, ultra thick] (activ) to (sum) node[right=6.mm] {$\frac{\partial f}{\partial s}$} ;
\draw [->, dashed, amethyst, ultra thick] (out) to (activ) node[right=7.mm] {$1$} ;
\draw [->, dashed, amethyst, ultra thick] (loss) to (out) node[right=7.mm] {$\frac{\partial L}{\partial z}$} ;
\draw [->, dashed] (loss) to (target) ;
}
\end{tikzpicture}
\begin{equation*}
z = f(s) = f(w_1 \cdot x_1 + w_2 \cdot x_2)
\end{equation*}
\only<1> { \alert{ Для SGD нам нужны $\frac{\partial L}{\partial w_1}$ и $\frac{\partial L}{\partial w_2}$ } }
\only<2>{
\[
\frac{\partial L}{\partial w_1} = \frac{\partial L}{\partial z} \cdot \frac{\partial f}{\partial s} \cdot x_1
\] }
\only<3>{
\[
\frac{\partial L}{\partial w_1} = \frac{\partial L}{\partial z} \cdot \frac{\partial f}{\partial s} \cdot x_1 \qquad \frac{\partial L}{\partial w_2} = \frac{\partial L}{\partial z} \cdot \frac{\partial f}{\partial s} \cdot x_2
\] }
\end{center}
\end{frame}
\begin{frame}{Цепное правило и грaф производных}
\begin{wideitemize}
\item Теперь у нас есть алгоритм для подсчета производных для любых
дифференцируемых графов вычислений
\item \alert{ Осталось делать вычисления быстро }
\end{wideitemize}
\end{frame}
\begin{frame}{Обратное распространение ошибки}
\alert{Мы хотим поменять параметры нейрона в рамках SGD}
\vfill
\[
h_2 = f(w_0 + w_1 z_1 + w_2 z_2)
\]
\vfill
\[
\frac{\partial L}{\partial w_1} = \frac{\partial L}{\partial y} \cdot \frac{\partial y}{\partial w_1} = \frac{\partial L}{\partial y} \cdot {\color{blue} \frac{\partial y}{\partial h_2}} \cdot \frac{\partial h_2}{\partial w_1}
\]
\vfill
\[
w_1^t = w_1^{t-1} - \gamma \cdot \frac{\partial L}{\partial w_1} (w_1^{t-1})
\]
\end{frame}
\begin{frame}{Обратное распространение ошибки}
\begin{equation*}
\begin{aligned}
\only<1-6>{ & 3: \quad {\color{blue} \frac{\partial y}{\partial h_2} \qquad \frac{\partial y}{\partial h_1}} \\}
\only<2-6>{& 2: \quad \frac{\partial y}{\partial z_1} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot {\color{amethyst} \frac{\partial h_1}{\partial z_1}} + \frac{\partial y}{\partial h_2} \cdot {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} \qquad \frac{\partial y}{\partial z_2} = {\color{blue} \frac{\partial y}{\partial h_1}} \cdot {\color{amethyst} \frac{\partial h_1}{\partial z_2}} + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \\}
\only<3>{& 1: \quad \frac{\partial y}{\partial x_1} = {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} {\color{red} \frac{\partial z_1}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} {\color{green} \frac{\partial z_2}{\partial x_1}} \\ }
\only<4>{& 1: \quad \frac{\partial y}{\partial x_1} = \left( {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_1}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_1}} \right) \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + \left( {\color{blue} \frac{\partial y}{\partial h_1}} {\color{amethyst} \frac{\partial h_1}{\partial z_2}} + {\color{blue} \frac{\partial y}{\partial h_2}} {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \right) \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \\ }
\only<5>{& 1: \quad \frac{\partial y}{\partial x_1} = \frac{\partial y}{\partial z_1} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + \frac{\partial y}{\partial z_2} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \\ }
\only<6>{& 1: \quad \frac{\partial y}{\partial x_1} = \frac{\partial y}{\partial z_1} \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + \frac{\partial y}{\partial z_2} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \qquad \frac{\partial y}{\partial x_2} = \frac{\partial y}{\partial z_1} \cdot {\color{red} \frac{\partial z_1}{\partial x_2}} + \frac{\partial y}{\partial z_2} \cdot {\color{green} \frac{\partial z_2}{\partial x_2}} \\ }
\only<7>{
& 3: \quad {\color{blue} \frac{\partial y}{\partial h_2} \qquad \boxed{ \frac{\partial y}{\partial h_1}} } \\
& 2: \quad \boxed{ \frac{\partial y}{\partial z_1} } = {\color{blue} \boxed{ \frac{\partial y}{\partial h_1}}} \cdot {\color{amethyst} \frac{\partial h_1}{\partial z_1}} + \frac{\partial y}{\partial h_2} \cdot {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \qquad \frac{\partial y}{\partial z_2} = {\color{blue} \boxed{ \frac{\partial y}{\partial h_1}} } \cdot {\color{amethyst} \frac{\partial h_1}{\partial z_2}} + {\color{blue} \frac{\partial y}{\partial h_2}} \cdot {\color{junglegreen} \frac{\partial h_2}{\partial z_2}} \\
& 1: \quad \frac{\partial y}{\partial x_1} = \boxed{ \frac{\partial y}{\partial z_1} } \cdot {\color{red} \frac{\partial z_1}{\partial x_1}} + \frac{\partial y}{\partial z_2} \cdot {\color{green} \frac{\partial z_2}{\partial x_1}} \qquad \frac{\partial y}{\partial x_2} = \boxed{ \frac{\partial y}{\partial z_1}} \cdot {\color{red} \frac{\partial z_1}{\partial x_2}} + \frac{\partial y}{\partial z_2} \cdot {\color{green} \frac{\partial z_2}{\partial x_2}} \\
}
\end{aligned}
\end{equation*}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% Hidden 1
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$z_\x$};
% Hidden 2
\foreach \x in {1,...,2}
\node at (6, -\x*1.5) [place] (third_\x){$h_\x$};
% Output
\node at (9, -2.25) [place] (fourth){$y$};
\draw [->, dashed, red] (second_1) to (first_1);
\draw [->, dashed, green] (second_2) to (first_1);
\draw [->, dashed, red] (second_1) to (first_2);
\draw [->, dashed, green] (second_2) to (first_2);
\draw [->, dashed, amethyst] (third_1) to (second_1);
\draw [->, dashed, junglegreen] (third_2) to (second_1);
\draw [->, dashed, amethyst] (third_1) to (second_2);
\draw [->, dashed, junglegreen] (third_2) to (second_2);
\draw [->, dashed, blue] (fourth) to (third_1);
\draw [->, dashed, blue] (fourth) to (third_2);
\only<1-6>{
\draw [->, dashed, ultra thick, blue] (fourth) to (third_1);
\draw [->, dashed, ultra thick, blue] (fourth) to (third_2);
}
\only<2-6>{
\draw [->, dashed, ultra thick, amethyst] (third_1) to (second_1);
\draw [->, dashed, ultra thick, junglegreen] (third_2) to (second_1);
}
\only<3-6>{
\draw [->, dashed, ultra thick, red] (second_1) to (first_1);
}
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}{Обратное распространение ошибки}
\begin{wideitemize}
\item Это называется reverse-mode дифференцирование, в теории нейросетей это называют \alert{back-propagation (обратное распространение ошибки)}
\item Работает быстро, потому что переиспользует вычисленные ранее значения
\item На самом деле, по каждому ребру пройдемся всего раз, то есть сложность линейна по количеству ребер (т.е. параметров)
\end{wideitemize}
\end{frame}
\begin{frame}{Back-propagation на одном нейроне}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
\tikzstyle{place2}=[circle, draw=red, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% weights
\draw node at (1, -0.5) [place] (param_1) {$w_1$};
\draw node at (1, -4) [place] (param_2) {$w_2$};
% product
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$\cdot$};
\node[thick] at (7, -1) {$z = \sigma(s) = \sigma(w_1 x_1 + w_2 x_2)$};
% sum
\node at (5, -2.25) [place] (sum){$s$};
\node at (7, -2.25) [place] (activ){$\sigma$};
\node at (9, -2.25) [place] (out){$z$};
\draw [->] (first_1) to (second_1);
\draw [->] (first_2) to (second_2);
\draw [->] (param_1) to (second_1);
\draw [->] (param_2) to (second_2);
\draw [->] (second_1) to (sum);
\draw [->] (second_2) to (sum);
\draw [->] (sum) to (activ);
\draw [->] (activ) to (out);
\end{tikzpicture}
\end{center}
\vfill
Данные текут сквозь нейрон:
\[ \boxed{X} \Rightarrow \boxed{s = X \cdot W} \Rightarrow \boxed{z =\sigma(s)} \Rightarrow \boxed{L(z, y) = (y - z)^2 }\]
\end{frame}
\begin{frame}{Back-propagation на одном нейроне}
Forward pass:
\only<1>{ \[ \boxed{X} \Rightarrow \boxed{s = X \cdot W} \Rightarrow \boxed{z =\sigma(s)} \Rightarrow \boxed{L(z, y) = (y - z)^2 }\] }
\only<2>{ \[ \boxed{X} \Rightarrow { \color{amethyst} \boxed{s = X \cdot W} } \Rightarrow \boxed{z =\sigma(s)} \Rightarrow \boxed{L(z, y) = (y - z)^2 }\] }
Backward pass:
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% weights
\draw node at (1, -0.5) [place] (param_1) {$w_1$};
\draw node at (1, -4) [place] (param_2) {$w_2$};
% product
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$\cdot$};
% sum
\node at (5, -2.25) [place] (sum){$s$};
\node at (7, -2.25) [place] (activ){$f$};
\node at (9, -2.25) [place] (out){$z$};
\node at (11, -2.75) [place] (loss){$L$};
\node at (9, -3.25) [place] (target){$y$};
\only<2>{
\node[amethyst, thick] at (7, 0.4) {\text{Нам нужно вычислить} };
\node[amethyst, thick] at (7, 0) {\text{сигмоиду в точке s} };
\node[thick] at (8, -1) {$\frac{\partial \sigma}{\partial s} = \sigma(s) \cdot (1 - \sigma(s))$};
}
\draw [->, dashed, red] (second_1) to (first_1) node[below right=2.mm] {$w_1$} ;
\draw [->, dashed, red] (second_2) to (first_2) node[above right=2.mm] {$w_2$} ;
\draw [->, dashed, red] (second_1) to (param_1) node[right=1.cm] {$x_1$} ;
\draw [->, dashed, red] (second_2) to (param_2) node[right=1.cm] {$x_2$} ;
\draw [->, dashed, red] (sum) to (second_1) node[right=8.mm] {$1$} ;
\draw [->, dashed, red] (sum) to (second_2) node[right=8.mm] {$1$} ;
\only<1>{ \draw [->, dashed, red] (activ) to (sum) node[right=6.mm] {$\frac{\partial \sigma}{\partial s}$} ; }
\only<2>{ \draw [->, dashed, ultra thick, amethyst] (activ) to (sum) node[right=6.mm] {$\frac{\partial \sigma}{\partial s}$} ; }
\draw [->, dashed, red] (out) to (activ) node[right=7.mm] {$1$} ;
\draw [->, dashed] (loss) to (out) node[right=7.mm] {$\frac{\partial L}{\partial z}$} ;
\draw [->, dashed] (loss) to (target) ;
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}{Сигмоида: прямой проход (forward pass)}
\begin{center}
\begin{tikzpicture}
\tikzstyle{place}=[circle, draw=black, minimum size = 8mm]
\tikzstyle{place2}=[circle, draw=red, minimum size = 8mm]
% Input
\foreach \x in {1,...,2}
\draw node at (0, -\x*1.5) [place] (first_\x) {$x_\x$};
% weights
\draw node at (1, -0.5) [place] (param_1) {$w_1$};
\draw node at (1, -4) [place] (param_2) {$w_2$};
% product
\foreach \x in {1,...,2}
\node at (3, -\x*1.5) [place] (second_\x){$\cdot$};
\node[thick] at (7, -1) {$z = \sigma(s) = \sigma(w_1 x_1 + w_2 x_2)$};
% sum
\node at (5, -2.25) [place2] (sum){\color{red} $s$};
\node at (7, -2.25) [place2] (activ){\color{red} $\sigma$};
\node at (9, -2.25) [place2] (out){\color{red} $z$};
\draw [->] (first_1) to (second_1);
\draw [->] (first_2) to (second_2);
\draw [->] (param_1) to (second_1);
\draw [->] (param_2) to (second_2);
\draw [->] (second_1) to (sum);
\draw [->] (second_2) to (sum);
\draw [->, red] (sum) to (activ);
\draw [->, red] (activ) to (out);
\end{tikzpicture}
\end{center}
{\color{green} def} {\color{blue} forward\_pass}(s): \\
\mbox{ } \hspace{5mm} {\color{green} return } 1/(1 + np.exp(-s))
\end{frame}
\begin{frame}{Сигмоида: обратный проход (backward pass)}
\begin{center}