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
。你知道吗相关问题 更多 >
编程相关推荐