斯坦福深度学习CS230课程cheatsheet学后总结笔记(2)
文章目录
FACE VERIFICATION AND RECOGNITION
模型类别-两种主要模型
- 人脸验证
- 人脸识别
One Shot learning
人脸验证算法,学习一个简单函数,其可以量化两张图像的而不同,常表示为 d ( i m a 1 , i m a 2 ) d(ima1,ima2) d(ima1,ima2)
Siamese Network
编码图像然后量化两张图像的不同,给定输入 x ( i ) x^{(i)} x(i),输出 f ( x ( i ) ) f(x^{(i)}) f(x(i))
Triplet(三个一组) loss
计算图像A(锚),P(positive),N(negative)三个一组的嵌入表示,锚和positive example属于同一类,negative example属于另一类。
α
∈
R
+
\alpha \in \mathbb{R^+}
α∈R+为参数容限,损失定义如下:
ℓ
(
A
,
P
,
N
)
=
m
a
x
(
d
(
A
,
P
)
−
d
(
A
,
N
)
+
α
,
0
)
\ell(A,P,N) = max(d(A,P)-d(A,N)+\alpha,0)
ℓ(A,P,N)=max(d(A,P)−d(A,N)+α,0)
Neural style transfer
目的
将主图像C通过一个给定的风格S变换成生成图像G(类似于加滤镜?)
激活值
第 l l l层,激活值为 a [ l ] a^{[l]} a[l],通常维度为 n H × n w × n c n_H \times n_w \times n_c nH×nw×nc
Content cost function
用来定义生成图像G与原始图像C的不同,如下:
J
c
o
n
t
e
n
t
(
C
,
G
)
=
1
2
∥
a
[
l
]
(
C
)
−
a
[
l
]
(
G
)
∥
2
J_{content}(C,G) = \frac{1}{2}\|a^{[l](C)}-a^{[l](G)}\|^2
Jcontent(C,G)=21∥a[l](C)−a[l](G)∥2
Style matrix
量化通道k和通道k‘的相关性,定义如下:
G
k
k
′
[
l
]
=
∑
i
=
1
n
H
[
l
]
∑
j
=
1
n
w
[
l
]
a
i
j
k
[
l
]
a
i
j
k
′
[
l
]
G^{[l]}_{kk'} = \sum_{i=1}^{n^{[l]}_H} \sum_{j=1}^{n^{[l]}_w}a^{[l]}_{ijk}a^{[l]}_{ijk'}
Gkk′[l]=i=1∑nH[l]j=1∑nw[l]aijk[l]aijk′[l]
有分别对应S和G的风格矩阵
Overall cost function
以上两个损失函数的结合,权重系数
α
,
β
\alpha,\beta
α,β,如下:
J
(
G
)
=
α
J
c
o
n
t
e
n
t
(
C
,
G
)
+
β
J
s
t
y
l
e
(
S
,
G
)
J(G) = \alpha J_{content}(C,G)+\beta J_{style}(S,G)
J(G)=αJcontent(C,G)+βJstyle(S,G)
Architecture using computational tricks
生成式对抗网络
GANs,由一个生成模型和一个鉴别模型组成,生成模型目的在于生成最可信的输出,然后将其送到鉴别模型中区分处生成的图像和真实图像。
Resnet
residual network
使用大量层和剩余blocks减少训练误差,特征方程:
a
[
l
+
2
]
=
g
(
a
[
l
]
+
z
[
l
+
2
]
)
a^{[l+2]} = g(a^{[l]}+z^{[l+2]})
a[l+2]=g(a[l]+z[l+2])
Inception Network
尝试不同的卷积层以提升性能。特殊地,使用 1 × 1 1 \times 1 1×1的卷积来降低计算复杂度
Recurrent(周期性的) Neural Network
传统RNN的架构
允许之前的输出继续作为输入
优点:
- 可处理任何输入长度
- 模型大小不随输入大小变化
- 计算考虑
- 权值共享
缺点:
- 计算变慢
- 难以获得很长时间之前的信息
- 不能在当前状态下考虑未来的输入
RNN的应用
自然语言处理,语音识别,各种应用类别(输入-to-输出)如下
type of RNN | Example |
---|---|
one-to-one | 传统神经网络 |
one-to-many | 音乐生成 |
many-to-one | 情感分类 |
many-to-many | 实体名字识别 |
many-to-many | 机器翻译 |
Loss function
ℓ ( y ^ , y ) = ∑ t = 1 T y ℓ ( y ^ < t > , y < t > ) \ell(\hat{y},y) = \sum_{t=1}^{T_y} \ell(\hat{y}^{<t>},y^{<t>}) ℓ(y^,y)=t=1∑Tyℓ(y^<t>,y<t>)
Backpropagation through time
权重矩阵W
∂
ℓ
T
∂
W
=
∑
t
=
1
T
∂
ℓ
T
∂
W
∣
(
t
)
\frac{\partial \ell^{T}}{\partial W} = \sum_{t=1}^{T}\frac{\partial \ell^{T}}{\partial W} \vert_{(t)}
∂W∂ℓT=t=1∑T∂W∂ℓT∣(t)
Handing long term dependencies
常用激活函数
- Sigmoid
- Tanh
- ReLU
VANISHING/EXPLODING GRADIENT
通常在RNN中遇到。原因:difficult to capture long term dependencies – 连乘的梯度可能指数下降或者上升(考虑层数)
Gradient cliping
解决梯度爆炸问题的一种技术,设定梯度最大值。
Types of gates
抑制梯度变为0的问题,使用specific gates:
Γ
=
σ
(
W
x
<
t
>
+
U
a
<
t
−
1
>
+
b
)
\Gamma = \sigma(Wx^{<t>}+Ua^{<t-1>}+b)
Γ=σ(Wx<t>+Ua<t−1>+b)
其中
W
,
U
,
b
W,U,b
W,U,b是gate的系数,
σ
\sigma
σ是sigmoid函数
主要的几种gate类型
- update gate – GRU,LSTM
- relevance gate – GRU,LSTM
- forget gate – LSTM
- output gate – LSTM
GRU/LSTM
gated recurrent unit
long short-term memory units
都是用来解决梯度消失问题。
LSTM是GRU的生成器
RNN变体
- Bidirectional
- Deep
LEARNING WORD REPRESENTATION
REPRESENTATION TECHNIQUES
两种主要表示方法:
- 1-hot representation
- word embedding
embedding matrix(E)
将word w 从1-hot representation (
o
w
o_w
ow)映射到embedding(
e
w
e_w
ew)
e
w
=
E
o
w
e_w = E_{o_w}
ew=Eow
word embedding
word2vec
框架-目的在通过估计给定word是否被其他word包围的可能性来学习word embedding,流行的模型包括skip-gram,negative sampling和CBOW
skip-gram
监督性学习任务——评估目标word在给定本文word出现的可能性,指定t的一个参数
θ
t
\theta_t
θt,,概率为:
P
(
t
∣
c
)
=
e
θ
t
T
e
c
∑
j
=
1
∣
V
∣
e
θ
j
T
e
c
P(t|c) = \frac{e^{\theta_t^Te_c}}{\sum_{j=1}^{|V|}e^{\theta_j^Te_c}}
P(t∣c)=∑j=1∣V∣eθjTeceθtTec
remark:分母的求和过程使得此模型计算开销很大
negative sampling
二进制分类器(使用logistics regression)k个negative和1个positive example
文本c,目标单词t
P
(
y
=
1
∣
c
,
t
)
=
σ
(
θ
t
T
e
c
)
P(y=1|c,t) = \sigma(\theta_t^Te_c)
P(y=1∣c,t)=σ(θtTec)
GloVe
word embedding 技术
X
i
,
j
X_{i,j}
Xi,j表示目标i在文本j中出现的次数
J
(
θ
)
=
1
2
∑
i
,
j
=
1
∣
V
∣
f
(
X
i
,
j
)
(
θ
i
T
e
j
+
b
i
+
b
j
′
−
l
o
g
(
X
i
,
j
)
)
2
J(\theta) = \frac{1}{2}\sum_{i,j=1}^{|V|}f(X_{i,j})(\theta_i^Te_j+b_i+b'_j-log(X_{i,j}))^2
J(θ)=21i,j=1∑∣V∣f(Xi,j)(θiTej+bi+bj′−log(Xi,j))2
这里
f
f
f是权重函数,例如
X
i
,
j
=
0
→
f
(
X
i
,
j
)
=
0
X_{i,j}=0 \to f(X_{i,j}) = 0
Xi,j=0→f(Xi,j)=0
最终word embedding
e
w
f
i
n
a
l
e_w^{final}
ewfinal
e
w
f
i
n
a
l
=
e
w
+
θ
w
2
e_w^{final} = \frac{e_w+\theta_w}{2}
ewfinal=2ew+θw
cosine similarity
word
w
1
w_1
w1 and word
w
2
w_2
w2之间的余弦相似性:
s
i
m
i
l
a
r
i
t
y
=
w
1
⋅
w
2
∥
w
1
∥
∥
w
2
∥
=
c
o
s
(
θ
)
similarity = \frac{w_1 \cdot w_2}{\|w_1\|\|w_2\|} = cos(\theta)
similarity=∥w1∥∥w2∥w1⋅w2=cos(θ)
t-SNE
减少高维度embedding,通常在2D空间使用