Answers.Body: <p>Your observation is correct. In BNNs trained with methods like Bayesian by backprop (BBB), the KL loss serves as a regularizer that encourages the posterior distribution of weights to approximate the prior distribution, therefore it's possible for the KL loss to remain relatively constant during training, especially if the model has not yet learned to deviate significantly from the prior meaning it's actually learning well w.r.t the prior as expected or the weights are initialized close to the prior. In BNNs and ML in general the prior remains fixed throughout training to be qualified as a regularizer for reducing test error, while in standard Bayesian inference the prior is continuously updated based on newly observed data without generalizable learning or prediction consideration. Though bearing in mind such functional difference, in principle BNNs are designed with the same aim as Bayesian inference to decrease prior uncertainty with more training data.</p>
  <p>BNNs training sometimes can readily lead to undesirable underfitting behavior, such as &quot;posterior collapse&quot; to a deterministic network caused by the complex interactions between the architecture of the neural network, the choice of prior, the amount of training data and the KL loss weight. For instance, your prior is put too much weight due to your confidence but the data is actually in total conflict with your prior, which is possible to fit your specific case. The loss of uncertainty propagation and update of learnable parameters defeats the purpose of employing Bayesian method which is crucial for <em>robust</em> decision-making.</p>
  <p>Balancing KL loss weight hyperparameter is often an empirical process and it depends on factors like the model capacity and the amount of available data. The more effective capacity or lesser training data, the larger the hyperparameter in general. Also techniques such as the use of a fixed schedule for annealing the KL weight could mitigate the &quot;posterior collapse&quot;.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-02T16:50:25.333Z
Answers.Text: Thanks. Part of the reason, I asked is because ordinarily you would expect that uncertainty would decrease with more data (or in this case more training) in a Bayesian setting. Is it still reasonable to expect that with BNNs?
Answers.UserDisplayName: profPlum
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-02T21:46:49.863Z
Answers.Text: In principle BNNs are designed with the same aim as Bayesian inference to decrease prior uncertainty with more training data, see my updated answer.
Answers.UserDisplayName: cinch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-02T08:01:50.150Z
Answers.LastActivityDate: 2024-03-02T21:41:29.103Z
Answers.LastEditDate: 2024-03-02T21:41:29.103Z
Answers.UserDisplayName: cinch
Answers.Body: <p>This looks like more underfitting than other issue.</p>
  <p>But you are overlooking that Bayes by Backprop is an approximation to Bayesian principles, because a true Bayesian NN is not tractable, you are using an approximation, and it behaves approximately, so not all principles you mentioned actually apply.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-11T20:41:31.797Z
Answers.Text: You're right actually the loss plots at the time had a bug in it. So I've removed them to focus on the theory component.
Answers.UserDisplayName: profPlum
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-12T05:37:43.837Z
Answers.Text: @profPlum If this is the right answer, you could accept it.
Answers.UserDisplayName: Dr. Snoopy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-02T16:51:08.530Z
Answers.LastActivityDate: 2024-03-02T16:51:08.530Z
Answers.UserDisplayName: Dr. Snoopy
Body: <p>I've been trying to train a Bayesian Neural Network and I noticed that the KL loss (which enforces the prior) isn't changing over time. And it occurred to me that while in standard Bayesian inference the prior acts like an artificial dataset (e.g. beta(N,N) adds 2N more observations). In Bayesian Neural networks like <a href="https://arxiv.org/abs/1505.05424" rel="nofollow noreferrer">Bayese-by-Backprop</a>, the prior is just a regularizing term in the loss function (<strong>the KL loss term</strong>).</p>
  <p><a href="https://i.sstatic.net/ecnBw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ecnBw.png" alt="Bayese-by-Backprop loss" /></a></p>
  <p>Which as I understand it means the KL loss term might never increase (depending on its weight), and thus uncertainty might never decrease, which contradicts the standard Bayesian inference behavior where the prior is guaranteed to lose it's importance as you get more data... Further more if you play with loss term weights then there is a question as to what weights are valid &amp; how to prevent collapse to a fully deterministic network...</p>
  <p><strong>Please tell me I'm wrong, and explain how (hopefully) this is fully comparable to regular Bayesian inference as well as why KL-loss might not change during training?</strong></p>
  
