Commit b3ffcd6e by xiaotong

new update

parent ca239bf0
......@@ -20,6 +20,9 @@
\usepackage{subfigure}
\usepackage{tikz-3dplot}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows,decorations.pathreplacing}
\usetikzlibrary{shadows} % LATEX and plain TEX when using Tik Z
......@@ -111,70 +114,34 @@
\newcounter{mycount3}
\newcounter{mycount4}
%%%------------------------------------------------------------------------------------------------------------
%%% 张量的单元操作
\begin{frame}{张量的单元操作}
%%% 定义XTensor
\begin{frame}{定义XTensor}
\begin{itemize}
\item 神经网络$\textbf{y}=f(\textbf{x}\cdot \textbf{w} + \textbf{b})$也包括一些张量的单元操作(element-wise opertation)
\begin{itemize}
\item 加法:$\textbf{s}+\textbf{b}$,其中$\textbf{s} = \textbf{x}\cdot \textbf{w}$
\item 激活函数:$f(\cdot)$
\end{itemize}
\item<2-> \textbf{单元加}就是对张量中的每个位置都进行加法
\begin{itemize}
\item 一般要求两个张量的形状是一样的
\item<3-> 不过,这里可以使用加法的\textbf{广播},重复利用一个张量进行加法,并不要求两个张量形状相同
\end{itemize}
\item NiuTensor张量由类XTensor定义
\begin{itemize}
\item \textbf{必须指定}:张量的阶和各个方向维度的大小,关于维度的约定和传统多维数组一样
\item \textbf{可以指定}:张量数据类型、稠密程度等等
\end{itemize}
\end{itemize}
\vspace{-1.5em}
\begin{center}
\begin{tikzpicture}
\visible<3->{
\begin{scope}
\setcounter{mycount1}{1}
\draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5);
\foreach \y in {+0.25,-0.25}
\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}};
\addtocounter{mycount1}{1};
}
\node [anchor=south] (varlabel) at (0,0.6) {$\textbf{s}$};
\end{scope}
\begin{scope}[xshift=1.5in]
\setcounter{mycount1}{1}
\draw[step=0.5cm,color=ugreen,thick] (-1,-0) grid (1,0.5);
\foreach \y in {+0.25}
\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};
\addtocounter{mycount1}{1};
}
\node [anchor=center] (plabel) at (-4.5em,0) {\huge{\textbf{$+$}}};
\node [anchor=south] (varlabel) at (0,0.6) {$\textbf{b}$};
\end{scope}
\begin{scope}[xshift=3in]
\setcounter{mycount1}{2}
\draw[step=0.5cm,color=orange,thick] (-1,-0.5) grid (1,0.5);
\foreach \y in {+0.25,-0.25}
\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}};
\addtocounter{mycount1}{1};
}
\node [anchor=center] (plabel) at (-4.5em,0) {\huge{\textbf{$=$}}};
\node [anchor=south] (varlabel) at (0,0.6) {$\textbf{s+b}$};
\end{scope}
}
\begin{tcolorbox}[enhanced,frame engine=empty,boxrule=0.1mm,size=title,colback=blue!10!white]
\begin{flushleft}
{\scriptsize
\begin{tabbing}
\end{tikzpicture}
\end{center}
\texttt{XTensor tensor;} \hspace{12em} \= // 声明张量tensor \\
\texttt{int sizes[3] = \{2,3,4\};} \> // 张量的形状为2*3*4 \\
\begin{itemize}
\item<4-> 类似的,我们可以对所有位置做加法、乘法等等一系列算数操作,也包括激活函数
\end{itemize}
\texttt{InitTensor(\&tensor, 3, sizes, X\_FLOAT);} \> // 定义形状为sizes的三阶张量
\end{tabbing}
}
\end{flushleft}
\end{tcolorbox}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
\subsection{参数学习 - 反向传播}
......
......@@ -20,6 +20,9 @@
\usepackage{subfigure}
\usepackage{tikz-3dplot}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows,decorations.pathreplacing}
\usetikzlibrary{shadows} % LATEX and plain TEX when using Tik Z
......@@ -61,6 +64,10 @@
%\usetheme{Boadilla}
%\usecolortheme{dolphin}
\newcounter{mycount1}
\newcounter{mycount2}
\newcounter{mycount3}
\newcounter{mycount4}
\usefonttheme[onlylarge]{structurebold}
......@@ -681,27 +688,70 @@ GPT-2 (Transformer) & Radford et al. & 2019 & \alert{35.7}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
\subsection{人工神经元}
%%%------------------------------------------------------------------------------------------------------------
%%% outline
\begin{frame}{入门神经网络(深度学习)的三个基本问题}
\begin{frame}{入门人工神经网络(深度学习)的三个基本问题}
\begin{center}
\begin{tikzpicture}
\vspace{1em}
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\node [anchor=west,draw,ublue,very thick,rounded corners=4pt,text width=18em,align=left,fill=white,drop shadow={shadow xshift=0.2em,shadow yshift=-0.2em}] (p1) at (0,0) {\black{\textbf{1. 人工神经网络的数学描述是什么,}}\\\black{\textbf{\hspace{0.9em} 如何实现这种数学模型?}}};
\textbf{1. 人工神经网络的基本单元是什么,}
\node [anchor=north west,draw,ublue,very thick,rounded corners=4pt,text width=18em,align=left,fill=white,drop shadow={shadow xshift=0.2em,shadow yshift=-0.2em}] (p21) at ([yshift=-1em]p1.south west) {\black{\textbf{2. 如何将简单的网络单元组合成更}}\\\black{\textbf{\hspace{0.9em} 强大的模型?}}};
\vspace{0.4em}
\textbf{\hspace{0.9em} 如何组合出更强大的模型?}
}
\end{tcolorbox}
\vspace{0.5em}
\node [anchor=north west,draw,ublue,very thick,rounded corners=4pt,text width=18em,align=left,fill=white,drop shadow={shadow xshift=0.2em,shadow yshift=-0.2em}] (p22) at ([yshift=-1em]p21.south west) {\black{\textbf{3. 如何对模型中的参数进行学习,}}\\\black{\textbf{\hspace{0.9em} 之后使用学习到的模型进行推断?}}};
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\textbf{2. 人工神经网络的数学描述是什么,}
\vspace{0.4em}
\textbf{\hspace{0.9em} 如何编程实现这种数学模型?}
}
\end{tcolorbox}
\end{tikzpicture}
\end{center}
\vspace{0.5em}
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\textbf{3. 如何对模型中的参数进行学习,}
\vspace{0.4em}
\textbf{\hspace{0.9em} 之后使用学习到的模型进行推断?}
}
\end{tcolorbox}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
\subsection{人工神经元}
%%% outline: problem 1
\begin{frame}{首先}
\vspace{6em}
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\textbf{人工神经网络的基本单元是什么,}
\vspace{0.4em}
\textbf{如何组合出更强大的模型?}
}
\end{tcolorbox}
\vspace{2em}
\begin{center}
\begin{tikzpicture}
\node [fill=blue!10] (label) at (0,0) {\Large{$\textbf{y} = ?(\textbf{x})$ }};
\end{tikzpicture}
\end{center}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 人工神经元的函数形式
......@@ -1600,6 +1650,67 @@ cycle}
\subsection{神经网络的简单实现:张量计算}
%%%------------------------------------------------------------------------------------------------------------
%%% outline: problem 2
\begin{frame}{然后}
\vspace{6em}
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\textbf{人工神经网络的数学描述是什么,}
\vspace{0.4em}
\textbf{如何编程实现这种数学模型?}
}
\end{tcolorbox}
\vspace{1em}
\begin{center}
\begin{tikzpicture}
\begin{scope}[yshift=6.5em,xshift=1em]
\setcounter{mycount1}{1}
\draw[step=0.5cm,color=orange,thick] (-1,-1) grid (0.5,0.5);
\foreach \y in {+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-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}};
\addtocounter{mycount1}{1};
}
\end{scope}
\begin{scope}[yshift=6em,xshift=0.5em]
\setcounter{mycount2}{2}
\draw[step=0.5cm,color=blue,thick] (-1,-1) grid (0.5,0.5);
\foreach \y in {+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25}{
\node [fill=blue!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount2}};
\addtocounter{mycount2}{1};
}
\end{scope}
\begin{scope}[yshift=5.5em,xshift=0em]
\setcounter{mycount3}{3}
\draw[step=0.5cm,color=ugreen,thick] (-1,-1) grid (0.5,0.5);
\foreach \y in {+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25}{
\node [fill=green!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount3}};
\addtocounter{mycount3}{1};
}
\end{scope}
\begin{scope}[yshift=5em,xshift=-0.5em]
\setcounter{mycount4}{4}
\draw[step=0.5cm,color=red,thick] (-1,-1) grid (0.5,0.5);
\foreach \y in {+0.25,-0.25,-0.75}
\foreach \x in {-0.75,-0.25,0.25}{
\node [fill=red!20,inner sep=0pt,minimum height=0.49cm,minimum width=0.49cm] at (\x,\y) {\number\value{mycount4}};
\addtocounter{mycount4}{1};
}
\end{scope}
\end{tikzpicture}
\end{center}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 张量
\begin{frame}{如何描述神经网络 - 张量计算}
\begin{itemize}
......@@ -1658,11 +1769,6 @@ cycle}
\end{frame}
\newcounter{mycount1}
\newcounter{mycount2}
\newcounter{mycount3}
\newcounter{mycount4}
%%%------------------------------------------------------------------------------------------------------------
%%% 张量的简单定义
\begin{frame}{张量是什么}
......@@ -1958,7 +2064,6 @@ cycle}
\begin{center}
\begin{tikzpicture}
\begin{scope}[yshift=6.5em,xshift=1em]
\visible<2->{
\setcounter{mycount1}{1}
......@@ -2154,7 +2259,127 @@ cycle}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 深度学习工具包
\begin{frame}{如何实现?- 开源张量计算框架}
\begin{itemize}
\item 实现神经网络的开源系统很多,最简单好用的一个工具包NumPy \url{https://numpy.org/}
\begin{itemize}
\item Python接口,多维数组的定义使用方便
\item 提供了张量表示和使用的范式
\end{itemize}
\item<2-> 最近,很火的两个框架:TensorFlow和Pytorch
\begin{itemize}
\item Google和Facebook出品,质量有保证
\item 功能强大,用例丰富
\item 可以进行大规模部署和应用
\item 大量可参考的实例
\end{itemize}
\includegraphics[scale=0.13]{./Figures/tensorflowpytorch.jpg}
\item<3-> 还有其它还在更新的优秀框架: CNTK、MXNet、PaddlePaddle、Keras、Chainer、 dl4j、NiuTensor等
\end{itemize}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% NiuTrans.Tensor工具包
\begin{frame}{NiuTensor}
\begin{itemize}
\item 这里使用我们自研的NiuTensor工具包进行教学 \url{http://www.niutrans.com/opensource/niutensor/index.html}
\begin{itemize}
\item 简单小巧,易于修改
\item C++语言编写,代码高度优化
\item 同时支持CPU和GPU设备
\item 丰富的张量计算接口
\end{itemize}
\end{itemize}
\includegraphics[scale=0.35]{./Figures/niutensor.jpg}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 使用NiuTensor
\begin{frame}{使用NiuTensor}
\begin{itemize}
\item NiuTensor的使用很简单,下面是一个C++例子
\end{itemize}
\begin{tcolorbox}[enhanced,frame engine=empty,boxrule=0.1mm,size=title,colback=blue!10!white]
\begin{flushleft}
{\scriptsize
\begin{tabbing}
\texttt{\#include "source/tensor/XTensor.h"} \hspace{4em} \= // 引用XTensor定义的头文件 \\
\texttt{using namespace nts;} \> // 引用nts命名空间 \\
\ \\
\texttt{int main(int argc, const char ** argv)\{} \\
\ \ \ \ \texttt{XTensor tensor;} \> // 声明张量tensor \\
\ \ \ \ \texttt{InitTensor2D(\&tensor, 2, 2, X\_FLOAT);} \> // 定义张量为2*2的矩阵 \\
\ \ \ \ \texttt{tensor.SetDataRand();} \> // 用[0,1]的均匀分布初始化张量 \\
\ \ \ \ \texttt{tensor.Dump(stdout);} \> // 输出张量内容 \\
\ \ \ \ \texttt{return 0;}\\
\texttt{\}}
\end{tabbing}
}
\end{flushleft}
\end{tcolorbox}
\begin{itemize}
\item<2-> 运行这个程序会看到张量每个元素的值
\end{itemize}
\visible<2->{
\begin{tcolorbox}[enhanced,frame engine=empty,boxrule=0.1mm,size=title,colback=black!10!white]
\begin{flushleft}
{\scriptsize
\begin{tabbing}
\texttt{order=2 dimsize=2,2 dtype=X\_FLOAT dense=1.000000} \\
\texttt{3.605762e-001 2.992340e-001 1.393780e-001 7.301248e-001}
\end{tabbing}
}
\end{flushleft}
\end{tcolorbox}
}
\vspace{-0.5em}
\begin{itemize}
\item<2-> 还可以看到:二阶张量(order=2),形状是$2 \times 2$ (dimsize=2,2),数据类型是单精度浮点(dtype=X\_FLOAT),是一个非稀疏张量(dense=1.000)
\end{itemize}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
\subsection{参数学习 - 反向传播}
%%%------------------------------------------------------------------------------------------------------------
%%% outline: problem 3
\begin{frame}{还有一个问题}
\vspace{6em}
\begin{tcolorbox}[enhanced,size=normal,left=2mm,right=1mm,colback=red!5!white,colframe=red!75!black,drop fuzzy shadow]
{\Large
\textbf{如何对模型中的参数进行学习,}
\vspace{0.4em}
\textbf{之后使用学习到的模型进行推断?}
}
\end{tcolorbox}
\vspace{2em}
\begin{center}
\begin{tikzpicture}
\node [fill=blue!10] (label) at (0,0) {\LARGE{$\frac{\partial \textbf{E}}{\partial \textbf{w}} = $ ? }};
\end{tikzpicture}
\end{center}
\end{frame}
\end{CJK}
\end{document}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论