diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index 0bd9aa8b5401..fddb4081a778 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -659,7 +659,10 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float if len(y_true) != len(y_pred): raise ValueError("Input arrays must have the same length.") - kl_loss = y_true * np.log(y_true / y_pred) + kl_loss = 0 + if y_true != 0: + kl_loss = y_true * np.log(y_true / y_pred) + return np.sum(kl_loss)