Learning hyper-paraeter for loss function regularization term

blade: <p>I was wondering, in the case of a regularized loss function, is it possible to learn a hyper-parameter for the loss function while training the network in PyTorch? I have looked at many research papers and it seems everyone is “tuning” the hyper-parameter than learning.</p>

ptrblck: <p>What kind of hyper-parameter would you like to tune?<br>
Usually the hyper-parameters of the training routine are e.g. the learning rate, weight decay etc.<br>
You could tune it using your training and validation loss, but I’m not sure I understand the connection to the loss function completely.</p>

blade: <p>Thanks for the response. There is a method for imposing physical constraints on the neural network, in which a physics-based loss is added to the loss function. This term is usually a function of the output of the network.</p>
<p>As a simplistic example, assume the network outputs a number, which should not fall below “3”. We add a (penalty) regularization term of the form “max(3-output, 0)” that penalizes when output is below 3 and is canceled when output is above 3.</p>
<p>As this is essentially a constrained optimization (minimizing NN loss function subject to the physical constraint above), which is turned into a regularized unconstraint optimization (in the form of a Lagrangian function), we need to find a Lagrangian multiplier for the regularization term. This Lagrangian multiplier is what I’m wondering if is possible to learn, rather than tune (as suggested in many papers).</p>
<p>You can see one such a work here:<br>
<a href="https://papers.nips.cc/paper/7942-constrained-generation-of-semantically-valid-graphs-via-regularizing-variational-autoencoders.pdf" rel="nofollow noopener">https://papers.nips.cc/paper/7942-constrained-generation-of-semantically-valid-graphs-via-regularizing-variational-autoencoders.pdf</a>. (section 3 and Eq 8 in particular)</p>
<p>Thank you!</p>

ptrblck: <p>Thanks for the information! I’m unfortunately not experienced enough in this area, but maybe <a class="mention" href="/u/tom">@tom</a> might know, if that’s possible. <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

tom: <p>So I’m not sure if I understand correctly what you have in mind, but a few quick comments that shape my intuition around this:</p>
<ul>
<li>As you write, the Lagrange multiplier helps turn a constrained problem into an unconstrained one. While it does so, however, it turns the (say) minimization problem into a saddle point problem. (Because you want the min_{variables} max_{Lagrange multipliers} L, and whenever your constraint is not satisfied, you get infinity in the max part, so it will be irrelevant to the min (if an admissible point exists).)</li>
<li>If you look at regularization, typically, you’ll have a weight for the regularization term as a hyperparameter. Now, if you naïvely included that in your optimization while enforcing positivity, you would just drive that to 0, because, obviously no penalty is cheaper than a penalty.</li>
<li>You can think of tuning as “optimizing hyperparameters” (and the Bayesian crowd will have thoughts on integrating over hyperparameters). This can be done if you set an objective <em>separate</em> from the “inner” optimization objectives, e.g. (as for manual tuning) loss on a validation set. This often goes under the label “meta-learning”.</li>
<li>The perhaps best-studied regularization method is <a href="https://en.wikipedia.org/wiki/Tikhonov_regularization" rel="nofollow noopener">Tikhonov regularization (leading to “ridge regression”)</a>. As the Wikipedia page notes, the optimal regularization parameter is typically unknown. It does offer some heuristics / discussion of helpful interpretations.</li>
<li>Yarin Gal, in <a href="http://mlg.eng.cam.ac.uk/yarin/blog_2248.html" rel="nofollow noopener">his thesis</a>, has a section on optimizing the dropout probability in the context of variational Bayesian inference (Section 6.4 ELBO correlation with test log likelihood), where he reports mixed results and offers some hypothesis for possible causes. I must admit I did not follow whether further research exists on any of these hypothesis.</li>
</ul>
<p>Best regards</p>
<p>Thomas</p>

blade: <p>Thank you for the insight. I recently encountered <a href="http://proceedings.mlr.press/v98/cotter19a.html" rel="nofollow noopener">this paper</a> and it’s <a href="https://github.com/google-research/tensorflow_constrained_optimization" rel="nofollow noopener">implementation in TF</a>. Although they address a more general case where the constraints are not differentiable using a so called <em>proxy Lagrangian</em>, I was wondering if you have encountered similar PyTorch implementations (Not necessarily for non-differentiable constraints, but only general enough to work for non-convex DNNs).</p>