def kl_for_log_probs(log_p, log_q):
p = tf.exp(log_p)
neg_ent = tf.reduce_sum(p * log_p, axis=-1)
neg_cross_ent = tf.reduce_sum(p * log_q, axis=-1)
kl = neg_ent - neg_cross_ent
return
传log_probs = tf.nn.log_softmax(logits, axis=-1)
微信扫一扫
def kl_for_log_probs(log_p, log_q):
p = tf.exp(log_p)
neg_ent = tf.reduce_sum(p * log_p, axis=-1)
neg_cross_ent = tf.reduce_sum(p * log_q, axis=-1)
kl = neg_ent - neg_cross_ent
return
传log_probs = tf.nn.log_softmax(logits, axis=-1)
相关推荐