链接: https://arxiv.org/abs/1912.03263v2
本文提出一个解释常用分类模型的新思路, 将之解读为一种基于能量的模型, 得到一个生成模型和判别模型的混合模型, 这种混合模型的训练, 能够同时提高分类精度和样本生成质量.
相关的工作
(Xie et al., 2016) 做了一个相似的解读, 但是模型定义并不相同, 他们定义了一个基于条件的模型 p ( x ∣ y ) p(\mathbf{x}|y) p(x∣y). 但是这需要学习额外的参数才能得出分类器和无条件模型. 这种差别可能是导致我们的模型更优秀的原因. (Song & Ou, 2018) 也是与本文类似的, 但是使用一个类似 GAN 的生成器来进行训练, 并应用于不同的场景.
本文的方法
首先介绍一下基于能量的模型 (Energy Based Models).
p
θ
(
x
)
=
exp
(
−
E
θ
(
x
)
)
Z
(
θ
)
.
p_{\theta}(\mathrm{x})=\frac{\exp \left(-E_{\theta}(\mathrm{x})\right)}{Z(\theta)}.
pθ(x)=Z(θ)exp(−Eθ(x)).
其中,
E
θ
(
x
)
:
R
D
→
R
E_{\theta}(\mathrm{x}): \mathbb{R}^{D} \rightarrow \mathbb{R}
Eθ(x):RD→R, 被称为能量函数,
Z
(
θ
)
=
∫
x
exp
(
−
E
θ
(
x
)
)
Z(\theta)=\int_{\mathbf{x}} \exp \left(-E_{\theta}(\mathbf{x})\right)
Z(θ)=∫xexp(−Eθ(x)) 被称为配分函数(partition function). 要训练这个函数, 可以考虑优化对数似然的方法. 对
θ
\theta
θ 求梯度:
∂
log
p
θ
(
x
)
∂
θ
=
E
p
θ
(
x
′
)
[
∂
E
θ
(
x
′
)
∂
θ
]
−
∂
E
θ
(
x
)
∂
θ
.
\frac{\partial \log p_{\theta}(\mathrm{x})}{\partial \theta}=\mathbb{E}_{p_{\theta}\left(\mathrm{x}^{\prime}\right)}\left[\frac{\partial E_{\theta}\left(\mathrm{x}^{\prime}\right)}{\partial \theta}\right]-\frac{\partial E_{\theta}(\mathrm{x})}{\partial \theta}.
∂θ∂logpθ(x)=Epθ(x′)[∂θ∂Eθ(x′)]−∂θ∂Eθ(x).
比较困难的地方是难以从
p
θ
(
x
)
p_{\theta}(\mathbf{x})
pθ(x) 采样. 可以采用 MCMC 方法来解决这个难点. 经过这几年的发展, 又有了新的采样方法, 也是本文将要采用的 Stochastic Gradient Langevin Dynamics (SGLD) (Welling & Teh, 2011), 采样方法为
x
0
∼
p
0
(
x
)
,
x
i
+
1
=
x
i
−
α
2
∂
E
θ
(
x
i
)
∂
x
i
+
ϵ
,
ϵ
∼
N
(
0
,
α
)
.
\mathbf{x}_{0} \sim p_{0}(\mathbf{x}), \quad \mathbf{x}_{i+1}=\mathbf{x}_{i}-\frac{\alpha}{2} \frac{\partial E_{\theta}\left(\mathbf{x}_{i}\right)}{\partial \mathbf{x}_{i}}+\epsilon, \quad \epsilon \sim \mathcal{N}(0, \alpha).
x0∼p0(x),xi+1=xi−2α∂xi∂Eθ(xi)+ϵ,ϵ∼N(0,α).
下面考虑一个通用形式的
K
K
K 类分类问题.
p
θ
(
y
∣
x
)
=
exp
(
f
θ
(
x
)
[
y
]
)
∑
y
′
exp
(
f
θ
(
x
)
[
y
′
]
)
p_{\theta}(y | \mathbf{x})=\frac{\exp \left(f_{\theta}(\mathbf{x})[y]\right)}{\sum_{y^{\prime}} \exp \left(f_{\theta}(\mathbf{x})\left[y^{\prime}\right]\right)}
pθ(y∣x)=∑y′exp(fθ(x)[y′])exp(fθ(x)[y])
其中
f
θ
(
x
)
[
y
]
f_{\theta}(\mathbf{x})[y]
fθ(x)[y] 是指网络输出向量的第
k
k
k 个分量, 通过 softmax 归一化得到属于某一类别的概率. 保持
f
θ
f_{\theta}
fθ 不变, 下面定义一个基于能量的模型:
p
θ
(
x
,
y
)
=
exp
(
f
θ
(
x
)
[
y
]
)
Z
(
θ
)
.
p_{\theta}(\mathbf{x}, y)=\frac{\exp \left(f_{\theta}(\mathbf{x})[y]\right)}{Z(\theta)}.
pθ(x,y)=Z(θ)exp(fθ(x)[y]).
其中
Z
(
θ
)
Z(\theta)
Z(θ) 是未知的归一化常数, 根据前面能量模型的定义, 可以看出
E
θ
(
x
,
y
)
=
−
f
θ
(
x
)
[
y
]
E_{\theta}(\mathbf{x}, y)=-f_{\theta}(\mathbf{x})[y]
Eθ(x,y)=−fθ(x)[y]. 通过对
y
y
y 积分, 可得到:
p
θ
(
x
)
=
∑
y
p
θ
(
x
,
y
)
=
∑
y
exp
(
f
θ
(
x
)
[
y
]
)
Z
(
θ
)
p_{\theta}(\mathrm{x})=\sum_{y} p_{\theta}(\mathrm{x}, y)=\frac{\sum_{y} \exp \left(f_{\theta}(\mathrm{x})[y]\right)}{Z(\theta)}
pθ(x)=y∑pθ(x,y)=Z(θ)∑yexp(fθ(x)[y])
再根据能量函数的定义, 可以得到某个数据
x
\mathbf{x}
x 的能量为:
E
θ
(
x
)
=
−
log
SumExp
y
(
f
θ
(
x
)
[
y
]
)
=
−
log
∑
y
exp
(
f
θ
(
x
)
[
y
]
)
E_{\theta}(\mathrm{x})=-\log \operatorname{SumExp}_{y}\left(f_{\theta}(\mathrm{x})[y]\right)=-\log \sum_{y} \exp \left(f_{\theta}(\mathrm{x})[y]\right)
Eθ(x)=−logSumExpy(fθ(x)[y])=−logy∑exp(fθ(x)[y])
下面是优化模型部分, 我们的目标是最大化似然
p
(
x
,
y
)
p(\mathbf{x},y)
p(x,y), 但由于
p
(
x
)
,
p
(
x
,
y
)
p(\mathbf{x}), p(\mathbf{x},y)
p(x),p(x,y) 是非归一化的, 因此很难直接优化, 所以对
p
(
x
,
y
)
p(\mathbf{x},y)
p(x,y) 做分解:
log
p
θ
(
x
,
y
)
=
log
p
θ
(
x
)
⋅
p
θ
(
y
∣
x
)
=
log
p
θ
(
x
)
+
log
p
θ
(
y
∣
x
)
.
\log p_{\theta}(\mathbf{x}, y)=\log p_{\theta}(\mathbf{x}) \cdot p_{\theta}(y | \mathbf{x}) = \log p_{\theta}(\mathbf{x})+\log p_{\theta}(y | \mathbf{x}).
logpθ(x,y)=logpθ(x)⋅pθ(y∣x)=logpθ(x)+logpθ(y∣x).
通过优化最后两项来达到优化目标, 即
log
p
θ
(
y
∣
x
)
\log p_{\theta}(y | \mathbf{x})
logpθ(y∣x) 使用交叉熵损失,
log
p
θ
(
x
)
\log p_{\theta}(\mathbf{x})
logpθ(x) 使用 SGLD 方法.
参考
- Jianwen Xie, Yang Lu, Song-Chun Zhu, and Yingnian Wu. A theory of generative convnet. In International Conference on Machine Learning, pp. 2635–2644, 2016.
- Yunfu Song and Zhijian Ou. Learning neural random fields with inclusive auxiliary generators. arXiv preprint arXiv:1806.00271, 2018.
- Max Welling and Yee W Teh. Bayesian learning via stochastic gradient langevin dynamics. In Proceedings of the 28th international conference on machine learning (ICML-11), pp. 681–688, 2011.
本人才疏学浅, 如有遗漏或错误之处, 请多多指教!