Commit 415f6e39 by xiaotong

new pages

parent 0ff8092c
...@@ -107,104 +107,69 @@ ...@@ -107,104 +107,69 @@
%%%------------------------------------------------------------------------------------------------------------ %%%------------------------------------------------------------------------------------------------------------
\section{为什么要谈神经网络} \section{为什么要谈神经网络}
%%%------------------------------------------------------------------------------------------------------------
\subsection{神经网络的简单实现:张量计算}
\newcounter{mycount1} \newcounter{mycount1}
\newcounter{mycount2} \newcounter{mycount2}
\newcounter{mycount3} \newcounter{mycount3}
\newcounter{mycount4} \newcounter{mycount4}
%%%------------------------------------------------------------------------------------------------------------ %%%------------------------------------------------------------------------------------------------------------
%%% 利用XTensor构建更复杂的神经网络 \subsection{参数学习 - 反向传播}
\begin{frame}{更复杂一点的例子}
%%%------------------------------------------------------------------------------------------------------------
%%% 神经网络 = 表达式
\begin{frame}{神经网络 = 表达式}
\begin{itemize} \begin{itemize}
\item 任何网络都可以构建,比如RNN、Transformer 等 \item 所有的神经网络都可以看做由变量和函数组成的表达式\\
\end{itemize} \end{itemize}
\begin{tcolorbox}
[bicolor,sidebyside,righthand width=4cm,size=title,frame engine=empty,
colback=blue!10!white,colbacklower=black!5!white]
{\scriptsize
\begin{tabbing}
\texttt{XTensor x[3], y[3], r, wh;} \\
\texttt{XTensor h1, h2, w1, b1, h3, h4;} \\
\texttt{XList splits;} \\
\texttt{...} \\
\texttt{for(unsigned i = 0; i < 3; i++)\{} \\
\texttt{\hspace{2em}r = Concatenate(x[i] + r) * wh;}\\
\texttt{\hspace{2em}splits.Add(\&r);}\\
\texttt{\}}\\
\visible<2->{
\texttt{} \\
\texttt{h1 = Merge(splits, 0);}\\
\texttt{h2 = Relu(h1 * w1 + b1);}\\
\texttt{h3 = h1 + h2;} \\
\texttt{h4 = Softmax(h3);} \\
}
\visible<3->{
\texttt{} \\
\texttt{Split(h4, splits, 0);} \\
\texttt{} \\
\texttt{for(unsigned i = 0; i < 3; i++)\{} \\
\texttt{\hspace{2em}y[i] = *(XTensor*)splits.Get(i);}\\
\texttt{\hspace{2em}y[i].Dump(stdout);}\\
\texttt{\}}
}
\end{tabbing}
}
\tcblower
\begin{center} \begin{center}
\begin{tikzpicture} \begin{tikzpicture}
\node [draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (x1) at (0,0) {\footnotesize{$\textrm{x}_1$}}; \node [anchor=north west] (eq1) at (0,0) {$\textbf{y} = \textbf{x} + \textbf{b}$};
\node [anchor=west,draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (x2) at ([xshift=2em]x1.east) {\footnotesize{$\textrm{x}_2$}}; \node [anchor=north west] (eq2) at (eq1.south west) {$\textbf{y} = \textrm{Relu}(\textbf{x} \cdot \textbf{w} + \textbf{b})$};
\node [anchor=west,draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (x3) at ([xshift=2em]x2.east) {\footnotesize{$\textrm{x}_3$}}; \node [anchor=north west] (eq3) at (eq2.south west) {$\textbf{y} = (\textrm{Relu}(\textbf{x} \cdot \textbf{w}_1 + \textbf{b}) + \textbf{x}) \cdot \textbf{w}_2$};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=2.5em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (rlayer1) at ([yshift=1em]x1.north) {\tiny{rlayer}}; \node [anchor=north west] (eq4) at (eq3.south west) {$\textbf{y} = \textrm{Sigmoid}(\textrm{Relu}(\textbf{x} \cdot \textbf{w}_1 + \textbf{b}_1) + \textbf{x}) \cdot \textbf{w}_2 + \textbf{b}_2$};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=2.5em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (rlayer2) at ([yshift=1em]x2.north) {\tiny{rlayer}};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=2.5em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (rlayer3) at ([yshift=1em]x3.north) {\tiny{rlayer}};
\draw [->,thick] (x1.north) -- (rlayer1.south);
\draw [->,thick] (x2.north) -- (rlayer2.south);
\draw [->,thick] (x3.north) -- (rlayer3.south);
\draw [->,thick] (rlayer1.east) -- (rlayer2.west);
\draw [->,thick] (rlayer2.east) -- (rlayer3.west);
\draw [->,thick] (rlayer1.north) -- ([yshift=1em]rlayer1.north);
\draw [->,thick] (rlayer2.north) -- ([yshift=1em]rlayer2.north);
\draw [->,thick] (rlayer3.north) -- ([yshift=1em]rlayer3.north);
\visible<2->{ \visible<2->{
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=9.4em,minimum height=1.0em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (h1) at ([yshift=1em]rlayer2.north) {\tiny{h1 = Merge($\cdot$)}}; \node [anchor=north west,minimum height=1.2em,minimum width=1.2em,fill=green!30!white] (xlabel) at ([yshift=-0.5em,xshift=0.3em]eq4.south west) {};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=9.4em,minimum height=1.0em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (h2) at ([yshift=1em]h1.north) {\tiny{h2 = Relu($\cdot$)}}; \node [anchor=west] (xlabel2) at (xlabel.east) {输入变量 - 由用户指定};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=9.4em,minimum height=1.0em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (h3) at ([yshift=1em]h2.north) {\tiny{h3 = Sum($\cdot$)}};
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=9.4em,minimum height=1.0em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (h4) at ([yshift=1em]h3.north) {\tiny{h4 = Softmax($\cdot$)}};
\draw [->,thick] (h1.north) -- (h2.south);
\draw [->,thick] (h2.north) -- (h3.south);
\draw [->,thick] (h3.north) -- (h4.south);
\draw [->,thick,rounded corners] (h1.east) -- ([xshift=0.5em]h1.east) -- ([xshift=0.5em,yshift=0.5em]h2.north east) -- ([xshift=-2em,yshift=0.5em]h2.north east) -- ([xshift=-2em,yshift=1em]h2.north east);
} }
\begin{pgfonlayer}{background}
\visible<2->{
\node [anchor=south, minimum height=1.6em,minimum width=0.8em,fill=green!30!white] (x1) at ([xshift=-1.3em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=0.8em,fill=green!30!white] (x2) at ([xshift=4.9em]eq4.south) {};
}
\end{pgfonlayer}
\visible<3->{ \visible<3->{
\node [anchor=south,draw,rounded corners,inner sep=2pt,minimum width=9.4em,minimum height=1.0em,fill=green!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (slayer) at ([yshift=1em]h4.north) {\tiny{Split($\cdot$)}}; \node [anchor=north west,minimum height=1.2em,minimum width=1.2em,fill=red!30!white] (wlabel) at ([yshift=-0.3em]xlabel.south west) {};
\node [anchor=south,draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (y2) at ([yshift=1em]slayer.north) {\footnotesize{$\textrm{y}_2$}}; \node [anchor=west] (wlabel2) at (wlabel.east) {模型参数 - 怎么设置???};
\node [anchor=east,draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (y1) at ([xshift=-2em]y2.west) {\footnotesize{$\textrm{y}_1$}};
\node [anchor=west,draw,circle,inner sep=1pt,fill=red!30!white,blur shadow={shadow xshift=1pt,shadow yshift=-1pt}] (y3) at ([xshift=2em]y2.east) {\footnotesize{$\textrm{y}_3$}};
\draw [<-,thick] (y1.south) -- ([yshift=-1em]y1.south);
\draw [<-,thick] (y2.south) -- ([yshift=-1em]y2.south);
\draw [<-,thick] (y3.south) -- ([yshift=-1em]y3.south);
} }
\visible<2->{ \begin{pgfonlayer}{background}
\draw [->,thick] (h4.north) -- (slayer.south); \visible<3->{
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (w1) at ([xshift=0.2em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (b1) at ([xshift=2.5em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (w2) at ([xshift=6.85em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (b2) at ([xshift=9.2em]eq4.south) {};
} }
\end{pgfonlayer}
\end{tikzpicture} \end{tikzpicture}
\end{center} \end{center}
\end{tcolorbox}
\end{frame} \visible<4->{
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=blue!5!white,colframe=blue!75!black,drop fuzzy shadow]
{\Large
\textbf{问题来了,}
\vspace{0.4em}
\textbf{如何确定w和b,使x与y对应得更好?}
}
\end{tcolorbox}
}
%%%------------------------------------------------------------------------------------------------------------ \end{frame}
\subsection{参数学习 - 反向传播}
\end{CJK} \end{CJK}
\end{document} \end{document}
...@@ -1986,7 +1986,7 @@ cycle} ...@@ -1986,7 +1986,7 @@ cycle}
\draw[step=0.5cm,thick] (0,-0.5) grid (1.5,0); \draw[step=0.5cm,thick] (0,-0.5) grid (1.5,0);
\setcounter{mycount1}{1} \setcounter{mycount1}{1}
\foreach \x in {0.25,0.75,1.25}{ \foreach \x in {0.25,0.75,1.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount1}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount1}$};
\addtocounter{mycount1}{1}; \addtocounter{mycount1}{1};
} }
\end{scope} \end{scope}
...@@ -2000,11 +2000,11 @@ cycle} ...@@ -2000,11 +2000,11 @@ cycle}
\draw[step=0.5cm,thick] (0,-0.5) grid (3.0,0); \draw[step=0.5cm,thick] (0,-0.5) grid (3.0,0);
\setcounter{mycount2}{1} \setcounter{mycount2}{1}
\foreach \x in {0.25,0.75,1.25}{ \foreach \x in {0.25,0.75,1.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount2}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount2}$};
\addtocounter{mycount2}{1}; \addtocounter{mycount2}{1};
} }
\foreach \x in {1.75,2.25,2.75}{ \foreach \x in {1.75,2.25,2.75}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount2}}; \node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount2}$};
\addtocounter{mycount2}{1}; \addtocounter{mycount2}{1};
} }
\end{scope} \end{scope}
...@@ -2018,19 +2018,19 @@ cycle} ...@@ -2018,19 +2018,19 @@ cycle}
\draw[step=0.5cm,thick] (0,-0.5) grid (6.0,0); \draw[step=0.5cm,thick] (0,-0.5) grid (6.0,0);
\setcounter{mycount3}{1} \setcounter{mycount3}{1}
\foreach \x in {0.25,0.75,1.25}{ \foreach \x in {0.25,0.75,1.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount3}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount3}$};
\addtocounter{mycount3}{1}; \addtocounter{mycount3}{1};
} }
\foreach \x in {1.75,2.25,2.75}{ \foreach \x in {1.75,2.25,2.75}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount3}}; \node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount3}$};
\addtocounter{mycount3}{1}; \addtocounter{mycount3}{1};
} }
\foreach \x in {3.25,3.75,4.25}{ \foreach \x in {3.25,3.75,4.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount3}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount3}$};
\addtocounter{mycount3}{1}; \addtocounter{mycount3}{1};
} }
\foreach \x in {4.75,5.25,5.75}{ \foreach \x in {4.75,5.25,5.75}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {\number\value{mycount3}}; \node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,-0.25) {$\number\value{mycount3}$};
\addtocounter{mycount3}{1}; \addtocounter{mycount3}{1};
} }
\draw[decorate,thick,decoration={brace,mirror,raise=0.2em}] (0,-0.50) -- (2.95,-0.50); \draw[decorate,thick,decoration={brace,mirror,raise=0.2em}] (0,-0.50) -- (2.95,-0.50);
...@@ -2071,7 +2071,7 @@ cycle} ...@@ -2071,7 +2071,7 @@ cycle}
\draw[step=0.5cm,color=orange,thick] (-1,-1) grid (1,1); \draw[step=0.5cm,color=orange,thick] (-1,-1) grid (1,1);
\foreach \y in {+0.75,+0.25,-0.25,-0.75} \foreach \y in {+0.75,+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{1}; \addtocounter{mycount1}{1};
} }
} }
...@@ -2083,7 +2083,7 @@ cycle} ...@@ -2083,7 +2083,7 @@ cycle}
\draw[step=0.5cm,color=blue,thick] (-1,-1) grid (1,1); \draw[step=0.5cm,color=blue,thick] (-1,-1) grid (1,1);
\foreach \y in {+0.75,+0.25,-0.25,-0.75} \foreach \y in {+0.75,+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=blue!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount2}}; \node [fill=blue!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount2}$};
\addtocounter{mycount2}{1}; \addtocounter{mycount2}{1};
} }
} }
...@@ -2095,7 +2095,7 @@ cycle} ...@@ -2095,7 +2095,7 @@ cycle}
\draw[step=0.5cm,color=ugreen,thick] (-1,-1) grid (1,1); \draw[step=0.5cm,color=ugreen,thick] (-1,-1) grid (1,1);
\foreach \y in {+0.75,+0.25,-0.25,-0.75} \foreach \y in {+0.75,+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount3}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount3}$};
\addtocounter{mycount3}{1}; \addtocounter{mycount3}{1};
} }
} }
...@@ -2107,7 +2107,7 @@ cycle} ...@@ -2107,7 +2107,7 @@ cycle}
\draw[step=0.5cm,color=red,thick] (-1,-1) grid (1,1); \draw[step=0.5cm,color=red,thick] (-1,-1) grid (1,1);
\foreach \y in {+0.75,+0.25,-0.25,-0.75} \foreach \y in {+0.75,+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount4}}; \node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount4}$};
\addtocounter{mycount4}{1}; \addtocounter{mycount4}{1};
} }
\node [anchor=north] (xlabel) at (0,-1.2) {$\textbf{x}$}; \node [anchor=north] (xlabel) at (0,-1.2) {$\textbf{x}$};
...@@ -2117,14 +2117,14 @@ cycle} ...@@ -2117,14 +2117,14 @@ cycle}
\begin{scope}[yshift=5em,xshift=1.5in] \begin{scope}[yshift=5em,xshift=1.5in]
\visible<2->{ \visible<2->{
\draw[step=0.5cm,thick] (-0.5,-1) grid (0.5,1.0); \draw[step=0.5cm,thick] (-0.5,-1) grid (0.5,1.0);
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,0.75) {-1}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,0.75) {\small{$-1$}};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,0.25) {0}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,0.25) {$0$};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,-0.25) {1}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,-0.25) {$1$};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,-0.75) {0}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (-0.25,-0.75) {$0$};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,0.75) {0}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,0.75) {$0$};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,0.25) {-1}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,0.25) {\small{$-1$}};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,-0.25) {1}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,-0.25) {$1$};
\node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,-0.75) {0}; \node [fill=black!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (0.25,-0.75) {$0$};
\node [anchor=north] (xlabel) at (0,-1.2) {$\textbf{w}$}; \node [anchor=north] (xlabel) at (0,-1.2) {$\textbf{w}$};
} }
...@@ -2140,7 +2140,7 @@ cycle} ...@@ -2140,7 +2140,7 @@ cycle}
\foreach \y in {+0.75,+0.25,-0.25,-0.75}{ \foreach \y in {+0.75,+0.25,-0.25,-0.75}{
\setcounter{mycount1}{2} \setcounter{mycount1}{2}
\foreach \x in {-0.25,0.25}{ \foreach \x in {-0.25,0.25}{
\node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{-1}; \addtocounter{mycount1}{-1};
} }
} }
...@@ -2153,7 +2153,7 @@ cycle} ...@@ -2153,7 +2153,7 @@ cycle}
\foreach \y in {+0.75,+0.25,-0.25,-0.75}{ \foreach \y in {+0.75,+0.25,-0.25,-0.75}{
\setcounter{mycount1}{2} \setcounter{mycount1}{2}
\foreach \x in {-0.25,0.25}{ \foreach \x in {-0.25,0.25}{
\node [fill=blue!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=blue!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{-1}; \addtocounter{mycount1}{-1};
} }
} }
...@@ -2166,7 +2166,7 @@ cycle} ...@@ -2166,7 +2166,7 @@ cycle}
\foreach \y in {+0.75,+0.25,-0.25,-0.75}{ \foreach \y in {+0.75,+0.25,-0.25,-0.75}{
\setcounter{mycount1}{2} \setcounter{mycount1}{2}
\foreach \x in {-0.25,0.25}{ \foreach \x in {-0.25,0.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{-1}; \addtocounter{mycount1}{-1};
} }
} }
...@@ -2179,7 +2179,7 @@ cycle} ...@@ -2179,7 +2179,7 @@ cycle}
\foreach \y in {+0.75,+0.25,-0.25,-0.75}{ \foreach \y in {+0.75,+0.25,-0.25,-0.75}{
\setcounter{mycount1}{2} \setcounter{mycount1}{2}
\foreach \x in {-0.25,0.25}{ \foreach \x in {-0.25,0.25}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{-1}; \addtocounter{mycount1}{-1};
} }
} }
...@@ -2200,15 +2200,14 @@ cycle} ...@@ -2200,15 +2200,14 @@ cycle}
%%% 张量的单元操作 %%% 张量的单元操作
\begin{frame}{张量的单元操作} \begin{frame}{张量的单元操作}
\begin{itemize} \begin{itemize}
\item 神经网络$\textbf{y}=f(\textbf{x}\cdot \textbf{w} + \textbf{b})$也包括一些张量的单元操作(element-wise opertation) \item 神经网络$\textbf{y}=f(\textbf{x}\cdot \textbf{w} + \textbf{b})$也包括一些张量的单元操作(element-wise operation)
\begin{itemize} \begin{itemize}
\item 加法:$\textbf{s}+\textbf{b}$,其中$\textbf{s} = \textbf{x}\cdot \textbf{w}$ \item 加法:$\textbf{s}+\textbf{b}$,其中$\textbf{s} = \textbf{x}\cdot \textbf{w}$
\item 激活函数:$f(\cdot)$ \item 激活函数:$f(\cdot)$
\end{itemize} \end{itemize}
\item<2-> \textbf{单元加}就是对张量中的每个位置都进行加法 \item<2-> \textbf{单元加}就是对张量中的每个位置都进行加法
\begin{itemize} \begin{itemize}
\item 一般要求两个张量的形状是一样的 \item<3-> 扩展:加法的\textbf{广播},重复利用一个张量进行加法,并不要求两个张量形状相同
\item<3-> 不过,这里可以使用加法的\textbf{广播},重复利用一个张量进行加法,并不要求两个张量形状相同
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
...@@ -2221,7 +2220,7 @@ cycle} ...@@ -2221,7 +2220,7 @@ cycle}
\draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5); \draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5);
\foreach \y in {+0.25,-0.25} \foreach \y in {+0.25,-0.25}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{1}; \addtocounter{mycount1}{1};
} }
\node [anchor=south] (varlabel) at (0,0.6) {$\textbf{s}$}; \node [anchor=south] (varlabel) at (0,0.6) {$\textbf{s}$};
...@@ -2231,7 +2230,7 @@ cycle} ...@@ -2231,7 +2230,7 @@ cycle}
\draw[step=0.5cm,color=ugreen,thick] (-1,-0) grid (1,0.5); \draw[step=0.5cm,color=ugreen,thick] (-1,-0) grid (1,0.5);
\foreach \y in {+0.25} \foreach \y in {+0.25}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {1}; \node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$1$};
\addtocounter{mycount1}{1}; \addtocounter{mycount1}{1};
} }
\node [anchor=center] (plabel) at (-4.5em,0) {\huge{$\textbf{+}$}}; \node [anchor=center] (plabel) at (-4.5em,0) {\huge{$\textbf{+}$}};
...@@ -2242,7 +2241,7 @@ cycle} ...@@ -2242,7 +2241,7 @@ cycle}
\draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5); \draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5);
\foreach \y in {+0.25,-0.25} \foreach \y in {+0.25,-0.25}
\foreach \x in {-0.75,-0.25,0.25,0.75}{ \foreach \x in {-0.75,-0.25,0.25,0.75}{
\node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount1}}; \node [fill=orange!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {$\number\value{mycount1}$};
\addtocounter{mycount1}{1}; \addtocounter{mycount1}{1};
} }
\node [anchor=center] (plabel) at (-4.5em,0) {\huge{$\textbf{=}$}}; \node [anchor=center] (plabel) at (-4.5em,0) {\huge{$\textbf{=}$}};
...@@ -2253,25 +2252,34 @@ cycle} ...@@ -2253,25 +2252,34 @@ cycle}
\end{tikzpicture} \end{tikzpicture}
\end{center} \end{center}
\vspace{-0.3em}
\begin{itemize} \begin{itemize}
\item<4-> 类似的,我们可以对所有位置做加法、乘法等等一系列算数操作,也包括激活函数 \item<4-> 类似的,我们可以做减法、乘法,也包括激活函数。这也被称作函数的向量化(vectorization)
\end{itemize} \end{itemize}
\vspace{-0.5em}
\visible<4->{
\begin{displaymath}
\textrm{Relu} \Big( \begin{pmatrix} 2 \\ -.3 \end{pmatrix} \Big) = \begin{pmatrix} 2 \\ 0 \end{pmatrix}
\end{displaymath}
}
\end{frame} \end{frame}
%%%------------------------------------------------------------------------------------------------------------ %%%------------------------------------------------------------------------------------------------------------
%%% 深度学习工具包 %%% 深度学习工具包
\begin{frame}{如何实现?- 开源张量计算框架} \begin{frame}{如何实现?- 开源张量计算框架}
\begin{itemize} \begin{itemize}
\item 实现神经网络的开源系统很多,最简单好用的一个工具包NumPy \url{https://numpy.org/} \item 实现神经网络的开源系统很多,一个简单好用的工具包NumPy \url{https://numpy.org/}
\begin{itemize} \begin{itemize}
\item Python接口,多维数组的定义使用方便 \item Python接口,多维数组的定义使用方便
\item 提供了张量表示和使用的范式 \item 提供了张量表示和使用的范式
\end{itemize} \end{itemize}
\item<2-> 最近,很火的两个框架:TensorFlow和Pytorch \item<2-> 最近,很火的两个框架:TensorFlow和PyTorch
\begin{itemize} \begin{itemize}
\item Google和Facebook出品,质量有保证 \item Google和Facebook出品,质量有保证
\item 功能强大,用例丰富 \item 功能强大,接口丰富
\item 可以进行大规模部署和应用 \item 可以进行大规模部署和应用
\item 大量可参考的实例 \item 大量可参考的实例
\end{itemize} \end{itemize}
...@@ -2700,5 +2708,61 @@ cycle} ...@@ -2700,5 +2708,61 @@ cycle}
\end{frame} \end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 神经网络 = 表达式
\begin{frame}{神经网络 = 表达式}
\begin{itemize}
\item 所有的神经网络都可以看做由变量和函数组成的表达式\\
\end{itemize}
\begin{center}
\begin{tikzpicture}
\node [anchor=north west] (eq1) at (0,0) {$\textbf{y} = \textbf{x} + \textbf{b}$};
\node [anchor=north west] (eq2) at (eq1.south west) {$\textbf{y} = \textrm{Relu}(\textbf{x} \cdot \textbf{w} + \textbf{b})$};
\node [anchor=north west] (eq3) at (eq2.south west) {$\textbf{y} = (\textrm{Relu}(\textbf{x} \cdot \textbf{w}_1 + \textbf{b}) + \textbf{x}) \cdot \textbf{w}_2$};
\node [anchor=north west] (eq4) at (eq3.south west) {$\textbf{y} = \textrm{Sigmoid}(\textrm{Relu}(\textbf{x} \cdot \textbf{w}_1 + \textbf{b}_1) + \textbf{x}) \cdot \textbf{w}_2 + \textbf{b}_2$};
\visible<2->{
\node [anchor=north west,minimum height=1.2em,minimum width=1.2em,fill=green!30!white] (xlabel) at ([yshift=-0.5em,xshift=0.3em]eq4.south west) {};
\node [anchor=west] (xlabel2) at (xlabel.east) {输入变量 - 由用户指定};
}
\begin{pgfonlayer}{background}
\visible<2->{
\node [anchor=south, minimum height=1.6em,minimum width=0.8em,fill=green!30!white] (x1) at ([xshift=-1.3em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=0.8em,fill=green!30!white] (x2) at ([xshift=4.9em]eq4.south) {};
}
\end{pgfonlayer}
\visible<3->{
\node [anchor=north west,minimum height=1.2em,minimum width=1.2em,fill=red!30!white] (wlabel) at ([yshift=-0.3em]xlabel.south west) {};
\node [anchor=west] (wlabel2) at (wlabel.east) {模型参数 - 怎么设置???};
}
\begin{pgfonlayer}{background}
\visible<3->{
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (w1) at ([xshift=0.2em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (b1) at ([xshift=2.5em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (w2) at ([xshift=6.85em]eq4.south) {};
\node [anchor=south, minimum height=1.6em,minimum width=1.2em,fill=red!30!white] (b2) at ([xshift=9.2em]eq4.south) {};
}
\end{pgfonlayer}
\end{tikzpicture}
\end{center}
\visible<4->{
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=blue!5!white,colframe=blue!75!black,drop fuzzy shadow]
{\Large
\textbf{问题来了,}
\vspace{0.4em}
\textbf{如何确定w和b,使x与y对应得更好?}
}
\end{tcolorbox}
}
\end{frame}
\end{CJK} \end{CJK}
\end{document} \end{document}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论