在 TensorFlow Probability 中,与贝叶斯层的损失 属性 相关的损失是多少?

What are the losses associated with the losses property of the Bayesian layers, in TensorFlow Probability?

TensorFlow Probability 层(例如 DenseFlipout)有一个 losses 方法(或 属性)可以得到 "losses associated with this layer." 有人可以解释这些损失是什么吗?

浏览 Flipout paper 后,我认为损失是指权重和偏差的先验分布和后验分布之间的 Kullback-Leibler 散度。如果有人比我更了解这些事情,请纠正我。

您的怀疑是正确的,尽管没有很好的记录。例如,在下面的一段代码中

import tensorflow_probability as tfp

model = tf.keras.Sequential([
    tfp.layers.DenseFlipout(512, activation=tf.nn.relu),
    tfp.layers.DenseFlipout(10),
])

logits = model(features)
neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(
    labels=labels, logits=logits)

kl = sum(model.losses) # Losses are summed

# The negative log-likelihood and the KL term are combined
loss = neg_log_likelihood + kl 

train_op = tf.train.AdamOptimizer().minimize(loss)

documentation of the DenseFlipout layer中提供,losses求和得到KL项,单独计算对数似然项,与KL项结合形成ELBO。

您可以看到添加的损失 here,经过一些间接寻址,表明正在使用 {kernel,bias}_divergence_fn,而这又默认为 lambda,调用tfd.kl_divergence(q, p).