0
$\begingroup$

A VAE is comprised of two parts: encoder and decoder. The encoder should take the input and then output a mean $\mu$ and a variance $\sigma^2$. Then, sampling occurs with $\mathcal{N}(\mu,\sigma^2)$ and that passes to the decoder, which will try to reconstruct the original signal. The loss function has a KL divergence term between $\mathcal{N}(0,1)$ and $\mathcal{N}(\mu,\sigma^2)$, where the goal is to make $\mu=0$ and $\log(\sigma) =0$. In my case, when training the encoder neural network what happens is exactly that, but for all inputs, namely, $f_\mu(x)=0$ and $f_\sigma(x)=0$ for all $x$, where $f_\mu,f_\sigma$ are the encoder network. Therefore, no matter what the input is in the encoder, the decoder will always output roughly the same because it is just sampling $\mathcal{N}(0,1)$.

Does anyone know how to deal with this problem? Thanks!

$\endgroup$
7
  • 1
    $\begingroup$ Use a weaker regularization term. $\endgroup$ Commented Apr 20, 2021 at 22:03
  • 1
    $\begingroup$ If the prediction is EXACTLY $f_\mu(x) = 0$ and $f_\sigma(x) = 0$, it sounds like you may have a bug in your code. If it is not exactly that, but roughly that, you may need to increase the weighting of the reconstruction term, or anneal the loss term. The loss (called ELBO) has both a regularization term( i.e. the KL divergence term you refer to), and a reconstruction term. Because training is hard, and the regularization term just makes it harder, it is common to start with a small coefficient for the regularization term, and slowly increase it up to the final value. This is called annealing. $\endgroup$
    – mgarort
    Commented Apr 21, 2021 at 1:22
  • $\begingroup$ It is not exactly 0. It is very close to 0, in fact in terms of sampling, I don't think there's any difference if the mean is 0.002 or 0.001, which are the orders of number I am getting. I'll try adding a weight to the KL term. :) $\endgroup$
    – Schach21
    Commented Apr 21, 2021 at 4:26
  • $\begingroup$ @mgarort why do you say that if $f_\mu(x)=0$ and $f_\sigma(x)=0$, then there is probably a bug in my code? $\endgroup$
    – Schach21
    Commented Apr 21, 2021 at 16:59
  • $\begingroup$ @Schach21 because it would be a great coincidence that the predicted mean and log-variance was exactly the same value for every datapoint, right? In the real world, I expect the datapoints to change slightly, and the output of the encoder to change slightly too. If a neural network (or any predictor) always predicts a constant, that suggests a bug to me. $\endgroup$
    – mgarort
    Commented Apr 21, 2021 at 22:23

0

Your Answer

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

Browse other questions tagged or ask your own question.