diff --git a/mlp/errors.py b/mlp/errors.py index 5ef95f7..a61b757 100644 --- a/mlp/errors.py +++ b/mlp/errors.py @@ -154,7 +154,7 @@ class CrossEntropySoftmaxError(object): Returns: Scalar error function value. """ - probs = np.exp(outputs) + probs = np.exp(outputs - outputs.max(-1)[:, None]) probs /= probs.sum(-1)[:, None] return -np.mean(np.sum(targets * np.log(probs), axis=1)) @@ -168,7 +168,7 @@ class CrossEntropySoftmaxError(object): Returns: Gradient of error function with respect to outputs. """ - probs = np.exp(outputs) + probs = np.exp(outputs - outputs.max(-1)[:, None]) probs /= probs.sum(-1)[:, None] return (probs - targets) / outputs.shape[0]