xingyusu's picture
human
7b98f0e
import tensorflow as tf
import tensorflow_probability as tfp
#from https://github.com/kundajelab/basepair/blob/cda0875571066343cdf90aed031f7c51714d991a/basepair/losses.py#L87
def multinomial_nll(true_counts, logits):
"""Compute the multinomial negative log-likelihood
Args:
true_counts: observed count values
logits: predicted logit values
"""
counts_per_example = tf.reduce_sum(true_counts, axis=-1)
dist = tfp.distributions.Multinomial(total_count=counts_per_example,
logits=logits)
return (-tf.reduce_sum(dist.log_prob(true_counts)) /
tf.cast(tf.shape(true_counts)[0], dtype=tf.float32))