From various explanation (e.g. https://www.youtube.com/watch?v=uaaqyVS9-rM), the decoder part of variational autoencoder corresponds to p(x|z) (or p(x_i|z_i)). However, if we fix z (sample a particular z from latent space), then the output is fixed instead of a distribution. So why does it corresponds to p(x|z)? Thanks in advance.


1 Answer 1


In VAEs, the decoder is implemented using a neural net. The network takes a realization $z$ of the latent variable as input, and outputs parameters of the conditional distribution $p(x \mid z)$ over the observed variable $x$.

For example, if $x = [x_1, \dots, x_d]^T$ is a binary vector, it's common to define $p(x \mid z)$ as a factorized multivariate Bernoulli distribution, where each element $x_i$ is conditionally independent of the others. In this case, the decoder network typically has a sigmoidal output layer $o$, where each unit $o_i$ specifies the probability that $x_i=1$:

$$p(x \mid z) = \prod_i \operatorname{Bernoulli}(x_i \mid o_i)$$

If $x \in \mathbb{R}^d$ is continous, it's common to define $p(x \mid z)$ as an isotropic Gaussian distribution. In this case, the decoder network typically has a linear output layer $o$ with $d+1$ units, where the first $d$ units specify the mean, and the last unit specifies the log variance:

$$p(x \mid z) = \mathcal{N}(x \mid \mu, \sigma^2 I)$$

$$\mu = [o_1, \dots, o_d]^T \quad \sigma^2 = \exp(o_{d+1})$$

Using the log variance lets us avoid constraints on the optimization problem, since exponentiating it always produces a valid, positive value for the variance.

  • $\begingroup$ Thank you so much for the reply. In this case I think the explanation I mentioned above is quite misleading since in it the output is called 'x_hat' (45:57 of the linked I provided). To me it really sounds like the output of VAE is trying to match the input x (just like in a typical AE case) instead of outputting the parameters of a distribution $\endgroup$
    – Sam
    Mar 14, 2021 at 15:24
  • $\begingroup$ same goes for this explanation: youtube.com/watch?v=8wrLjnQ7EWQ it is literally trying to output an image $\endgroup$
    – Sam
    Mar 14, 2021 at 16:41
  • $\begingroup$ I've checked out a few more github repos. All of them treat the output as reconstructed x (image). $\endgroup$
    – Sam
    Mar 15, 2021 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.