<blockquote>
  <ol>
  <li>In the paper by Blundell (2015), the coefficient is set to 1/M (where M is the number of mini-batches). In the example given by TFP, the coefficient is given as 1/mnist_data.train.num_examples. Why?</li>
  </ol>
</blockquote>

<p>In the BBB paper eq. 8, they refer to M being the number of mini-batches. To be consistent with the non-stochastic gradient learning, it should be scaled by the number of mini-batches which is what is done by <a href="https://papers.nips.cc/paper/4329-practical-variational-inference-for-neural-networks.pdf" rel="nofollow noreferrer">Graves</a>. Another alternative is that done in eq. 9, where they scale it by <code>\pi_i</code>, where the sum of all the values in the set <code>{\pi}</code> sum to one.</p>

<p>In the TFP example, it does look like the <code>num_examples</code> is the total number of independent samples within the training set, which is much larger than the number of batches. This is goes by a few names, such as <a href="https://arxiv.org/pdf/1910.09227v1.pdf" rel="nofollow noreferrer">Safe Bayes</a> or <a href="https://arxiv.org/pdf/2002.08791.pdf" rel="nofollow noreferrer">Tempering</a>.  Have a look at sec. 8 of <a href="https://arxiv.org/pdf/2002.08791.pdf" rel="nofollow noreferrer">this paper</a> for some more discussion about the use of tempering within Bayesian inference and it's suitability.</p>

<blockquote>
  <p>As I go from 2d input to 3d images volumes, the KL loss is still significantly larger (~1k) than the cross-entropy (~1), even after dividing by mnist_data.train.num_examples. Why?</p>
</blockquote>

<p>The ELBO will always be larger than just your cross-entropy (which defines your likelihood). Have a look at how the KL divergence term in the ELBO is found.  (and a full mean-field approach where each weight/parameter is assumed to be independent).</p>

<p>Since the assumed posterior is factorised (assume each parameter is independent), can write the joint distribution as a product. This means when you take the log when you are computing the KL between the approx. posterior and the prior, you can write it as a sum of the KL terms between each parameter. Since the KL is >= 0, for each parameter you add to your model you will be adding another positive term to your ELBO. This is likely why your loss is so much more for your 3D model, likely because there is more parameters.</p>

<p>Another reason this could occur is if you have less data (your M is smaller, than the KL term is weighted less).</p>

<blockquote>
  <p>What is the guideline for getting a proper value for this coefficient? Maybe like the two-loss terms should be the same order of magnitude?</p>
</blockquote>

<p>I am unsure of any specific guideline, for training you are interested primarily in the gradients. A large loss does not mean a large gradient. Have a look at the gradients contributed by the negative log likelihood and the KL term in your ELBO. If the KL term is too large, you probably need a more informative prior or more data (you could simply scale the KL term but this feels a bit yucky for the Bayesian in me).</p>

<blockquote>
  <p>The current coefficient only takes care of the number of training samples, but not the network complexity or the number of parameters in the network, which I assume the KL loss increase with the complexity of the model.</p>
</blockquote>

<p>Yes, as stated before, in general, more parameters == greater ELBO (for a mean-field approach as used in Bayes by Backprop).</p>

<blockquote>
  <p>I am trying to implement a neural network with the KL loss, without using keras.model.losses, as some software production and hardware support limitation. I am trying to train my model with TF 1.10 and TFP 0.3.0., the issue is that for tf&lt;=1.14, tf.keras.model does not support tf.layers inside the Keras model, so I can't use my original model straight away. Is there a way to get the KL loss, not from model.losses, but from layers or weights of the network in a TF construct?</p>
</blockquote>

<p>I am unsure about the best way to tackle this part of it. I would be cautious about going to older versions where it isn't explicitly supported. They put those warnings/exceptions in for a reason.</p>

<blockquote>
  <p>Is batch normalization or group normalization still helpful in Bayesian deep learning?</p>
</blockquote>

<p>For variational inference (as done in Bayes by Backprop) Batchnorm is fine. For sampling methods such as MCMC, Batch normalization is no longer suitable. Have a look at <a href="https://arxiv.org/pdf/1908.03491v1.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1908.03491v1.pdf</a> for info on suitability for batch norm with sampling methods for approx. Bayesian inference.</p>
Multiple questions regarding the KL term in the ELBO loss with TensorFlow Probability
<p>I have been trying to conduct a few experiments using TensorFlow Probability (TFP), and I got a few questions.</p>

<ol>
<li><p>What is the proper value of the coefficient of the KL loss?</p>

<ol>
<li><p>In the paper by Blundell (2015), the coefficient is set to <code>1/M</code> (where <code>M</code> is the number of mini-batches). In the example given by TFP, the coefficient is given as <code>1/mnist_data.train.num_examples</code>. Why?</p></li>
<li><p>As I go from 2d input to 3d images volumes, the KL loss is still significantly larger (~1k)  than the cross-entropy (~1), even after dividing by <code>mnist_data.train.num_examples</code>. Why?</p></li>
<li><p>What is the guideline for getting a proper value for this coefficient? Maybe like the two-loss terms should be the same order of magnitude?</p></li>
<li><p>The current coefficient only takes care of the number of training samples, but not the network complexity or number of parameters in the network, which I assume the KL loss increase with the complexity of the model.</p></li>
</ol></li>
<li><p>I am trying to implement a neural network with the KL loss, without using <code>keras.model.losses</code>, as some software production and hardware support limitation. I am trying to train my model with TF 1.10 and TFP 0.3.0., the issue is that for <code>tf&lt;=1.14</code>, <code>tf.keras.model</code> does not support <code>tf.layers</code> inside the Keras model, so I can't use my original model straight away. Is there a way to get the KL loss, not from <code>model.losses</code>, but from layers or weights of the network in a TF construct?</p></li>
<li><p>Is batch normalization or group normalization still helpful in Bayesian deep learning?</p></li>
</ol>