李宏毅老师GAN的课程中曾经对于这个问题有一个直观的解释,大体上可以参考以下的简单理解
那么具体在数学上如何理解这个问题的产生呢?在Goodfellow提出的GAN的原始论文中指出,当生成器和判别器的能力足够强的时候,一定可以收敛到纳什均衡点,此时得到的最优的判别器 D ∗ D^* D∗为
D ∗ = p r ( x ) p r ( x ) + p θ ( x ) D^*=\frac{p_{r}(x)}{p_{r}(x)+p_{\theta}(x)} D∗=pr(x)+pθ(x)pr(x)
而当判别器固定时,生成器的目标函数为:
max θ ( E z ∼ p ( z ) [ log D ( G ( z , θ ) , ϕ ) ] ) \max _{\theta}\left(\mathbb{E}_{\mathrm{z} \sim p(\mathrm{z})}[\log D(G(\mathbf{z}, \theta), \phi)]\right) θmax(Ez∼p(z)[logD(G(z,θ),ϕ)])
那么将 D ∗ D^* D∗的表达式代入上式有
L ′ ( G ∣ D ⋆ ) = E x ∼ p θ ( x ) [ log D ⋆ ( x ) ] = E x ∼ p θ ( x ) [ log p r ( x ) p r ( x ) + p θ ( x ) ⋅ p θ ( x ) p θ ( x ) ] = − E x ∼ p θ ( x ) [ log p θ ( x ) p r ( x ) ] + E x ∼ p θ ( x ) [ log p θ ( x ) p r ( x ) + p θ ( x ) ] = − D K L ( p θ ∥ p r ) + E x ∼ p θ ( x ) [ log ( 1 − D ⋆ ( x ) ) ] = − D K L ( p θ ∥ p r ) + 2 D J S ( p r ∥ p θ ) − 2 log 2 − E x ∼ p r ( x ) [ log D ⋆ ( x ) ] \begin{array}{l}{\mathcal{L}^{\prime}\left(G | D^{\star}\right)=\mathbb{E}_{\mathbf{x} \sim p_{\theta}(\mathbf{x})}\left[\log D^{\star}(\mathbf{x})\right]} \\ {\quad=\mathbb{E}_{\mathbf{x} \sim p_{\theta}(\mathbf{x})}\left[\log \frac{p_{r}(\mathbf{x})}{p_{r}(\mathbf{x})+p_{\theta}(\mathbf{x})} \cdot \frac{p_{\theta}(\mathbf{x})}{p_{\theta}(\mathbf{x})}\right]} \\ {=-\mathbb{E}_{\mathbf{x} \sim p_{\theta}(\mathbf{x})}\left[\log \frac{p_{\theta}(\mathbf{x})}{p_{r}(\mathbf{x})}\right]+\mathbb{E}_{\mathbf{x} \sim p_{\theta}(\mathbf{x})}\left[\log \frac{p_{\theta}(\mathbf{x})}{p_{r}(\mathbf{x})+p_{\theta}(\mathbf{x})}\right]} \\ \begin{array}{l}{=-D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right)+\mathbb{E}_{\mathrm{x} \sim p_{\theta}(\mathrm{x})}\left[\log \left(1-D^{\star}(\mathrm{x})\right)\right]} \\ {=-D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right)+2 D_{\mathrm{JS}}\left(p_{r} \| p_{\theta}\right)-2 \log 2-\mathbb{E}_{\mathrm{x} \sim p_{r}(\mathrm{x})}\left[\log D^{\star}(\mathrm{x})\right]}\end{array} \end{array} L′(G∣D⋆)=Ex∼pθ(x)[logD⋆(x)]=Ex∼pθ(x)[logpr(x)+pθ(x)pr(x)⋅pθ(x)pθ(x)]=−Ex∼pθ(x)[logpr(x)pθ(x)]+Ex∼pθ(x)[logpr(x)+pθ(x)pθ(x)]=−DKL(pθ∥pr)+Ex∼pθ(x)[log(1−D⋆(x))]=−DKL(pθ∥pr)+2DJS(pr∥pθ)−2log2−Ex∼pr(x)[logD⋆(x)]
其中后两项为常数,只有前两项与生成器有关,所以可以将生成器的目标函数表示为
max θ L ′ ( G ∣ D ⋆ ) = min θ D K L ( p θ ∥ p r ) − 2 D J S ( p r ∥ p θ ) \max _{\theta} \mathcal{L}^{\prime}\left(G | D^{\star}\right)=\min _{\theta} D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right)-2 D_{\mathrm{JS}}\left(p_{r} \| p_{\theta}\right) θmaxL′(G∣D⋆)=θminDKL(pθ∥pr)−2DJS(pr∥pθ)
那么根据原论文中的介绍,其中第二项的 2 D J S ( p r ∥ p θ ) 2 D_{\mathrm{JS}}\left(p_{r} \| p_{\theta}\right) 2DJS(pr∥pθ)为有界函数,因此 L \mathcal{L} L主要受逆向KL散度 D K L ( p θ ∥ p r ) D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right) DKL(pθ∥pr)的影响,因此为了更快的收敛,生成器会倾向于生成一些已经骗过判别器的样本,这样的话,样本的多样性就会下降,从而造成了**模式坍缩(model collapse)**的问题。
为什么当 L \mathcal{L} L主要受逆向KL散度 D K L ( p θ ∥ p r ) D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right) DKL(pθ∥pr)的影响时就会出现模式坍缩呢?这要从逆向KL散度的性质来看。我们知道KL散度是非对称的,印象按照表达式中分布顺序的不同,可以分为正向KL散度和逆向KL散度,表达如下所示
D K L ( p r ∥ p θ ) = ∫ p r ( x ) log p r ( x ) p θ ( x ) d x D K L ( p θ ∥ p r ) = ∫ p θ ( x ) log p θ ( x ) p r ( x ) d x \begin{aligned} D_{\mathrm{KL}}\left(p_{r} \| p_{\theta}\right) &=\int p_{r}(\mathrm{x}) \log \frac{p_{r}(\mathrm{x})}{p_{\theta}(\mathrm{x})} d \mathrm{x} \\ D_{\mathrm{KL}}\left(p_{\theta} \| p_{r}\right) &=\int p_{\theta}(\mathrm{x}) \log \frac{p_{\theta}(\mathrm{x})}{p_{r}(\mathrm{x})} d \mathrm{x} \end{aligned} DKL(pr∥pθ)DKL(pθ∥pr)=∫pr(x)logpθ(x)pr(x)dx=∫pθ(x)logpr(x)pθ(x)dx
在前向KL散度中:
- 当 p x → 0 p_{x} \rightarrow 0 px→0而 p θ > 0 p_{\theta}>0 pθ>0时,积分号内整体趋近于0,所以 p θ ( x ) p_{\theta}(x) pθ(x)的取值对于KL散度的计算不起任何作用
- 当 p x > 0 p_{x} > 0 px>0而 p θ → 0 p_{\theta} \rightarrow0 pθ→0时,积分号内整体趋近于 ∞ \infty ∞,所以KL散度会变得非常大
从中我们可以看出,前向KL散度会鼓励模型分布 p θ ( x ) p_{\theta}(x) pθ(x) 尽可能的覆盖所有真实分布 p r ( x ) > 0 p_{r}(x) >0 pr(x)>0的点,而不用会回避 p r ( x ) ≈ 0 p_{r}(x) \approx 0 pr(x)≈0的点。换言之,如果我们使用前向KL散度来衡量两个分布,生成器会更加倾向于生成多样性更好的样本。
而在逆向的KL散度中
- 当 p x → 0 p_{x} \rightarrow 0 px→0而 p θ > 0 p_{\theta}>0 pθ>0时,积分号内整体趋近于 ∞ \infty ∞,即当 p θ ( x ) p_{\theta}(x) pθ(x)趋近于0时,而 p θ ( x ) p_{\theta}(x) pθ(x)有一定的密度时,逆向KL散度的值就会变得非常大
- 当 p θ → 0 p_{\theta} \rightarrow0 pθ→0时,无论 p r ( x ) p_{r}(x) pr(x)如何取值,积分号内的整体都将趋近于0
从中我们可以看出,逆向KL散度会鼓励模型分布 p θ ( x ) p_{\theta}(x) pθ(x) 尽可能避开所有真实分布 p r ( x ) ≈ 0 p_{r}(x) \approx 0 pr(x)≈0 的点,而不需要考虑是否覆盖所有 p r ( x ) > 0 p_{r}(x) > 0 pr(x)>0的点。这样的话,只要真实分布不趋近于0,模型就会尽量生成类似于已接近真实分布的新样本,而不是去生成所有覆盖真实分布的样本。
形象的表示如下
因此,如果使用逆向KL散度作为衡量手段的话,就会出现模式坍缩的问题。为了解决这个问题,不少人针对两个分布之间的衡量提出了很多GAN的变体,例如WGAN、Improved-WAN、LSGAN等等。
邱锡鹏《神经网络与深度学习》13.3.5.1节