Line graph of loss

pourya_farzi: <p>have run my model, I got these two graphs. The first one is on dataset_A( Train = 4500 samples, Eval= 500).<br>
In the second run, I used previous evaluation data (from dataset_A) but new 750-sample train data. Is it reasonable to have these patterns?? I mean loss convergence and values.<br>
Thanks<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/0/807687bfb4652d733c4ab1f11983800a56733906.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/807687bfb4652d733c4ab1f11983800a56733906" title="result pick dataset"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/0/807687bfb4652d733c4ab1f11983800a56733906_2_436x500.jpeg" alt="result pick dataset" data-base62-sha1="ikr46gN54WqypgEhV7VAT0ddnTM" width="436" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/0/807687bfb4652d733c4ab1f11983800a56733906_2_436x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/8/0/807687bfb4652d733c4ab1f11983800a56733906_2_654x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/8/0/807687bfb4652d733c4ab1f11983800a56733906_2_872x1000.jpeg 2x" data-dominant-color="D1D1D1"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">result pick dataset</span><span class="informations">902×1034 40.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/c/6c5a51cb537ddfd0a77881a7835c31762b56a91c.png" data-download-href="https://discuss.pytorch.org/uploads/default/6c5a51cb537ddfd0a77881a7835c31762b56a91c" title="result2 train SMTeuroparl eval sick"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5a51cb537ddfd0a77881a7835c31762b56a91c_2_418x500.png" alt="result2 train SMTeuroparl eval sick" data-base62-sha1="fsx4G54ZCh7kCdsOWce8cK5Ab6c" width="418" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/c/6c5a51cb537ddfd0a77881a7835c31762b56a91c_2_418x500.png, https://discuss.pytorch.org/uploads/default/original/3X/6/c/6c5a51cb537ddfd0a77881a7835c31762b56a91c.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/c/6c5a51cb537ddfd0a77881a7835c31762b56a91c.png 2x" data-dominant-color="FCFCFB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">result2 train SMTeuroparl eval sick</span><span class="informations">588×702 37.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

vdw: <p>Since you posted in <code>nlp</code>, I assume your input data is text. I would also assume that your train a classification task, because in this case I’ve also seen a big drop of the training loss after the first epoch. I think(!) this is even more pronounced when using pretrained word embeddings.</p>
<p>The first plot definitely looks “as usual”: the training loss goes down towards overfitting, while the validation loss starts to increase due to that overfitting. The absolute values depend on how exactly you calculate the loss, so they don’t really help.</p>
<p>In the second plot, I’m not sure about the jumps at epoch 17/18 and 32/33. They look rather regular. Do you reset the learning rate or something? The difference in absolute numbers between the 2 plots may stem from the different datasets. I assume, that for the first plot, the training and validation data came from the same dataset. Where do the 750 other samples come from? In any case, 750 is not a large training set – neither is 4,500 – so the overlap in the distribution of the training in validation data might be large.</p>
<p>In short, I don’t see any inherent problems with your graphs, and I can easily explain what I see (maybe part from the jumps). Of course, that doesn’t mean I’m right :).</p>

pourya_farzi: <p>First, my special thanks go to you.<br>
You are right that’s the NLP task with a siamese network to find the similarity between two sentences. I compute loss by code below. Besides, <strong>How can I deal with overfitting in my case well?</strong> I found out that augmentation can help, but any suggestions are welcomed.<br>
<strong>The reason for jump</strong> is that, after a few epochs, if loss gets worse, then I restore the best previous model and decrease the learning rate by multiplying 0.85.  <strong>(AdamW(MM.parameters(), lr=0.001))</strong><br>
As mentioned earlier, <strong>4500 train samples and 500 eval samples of a dataset</strong> for the first plot are used. <strong>For the second I altered train samples with new 750 ones from another dataset</strong><br>
LOSS is computed like this:</p>
<pre><code class="lang-auto">for i, (xA, xB, score) in enumerate(data_loader, 1):
   total_loss += (loss.item()*len(xA))

epoch_loss = total_loss / len(data_loader.dataset)
</code></pre>
<p>Is it OK for showing the result, or should I use cumulative loss like <strong>(loss.item() / i ) * len(A)</strong> ??</p>

vdw: <p>OK, that explains the jumps indeed :). For the training, any normalization of the loss with a constant (here <code>len(xA</code> and <code>len(data_loader.dataset)</code> shouldn’t better. Sure it affects the absolute values of the loss but not the gradients for training.</p>
<p>I’m not aware of Sesame Networks? Do you mean a Siamese Network? I get the idea behind this network architecture but only dabbled once a bit just for some practice.</p>
<p>When you say similarity between two sentences, I assume you refer to semantic similarity – well otherwise you wouldn’t need a Deep Learning model, I guess :). I would argue that this is a very challenging tasks (well, like most NLP task really) since language is extremely flexible and can be very subtle. Even a small change in a sentence can completely alter it’s meaning.</p>
<p>That’s why I never tried data augmentation with text. With images it seems straightforward. Rotating, slight shifting or cropping etc. will still show the same object for classification. I don’t see how to directly map this to text. But that’s just my thought, and I’m anything but an expert!!!</p>

pourya_farzi: <p>You are right of course. Sorry my bad, it’s a typo which I correct. Just one more thing, I’m pretraining my network <strong>by different datasets and wanna use obtained state_dicts</strong> for this one. Which one is reasonable to do, ‘‘pre_training one by one for each dataset’’ or ‘‘combine all of the datasets and just do pretraining once’’?</p>