关于使用 TensorFlow Probability 的 ELBO 损失中 KL 项的多个问题

Multiple questions regarding the KL term in the ELBO loss with TensorFlow Probability

我一直在尝试使用 TensorFlow Probability (TFP) 进行一些实验,但我遇到了一些问题。

  1. KL损失系数的正确取值是多少?

    1. 在 Blundell (2015) 的论文中,系数设置为 1/M(其中 M 是小批量的数量)。在TFP给出的例子中,系数给出为1/mnist_data.train.num_examples。为什么?

    2. 当我从 2d 输入到 3d 图像体积时,KL 损失仍然比交叉熵 (~1) 大得多 (~1k),即使除以 mnist_data.train.num_examples.为什么?

    3. 获得此系数的正确值的准则是什么?也许就像两个损失项应该是同一个数量级?

    4. 当前系数只考虑训练样本的数量,不考虑网络复杂度或网络中参数的数量,我假设KL loss随着模型复杂度的增加而增加。

  2. 我试图在不使用 keras.model.losses 的情况下实现具有 KL 损失的神经网络,因为某些软件生产和硬件支持限制。我正在尝试使用 TF 1.10 和 TFP 0.3.0 训练我的模型,问题是对于 tf<=1.14tf.keras.model 在 Keras 模型中不支持 tf.layers,所以我可以'不要马上使用我原来的模型。有没有办法不是从 model.losses,而是从 TF 结构中的网络层或权重获得 KL 损失?

  3. batch normalization或group normalization对贝叶斯深度学习还有帮助吗?

  1. 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?

在 BBB 论文方程式中。 8,他们提到 M 是小批量的数量。为了与非随机梯度学习一致,它应该按 Graves 所做的小批量的数量进行缩放。另一种选择是在等式中完成。 9,他们按 \pi_i 缩放它,其中集合 {\pi} 中所有值的总和为一。

在 TFP 示例中,num_examples 看起来确实是训练集中独立样本的总数,远大于批次数。这有几个名字,例如 Safe Bayes or Tempering. Have a look at sec. 8 of this paper 用于更多关于在贝叶斯推理中使用回火及其适用性的讨论。

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?

ELBO 将始终大于您的交叉熵(它定义了您的可能性)。看看 ELBO 中的 KL 散度项是如何找到的。 (以及一个完整的平均场方法,其中每个 weight/parameter 被假定为独立的)。

由于假设后验是因式分解的(假设每个参数都是独立的),可以将联合分布写成乘积。这意味着当您在计算大约之间的 KL 时获取日志。后验和先验,你可以把它写成每个参数之间的 KL 项的总和。由于 KL >= 0,对于您添加到模型中的每个参数,您将向 ELBO 添加另一个正项。这可能就是为什么您的 3D 模型损失更多的原因,可能是因为参数更多。

发生这种情况的另一个原因是如果您的数据较少(您的 M 较小,KL 项的权重较小)。

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?

我不确定是否有任何具体的指导原则,对于训练,您主要对梯度感兴趣。大损失并不意味着大梯度。查看由负对数似然和 ELBO 中的 KL 项贡献的梯度。如果 KL 项太大,您可能需要更多信息先验或更多数据(您可以简单地缩放 KL 项,但这对我的贝叶斯主义者来说有点令人讨厌)。

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.

是的,如前所述,一般来说,更多参数 == 更大的 ELBO(对于 Backprop 在贝叶斯中使用的平均场方法)。

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<=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?

我不确定解决这部分问题的最佳方法。对于未明确支持的旧版本,我会持谨慎态度。他们把那些 warnings/exceptions 放进去是有原因的。

Is batch normalization or group normalization still helpful in Bayesian deep learning?

对于变分推理(如 Backprop 在贝叶斯中所做的那样)Batchnorm 很好。对于 MCMC 等采样方法,Batch normalization 不再适用。查看 https://arxiv.org/pdf/1908.03491v1.pdf 以获取有关批量规范适用性的信息,其中采样方法约为。贝叶斯推理。