From ee0f8895df800b3f55c4720d0dfb9f44ca6e8eda Mon Sep 17 00:00:00 2001 From: Lukas Eller Date: Fri, 10 Nov 2023 08:29:17 +0100 Subject: [PATCH] Upload New File --- helpers/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 helpers/utils.py diff --git a/helpers/utils.py b/helpers/utils.py new file mode 100644 index 0000000..818fb71 --- /dev/null +++ b/helpers/utils.py @@ -0,0 +1,14 @@ +import tensorflow as tf + +@tf.function +def logsumexp10(x, alpha=1): + c = tf.reshape(tf.reduce_max(x, axis=1), (-1, 1)) + return tf.cast(c, tf.float32)[:, 0] + 10 * tf.cast( + tf.math.log( + tf.reduce_sum( + alpha * 10**((x - c)/10), + axis=1 + ) + ), + tf.float32 + ) / tf.math.log(10.) -- 2.22.0