VAE Loss not decreasing

username: Akshay_Subramanian
cooked: <p>I have implemented a Variational Autoencoder in Pytorch that works on SMILES strings(String representations of molecular structures).<br>
When trained to output the same string as the input, the loss does not decrease between epochs.</p>
<p>I have tried removing the KL Divergence loss and sampling and training only the simple autoencoder. But, even this fails to converge.<br>
Therefore I assume that the error must be with either the encoder, decoder or the training loop and probably is not related to the loss or sampling.</p>
<p>I have also tried the following unsuccessfully:</p>
<ol>
<li>Addition of more GRU layers to improve learning capability of model.</li>
<li>Increasing and decreasing learning rate.</li>
<li>Changing the optimizer from Adam to SGD.</li>
<li>Modifying the batch size(increasing and decreasing)</li>
</ol>
<p>The following is a link to my code:<br>
<a href="https://colab.research.google.com/drive/1LctSm_Emnn5sHpw_Hon8xL5fF4bmKRw5" class="onebox" target="_blank" rel="nofollow noopener">https://colab.research.google.com/drive/1LctSm_Emnn5sHpw_Hon8xL5fF4bmKRw5</a></p>
<p>The following is a link to an equivalent( Same architecture) keras model that successfully trains.<br>
<a href="https://colab.research.google.com/drive/170Peseik03CFYpWPNyD8B8mxUGxTQx67" class="onebox" target="_blank" rel="nofollow noopener">https://colab.research.google.com/drive/170Peseik03CFYpWPNyD8B8mxUGxTQx67</a></p>

username: Akshay_Subramanian
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a>  Could you please have a look at the problem? I have been stuck on it for almost a week now. Any ideas would be helpful. Thanks.</p>

username: ptrblck
cooked: <p>Could you explain the general workflow of your model a bit?<br>
It seems that you are using <code>nn.BCELoss</code> with a softmax output from your decoder.<br>
Also does <code>data</code> represent a probability distribution in <code>[0, 1]</code>?</p>
<p>I would suggest to use a small data sample (e.g. 10 samples) and try to overfit your model.<br>
If your model cannot overfit this small sample, there might be other code bugs.</p>

username: Akshay_Subramanian
cooked: <p>Thanks for your reply <a class="mention" href="/u/ptrblck">@ptrblck</a>.<br>
Yes, I am using <code>nn.BCELoss</code> with a softmax output from the decoder.<br>
<code>data</code> represents a one hot encoded vector of shape [600, 120, 33] (120 is the length of each string and 33 is the length of the character set used to make these strings).</p>
<p>I tried training the model on a small data sample of 10 samples. The initial loss was 20.636. The loss stagnated at 19.803 after around 7500 epochs. The loss decreased very slowly but continuously through these epochs.<br>
So, I guess it is not overfitting at all.</p>
<p>Please let me know if I can clarify anything else about the code.<br>
Any ideas on what can be done <a class="mention" href="/u/ptrblck">@ptrblck</a> ? Thanks.</p>

username: Adnan-annan
cooked: <p><a class="mention" href="/u/akshay_subramanian">@Akshay_Subramanian</a> were you able to get the vae working ? i am facing a similar problem where loss is not decreasing at all. please give me any suggestions.</p>

username: Keyv_Krmn
cooked: <p>I recommend to first try with a very small data size as <a class="mention" href="/u/ptrblck">@ptrblck</a> suggested.  Also, see if you can converge with Autoencoders first, VAE could be tricky to converge. Chek if you apply optimizer.step(), the dimenstion of the output, your loss function, and finally hyperparameters. The best way to debug if to print the output of the model and see if they change</p>