I'm using TensorFlow probability to train a model whose output is a tfp.distributions.Independent object for probabilistic regression. My problem is that I'm unsure how to implement sample weighting in the negative log likelihood (NLL) loss function.
I have the following loss function which I believe does not use the sample_weight third argument:
class NLL(tf.keras.losses.Loss):
''' Custom keras loss/metric for negative log likelihood '''
def __call__(self, y_true, y_pred, sample_weight=None):
return -y_pred.log_prob(y_true)
With standard TensorFlow loss functions and a dataset containing (X, y, sample_weight) tuples, the use of sample_weight in the loss reductions summations is handled under the hood. How can I make the sum in y_pred.log_prob use the weights in the sample_weight tensor?