在张量流概率中,与贝叶斯层的损失特性相关的损失是什么?

2024-04-19 08:06:17 发布

您现在位置:Python中文网/ 问答频道 /正文

TensorFlow概率层(例如DenseFlipout)有一个losses方法(或属性),可以得到“与该层相关的损失”。有人能解释这些损失是什么吗?你知道吗

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


Tags: 方法属性tensorflow概率paper权重偏差损失
1条回答
网友
1楼 · 发布于 2024-04-19 08:06:17

你的怀疑是正确的,尽管没有充分的证据。例如,在下面的一段代码中

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 ^{} layer中提供,将losses求和以得到KL项,并且单独计算对数似然项,并且与KL项组合以形成ELBO。你知道吗

您可以看到添加的损失here,在一些间接操作之后,显示正在使用{kernel,bias}_divergence_fn,而这又默认为调用tfd.kl_divergence(q, p)lambda。你知道吗

相关问题 更多 >