Conditional Variational Autoencoders (CVAE)¶
Definition¶
We want to learn \(p(\mathbf{x|y})\).
For example, in the case of \(p(\mathbf{x})\), our VAE will generate an image of any digit, but what if we only wanted it to generate digits of 9? With \(p(\mathbf{x|y}= 9)\), we are able to do so.
The modification from VAE's to CVAE's is quite simple.
The encoder needs to condition on \(\mathbf{y}\) to learn \(p(\mathbf{h | x, y})\), and the decoder also needs to condition on \(\mathbf{y}\) to learn \(p(\mathbf{x | h, y})\).
When we want to use the decoder, we input a \(\mathbf{y}\) and \(\mathbf{h} \sim \mathcal{N}(\mathbf{0, I})\) to generate \(\mathbf{x}\). If we want to sample multiple \(\mathbf{x}\) for a given \(\mathbf{y}\), then we input the same \(\mathbf{y}\) again with a new \(\mathbf{h}\).
When training a CVAE, we use nearly the same loss, the negative ELBO loss. For a given sample \((\mathbf{x, y})\), we input both \(\mathbf{x}\) and \(\mathbf{y}\) into the encoder and input the same \(\mathbf{y}\) into the decoder. The negative ELBO for the conditional VAE is: