深度学习入门

深度学习入门

Three Steps for Deep Learning

Step1: Define a set of function(Neural Network)

Step2: goodness of function

Step3: pick the best function

Define a set of function(Neural Network)

Deep Learning 的关键、难点就是在于定义 Neural network structure。

function set:

  • 就是所谓的 model.

  • Including all different w and b.

  • 可能包含无穷个函数.

Fully Connect Feedforward Network

Neural network structure 的一种

Deep = Many hidden layers.

FAQ
  • Q: How many layers? How many neurons for each layer?

    神经网路的层数以及神经元的数目是由尝试得到的(Trial and Error + Intuition)

  • Q: Can the structure be automatically determined?

    神经网络的结构可以被自动定义 E.g. Evolutionary Artificial Neural Networks

  • Q: Can we design the network structure?

    可以自定义神经网络的结构,上图展示的为 Fully Connect Feedforward Network ,另外还有 Convolutional Neural Network (CNN) 等等。

goodness of function

通过 Total Loss 来判断这个 function 的好坏

以十分类问题为例(以 Cross Entropy(交叉熵)定义 Loss 函数):

Loss for an Example

请添加图片描述

Total Loss - Loss Function

所有 Examples 的交叉熵的和。

Loss Function:

  • function 的 function

  • Input: a function

  • output: how bad it is

在这里插入图片描述

目的:

  • Find a function in function set that minimizes total loss L.

  • Find the network parameters 𝜽 that minimize total loss L.

pick the best function

如何减小 Total Loss ,使用的方法就是Gradient Descent

1. Compute Gradient.

在这里插入图片描述

2. Gradient Descent

𝑤i − 𝜇 * 𝜕L / 𝜕𝑤i ,bi − 𝜇 * 𝜕L / 𝜕bi

𝜇 是 Learning rate 学习速率。

在这里插入图片描述

  • Even alpha go using this approach(Gradient Descent).

  • 计算梯度的方法 Backpropagation。

Backpropagation

To compute the gradients efficiently, we use backpropagation(反向传播).

原理

通过链式法则,将Cross Entropy 函数对参数的偏微分转化成以 sigmoid(以sigmoid函数为例)的输入 z 为中介的偏微分式,在这里插入图片描述

  • 𝜕𝑧 / 𝜕𝑤 利用 Forward Pass 来计算
  • 𝜕C / 𝜕z 利用 Backward Pass 来计算

在这里插入图片描述

Forward Pass

Compute 𝜕𝑧 / 𝜕𝑤 for all parameters.

𝜕𝑧 / 𝜕𝑤 = The value of the input connected by the weight.

z 的函数式是用 xi 与 wi 线性表示的,因此 𝜕𝑧 / 𝜕𝑤 的值即为 input x。

Backward Pass

Compute 𝜕𝐶 / 𝜕𝑧 for all activation function inputs z.

在这里插入图片描述

依然通过链式法则将 𝜕𝐶 / 𝜕𝑧 进行转换。
在这里插入图片描述

计算 𝜕a / 𝜕𝑧

这里 𝜕a / 𝜕𝑧 相当于是一个常数,因为 a 是 z 带入 sigmoid 函数中求出的,可直接对 sigmoid 函数求导。

计算 𝜕C / 𝜕a

𝜕C / 𝜕a 再次利用 链式法则 通过下一层 layer 表示

在这里插入图片描述

Case1.output layer
在这里插入图片描述

当 𝜕C / 𝜕a 的下一层就是 output layer 时,𝜕C / 𝜕y 是容易求出的,depend on cost function 是怎样定义的(例如:MSE、Cross-entropy)。

Case2.Not Output Layer

Compute 𝜕𝐶 / 𝜕𝑧 recursively, Until we reach the output layer.

当 𝜕C / 𝜕a 的下一层就是 output layer 时,就可以通过逐层递归求出前面的 𝜕C / 𝜕a 的值。

即为下图所示反向传播的过程(逐层求前面的 𝜕C / 𝜕a ):

在这里插入图片描述

Summary

在这里插入图片描述

Regression

Regression: Output a scalar.

预测神奇宝贝升级后的CP值 为例。

Step 1: Model

y = b + w ∙ x

将一般的线性回归中加入 神奇宝贝的种类 这一定类变量,来优化预测结果。
在这里插入图片描述
在这里插入图片描述

Step 2: Goodness of Function

对每个参数随机选取初始值,之后做 Gradient Descent。

注:

  • 单参数时:Regression 上没有 Local minimum.

  • 双参数时:In linear regression, the loss function L is convex(凸面的) , 即 No local optimal.

  • 所以不用担心,参数初始值选取的不同对 Gradient Descent 结果的影响。

Regularization(规则化)

根据一般的结果:We believe smoother function is more likely to be correct。

在这里插入图片描述

  • 不断调整 λ 的值,得出最优的 model。

  • 在做 Regularization 的时候,是不需要考虑 bias 这一项的。因为 bias 这一项对函数的平滑程度没有影响。

Step 3: pick the best function

只要 L 是可微分的,Gradient Descent 就可以帮助找到比较好的 function 或者是 参数。

Classification: Probabilistic Generative Model

分类神奇宝贝(概率模型)

