Neural Discrete Representation Learning (VQ-VAE) 简介

目录

  • VQ-VAE
  • 参考

VQ-VAE

VAE是一种生成模型。
Vector QuantisedVariational AutoEncoder (VQ-VAE)是VAE的变种,其隐含变量是离散的。离散的隐含变量对于自然语言,推理都比较有帮助。著名的DALL-E就使用了类似VQ-VAE的离散隐含变量来从文本生成图像,DALL-E对VQ-VAE进行了一些改进。
Neural Discrete Representation Learning (VQ-VAE) 简介_第1张图片
VQ-VAE通过vector quantisation (VQ) 将隐含变量离散化。
假设 e ∈ R K × D \mathbf{e} \in \mathbb{R}^{K \times D} eRK×D是codebook。其中 K K K是codebook中embeddings的个数, D D D是codebook的维度。 e i \mathbf{e}_i ei是其中一个embedding。
encoder的输出 E ( x ) = z e E(\mathbf{x}) = \mathbf{z}_e E(x)=ze将通过最近邻查找的方式找到自己属于的embedding向量。这个embedding向量通过decoder D ( . ) D(.) D(.)的输出将尽可能与 x \mathbf{x} x相似。
z q ( x ) = Quantize ( E ( x ) ) = e k  where  k = arg ⁡ min ⁡ i ∥ E ( x ) − e i ∥ 2 \mathbf{z}_q(\mathbf{x}) = \text{Quantize}(E(\mathbf{x})) = \mathbf{e}_k \text{ where } k = \arg\min_i \|E(\mathbf{x}) - \mathbf{e}_i \|_2 zq(x)=Quantize(E(x))=ek where k=argiminE(x)ei2

VQ-VAE优化的是下面的目标:
L = ∥ x − D ( e k ) ∥ 2 2 ⏟ reconstruction loss + ∥ sg [ E ( x ) ] − e k ∥ 2 2 ⏟ VQ loss + β ∥ E ( x ) − sg [ e k ] ∥ 2 2 ⏟ commitment loss L = \underbrace{\|\mathbf{x} - D(\mathbf{e}_k)\|_2^2}_{\textrm{reconstruction loss}} + \underbrace{\|\text{sg}[E(\mathbf{x})] - \mathbf{e}_k\|_2^2}_{\textrm{VQ loss}} + \underbrace{\beta \|E(\mathbf{x}) - \text{sg}[\mathbf{e}_k]\|_2^2}_{\textrm{commitment loss}} L=reconstruction loss xD(ek)22+VQ loss sg[E(x)]ek22+commitment loss βE(x)sg[ek]22其中sq表示stop_gradient。

codebook中的embedding向量使用EMA (exponential moving average)学习。
N i ( t ) = γ N i ( t − 1 ) + ( 1 − γ ) n i ( t )        m i ( t ) = γ m i ( t − 1 ) + ( 1 − γ ) ∑ j = 1 n i ( t ) z i , j ( t )        e i ( t ) = m i ( t ) / N i ( t ) N_i^{(t)} = \gamma N_i^{(t-1)} + (1-\gamma)n_i^{(t)}\;\;\; \mathbf{m}_i^{(t)} = \gamma \mathbf{m}_i^{(t-1)} + (1-\gamma)\sum_{j=1}^{n_i^{(t)}}\mathbf{z}_{i,j}^{(t)}\;\;\; \mathbf{e}_i^{(t)} = \mathbf{m}_i^{(t)} / N_i^{(t)} Ni(t)=γNi(t1)+(1γ)ni(t)mi(t)=γmi(t1)+(1γ)j=1ni(t)zi,j(t)ei(t)=mi(t)/Ni(t)

参考

lilianweng.github.io VQ-VAE

你可能感兴趣的:(人工智能,深度学习)