From 23a8059f8e3a49147fcc3ab57af4b91fc2907dca Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Wed, 18 Oct 2023 14:25:08 +0200 Subject: [PATCH] RF safe_log, better default eps --- returnn/frontend/math_.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/returnn/frontend/math_.py b/returnn/frontend/math_.py index 549d0da2b6..3b9316b2b6 100644 --- a/returnn/frontend/math_.py +++ b/returnn/frontend/math_.py @@ -375,8 +375,10 @@ def log(a: Tensor) -> Tensor: return a._raw_backend.activation(a, "log") -def safe_log(a: Tensor, *, eps: float = 1e-7) -> Tensor: +def safe_log(a: Tensor, *, eps: Optional[float] = None) -> Tensor: """safe_log""" + if eps is None: + eps = numpy.nextafter(numpy.array(0, dtype=a.dtype), numpy.array(1, dtype=a.dtype)) # noinspection PyProtectedMember return a._raw_backend.safe_log(a, eps=eps)