Model
  1. 假设只有两个用于分类的 feature,可以将这两个 feature 在二维平面中做图出来。
  2. 确定这些点的 probability distribution
  3. Assume the points are sampled from a Gaussian distribution.
Gaussian distribution

  • Input: vector x, output: probability of sampling x

  • The shape of the function determines by mean 𝝁 and covariance matrix 𝜮

The Gaussian with any mean 𝜇 and covariance matrix 𝛴 can generate these points. 只是 Different Likelihood 罢了,因此如何确定 𝜇(均值) 与 𝛴(相关系数矩阵),使得 Likelihood 最大?公式如下:

在这里插入图片描述
在这里插入图片描述

因此 Model 可以确定如下:
在这里插入图片描述

P ( 𝑥|C1 ) = 在这里插入图片描述

P ( 𝑥|C2 ) = 在这里插入图片描述

P ( C1 ) = 数据集中 C1类别的个数 / 数据集总个数

P ( C2 ) = 数据集中 C2类别的个数 / 数据集总个数

Modifying Model —— 组合 Σ

训练效果不佳时,可以将两个 feature 使用 The same Σ(𝜇 保持不变),从而得到 Less parameters 的模型,从而减少由于 parameters 过多引起的过拟合 accuracy 较低得问题。

Σ = 数据集中 C2类别的个数 / 数据集总个数 · Σ1 + 数据集中 C2类别的个数 / 数据集总个数 · Σ2

  • 当两个 feature 共用一个 covariance matrix 时,得到的分类 boundary is linear, 因此我们也把这个 model 成为 linear 的 model。

  • 如果两个 feature 之间共用了 covariance matrix Σ,也就是说他俩之间是有关系的(比如说是正相关的)。

Probability distribution 的其他说明
  • 1-D Guassian 的 covariance matrix 是 diagonal 的(对角线的),也即只有对角线上的元素有值,其他地方的元素都是0,从而减少需要用的参数量。

  • If you assume all the dimensions are independent, then you are using **Naive Bayes Classifier.**这时使用模型会预测出很好的结果。
    在这里插入图片描述

  • For binary features, you may assume they are from Bernoulli distributions.

Classification: Logistic Regression

  • Logistic Regression 二分类的 boundary 就是一条直线。

模型的推导

Posterior Probability

在这里插入图片描述

代入公式可得:

在这里插入图片描述
在这里插入图片描述

𝑃( 𝐶1|𝑥 ) = 𝜎( 𝑧 ) = 𝜎( 𝑤 ∙ 𝑥 + 𝑏 )

Logistic Regression 做法是 directly find 𝑤 and 𝑏

Step 1: Function Set

Function set: Including all different w and b

Step 2: Goodness of a Function

Assume the data is generated based on 𝑓𝑤,𝑏( 𝑥 ) = 𝑃𝑤,𝑏( 𝐶1|𝑥 )

在这里插入图片描述

The most likely w* and b* is the one with the largest 𝐿( 𝑤, 𝑏 ).

在这里插入图片描述

−𝑙𝑛𝐿( 𝑤, 𝑏 ) =

注:Logistic Regression 使用 Cross Entropy 来定义 Loss 函数,不能用 Square Error 来定义 Loss 函数。

Cross Entropy v.s. Square Error(如下图):

Cross Entropy:距离目标越远,微分值就越大,参数 update 的速度就越快

Square Error:距离目标很远时,微分值是很小,导致移动的速度非常慢,使得 training 非常卡,很难训练出好的结果。

Limitation of Logistic Regression

有些数据集很难使用线性的分隔。

但是通过将数据集中的数据经过多次 sigmoid 变换之后,也即经过多次的 Logistic Regression,就可以有效的进行分割,我们将每一个 Logistic Regression 称作 neural,把这些 Logistic Regression 串起来组成的 network 就叫做 Neural Network,这就是 Deep Learning

两种 Classification 对比总结

在这里插入图片描述

Discriminative v.s. Generative

Discriminative 的方法:Logistic Regression

Generative 的方法:用 Gussian(或其他 probability distribution )来描述 posterior probability

两种方法找出来的 w 和 b 是不同的

两种模型的优势
  • Discriminative:文献上常常会说 Discriminative 的 model 比 Generative 的 model performance 更好。

  • Generative model:会做一些脑补( assumption of probability distribution ),可能得到的实际预测结果和人类的直觉不一样。因此 Generative model 的优势就是 在 data 数据量比较少的时候,或是数据集有 noise 时,Generative model 预测的结果有时是比 Discriminative model 要好的,因为 Discriminative model 只看着数据说话。

两种模型的区别
  • Discriminative 的方法:直接假设了一个 posterior probability ,然后去找 posterior probability 里面的参数。
  • Generative 的方法:把整个 formulation 里面拆成 prior、class-dependent 的 probability 这两项(因此 prior、class-dependent 可以来自于不同的来源)。

整个语音辨识的系统(model)是一个 Generative 的系统,Discriminative(Neural Network)只是其中一部分而已)

Multi-class Classification —— Softmax

对最大值做强化,通过取ex(exponential),将最大值与最小值之间的差距拉的更开。同时使最终结果均介于 0~1之间,且加和为1.

三分类为例:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Uncle Tan_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值