TensorFlow 概率层(例如 DenseFlipout )有一个 losses
方法(或属性),用于获取“与该层相关的损失”。有人可以解释一下这些损失是什么吗?
浏览 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 中提供,将损失
相加得到 KL 项,并单独计算对数似然项,并与 KL 项组合形成 ELBO。
您可以看到损失被添加here经过一些间接的处理后,我们发现正在使用 {kernel,bias}_divergence_fn
,并且默认为调用 tfd.kl_divergence 的
。lambda
(q,p)
关于python - 在 TensorFlow Probability 中,与贝叶斯层的损失属性相关的损失是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54101971/