论文名称: Neural Discrete Representation Learning 开源地址 发表时间:NIPS2017
作者及组织:Aaron van den Oord,Oriol Vinyals和Koray Kavukcuoglu, 来自DeepMind。

1、VAE

  简单回顾下VAE的损失函数,ELBO的下界为:
VQVAE:Neural Discrete Representation Learning_损失函数
 其中第一项为解码器的重构损失(regression loss) ;第二项为正则项,用KL散度来使Encoder----后验概率 VQVAE:Neural Discrete Representation Learning_生成模型_02 和 先验 VQVAE:Neural Discrete Representation Learning_反向传播_03 分布近似,通常 VQVAE:Neural Discrete Representation Learning_反向传播_03 假设为多元标准正太分布,该项主要防止VAE坍塌到一个点,毕竟是生成模型。
 而VQVAE和VAE主要不同:Encoder输出是离散的,而不是连续的隐变量z。

1、方法

1.1.模型结构

VQVAE:Neural Discrete Representation Learning_损失函数_05

VQVAE:Neural Discrete Representation Learning_损失函数_06 ,然后计算 VQVAE:Neural Discrete Representation Learning_深度学习_07 中每条特征向量跟codebook的最接近的向量的索引,得到 VQVAE:Neural Discrete Representation Learning_深度学习_08 , 然后用codebook中向量 VQVAE:Neural Discrete Representation Learning_损失函数_09 来替换 VQVAE:Neural Discrete Representation Learning_反向传播_10 得到 VQVAE:Neural Discrete Representation Learning_反向传播_11 。最后经过Decoder得到 VQVAE:Neural Discrete Representation Learning_深度学习_12

1.2.训练

 先说下总体损失函数,其实跟VAE的损失函数类似:
VQVAE:Neural Discrete Representation Learning_反向传播_13

 其中第一项就是VAE中的重构损失,但有个问题:在用L2 Loss计算重构损失后,反向传播时,由于在codebook中argmin这个操作是不可导的,这样就优化不了Encoder,于是本文直接将 VQVAE:Neural Discrete Representation Learning_反向传播_11 节点的梯度拷贝给了 VQVAE:Neural Discrete Representation Learning_反向传播_10 ,使得反向传播得以继续。具体的表达式如下:
VQVAE:Neural Discrete Representation Learning_损失函数_16
 式中的 VQVAE:Neural Discrete Representation Learning_深度学习_17 表示 .detach() 操作,由于VQVAE多了一个可学习的codebook,而重构损失并没有梯度传过去。因此损失第二项就是让 VQVAE:Neural Discrete Representation Learning_深度学习_18 逼近 VQVAE:Neural Discrete Representation Learning_反向传播_10

VQVAE:Neural Discrete Representation Learning_反向传播_10 逼近 VQVAE:Neural Discrete Representation Learning_深度学习_18

VQVAE:Neural Discrete Representation Learning_深度学习_12 取得 VQVAE:Neural Discrete Representation Learning_深度学习_18 的概率非0即1: VQVAE:Neural Discrete Representation Learning_反向传播_24 ,相当于二项分布,同时假设 VQVAE:Neural Discrete Representation Learning_反向传播_03

1.3.生成

 在训练集上训练完VQVAE后,VQVAE学习到的是一个有效的低维度的离散表示。然后将VQVAE置为推理阶段,用自回归模型PixCNN来拟合 VQVAE:Neural Discrete Representation Learning_损失函数_26

2、实验

  生成的小图还是可以的。

VQVAE:Neural Discrete Representation Learning_生成模型_27

思考

  替换更强的自回归模型Transformer也就是后来VQGAN的工作了。