Tags: <bayesian-deep-learning><bayesian-neural-networks>
Title: KL loss not changing in a Bayesian Neural Network?
UserDisplayName: profPlum
ThreadText: # KL loss not changing in a Bayesian Neural Network?
  
  (Asked by: username_0 on 2024-03-01)
  
  I've been trying to train a Bayesian Neural Network and I noticed that the KL loss (which enforces the prior) isn't changing over time. And it occurred to me that while in standard Bayesian inference the prior acts like an artificial dataset (e.g. beta(N,N) adds 2N more observations). In Bayesian Neural networks like [Bayese-by-Backprop](https://arxiv.org/abs/1505.05424), the prior is just a regularizing term in the loss function (**the KL loss term**).
  
  [![Bayese-by-Backprop loss](https://i.sstatic.net/ecnBw.png)](https://i.sstatic.net/ecnBw.png)
  
  Which as I understand it means the KL loss term might never increase (depending on its weight), and thus uncertainty might never decrease, which contradicts the standard Bayesian inference behavior where the prior is guaranteed to lose it's importance as you get more data... Further more if you play with loss term weights then there is a question as to what weights are valid & how to prevent collapse to a fully deterministic network...
  
  **Please tell me I'm wrong, and explain how (hopefully) this is fully comparable to regular Bayesian inference as well as why KL-loss might not change during training?**
  
  **Tags:** bayesian-deep-learning, bayesian-neural-networks
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2024-03-02. Score: 2 | Accepted answer
  
  This looks like more underfitting than other issue.
  
  But you are overlooking that Bayes by Backprop is an approximation to Bayesian principles, because a true Bayesian NN is not tractable, you are using an approximation, and it behaves approximately, so not all principles you mentioned actually apply.
  
  > **Comments:**
  > **username_0**: You're right actually the loss plots at the time had a bug in it. So I've removed them to focus on the theory component.  
  > **username_2**: @profPlum If this is the right answer, you could accept it.  
  
  ---
  
  ### Answer by username_1 on 2024-03-02. Score: 1
  
  Your observation is correct. In BNNs trained with methods like Bayesian by backprop (BBB), the KL loss serves as a regularizer that encourages the posterior distribution of weights to approximate the prior distribution, therefore it's possible for the KL loss to remain relatively constant during training, especially if the model has not yet learned to deviate significantly from the prior meaning it's actually learning well w.r.t the prior as expected or the weights are initialized close to the prior. In BNNs and ML in general the prior remains fixed throughout training to be qualified as a regularizer for reducing test error, while in standard Bayesian inference the prior is continuously updated based on newly observed data without generalizable learning or prediction consideration. Though bearing in mind such functional difference, in principle BNNs are designed with the same aim as Bayesian inference to decrease prior uncertainty with more training data.
  
  BNNs training sometimes can readily lead to undesirable underfitting behavior, such as "posterior collapse" to a deterministic network caused by the complex interactions between the architecture of the neural network, the choice of prior, the amount of training data and the KL loss weight. For instance, your prior is put too much weight due to your confidence but the data is actually in total conflict with your prior, which is possible to fit your specific case. The loss of uncertainty propagation and update of learnable parameters defeats the purpose of employing Bayesian method which is crucial for *robust* decision-making.
  
  Balancing KL loss weight hyperparameter is often an empirical process and it depends on factors like the model capacity and the amount of available data. The more effective capacity or lesser training data, the larger the hyperparameter in general. Also techniques such as the use of a fixed schedule for annealing the KL weight could mitigate the "posterior collapse".
  
  > **Comments:**
  > **username_0**: Thanks. Part of the reason, I asked is because ordinarily you would expect that uncertainty would decrease with more data (or in this case more training) in a Bayesian setting. Is it still reasonable to expect that with BNNs?  
  > **username_1**: In principle BNNs are designed with the same aim as Bayesian inference to decrease prior uncertainty with more training data, see my updated answer.  
  
  ---
  
  