From 5d50fa5c60e4284ea8e0592518cf4f600f1e20fa Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 2 Jan 2020 08:13:45 -0500 Subject: [PATCH 1/4] Add more documentation + usage example for sigmoid --- tensorflow/python/ops/math_ops.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tensorflow/python/ops/math_ops.py b/tensorflow/python/ops/math_ops.py index 0ca39af2ed2379..9ffd09b9734bd6 100644 --- a/tensorflow/python/ops/math_ops.py +++ b/tensorflow/python/ops/math_ops.py @@ -3204,6 +3204,12 @@ def sigmoid(x, name=None): """Computes sigmoid of `x` element-wise. Specifically, `y = 1 / (1 + exp(-x))`. + + The sigmoid function is a function that outputs between `[0, 1]` and is often used as the logistic activation function of the last layer in a classification model. + This is due to the nature of its range - for values of `x` that are positive, the function outputs a value `> 0.5` (and as `x` approaches infinity, the value + approaches `1`), and for values of `x` that are negative, the function outputs a value `< 0.5` (and as `x` approaches negative infinity, the value approaches `0`). + At `x = 0`, the value is `0.5`. Due to this behavior, the sigmoid function is often used to map a tensor to a list of probabilities (since probabilities, as well, + are between `[0, 1]`). Args: x: A Tensor with type `float16`, `float32`, `float64`, `complex64`, or @@ -3212,6 +3218,15 @@ def sigmoid(x, name=None): Returns: A Tensor with the same type as `x`. + + Usage Example: + + >>> y = tf.math.sigmoid(10.0) + >>> print(y) + tf.Tensor(0.9999546, shape=(), dtype=float32) + >>> y = tf.math.sigmoid(-10.0) + >>> print(y) + tf.Tensor(4.5397872e-05, shape=(), dtype=float32) @compatibility(scipy) Equivalent to scipy.special.expit From 49288595b7cd5d282b76e95bd1098562f68516c8 Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 2 Jan 2020 16:47:33 -0500 Subject: [PATCH 2/4] Fixing floating-point precision and line length --- tensorflow/python/ops/math_ops.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tensorflow/python/ops/math_ops.py b/tensorflow/python/ops/math_ops.py index 9ffd09b9734bd6..442f4976e0b153 100644 --- a/tensorflow/python/ops/math_ops.py +++ b/tensorflow/python/ops/math_ops.py @@ -3205,11 +3205,15 @@ def sigmoid(x, name=None): Specifically, `y = 1 / (1 + exp(-x))`. - The sigmoid function is a function that outputs between `[0, 1]` and is often used as the logistic activation function of the last layer in a classification model. - This is due to the nature of its range - for values of `x` that are positive, the function outputs a value `> 0.5` (and as `x` approaches infinity, the value - approaches `1`), and for values of `x` that are negative, the function outputs a value `< 0.5` (and as `x` approaches negative infinity, the value approaches `0`). - At `x = 0`, the value is `0.5`. Due to this behavior, the sigmoid function is often used to map a tensor to a list of probabilities (since probabilities, as well, - are between `[0, 1]`). + The sigmoid function is a function that outputs between `[0, 1]` and is often + used as the logistic activation function of the last layer in a + classification model. This is due to the nature of its range - for values of + `x` that are positive, the function outputs a value `> 0.5` (and as `x` + approaches infinity, the value approaches `1`), and for values of `x` that + are negative, the function outputs a value `< 0.5` (and as `x` approaches + negative infinity, the value approaches `0`). At `x = 0`, the value is `0.5`. + Due to this behavior, the sigmoid function is often used to map a tensor to + a list of probabilities (since probabilities, as well, are between `[0, 1]`). Args: x: A Tensor with type `float16`, `float32`, `float64`, `complex64`, or @@ -3221,12 +3225,12 @@ def sigmoid(x, name=None): Usage Example: - >>> y = tf.math.sigmoid(10.0) + >>> y = tf.math.sigmoid(1.0) >>> print(y) - tf.Tensor(0.9999546, shape=(), dtype=float32) - >>> y = tf.math.sigmoid(-10.0) + tf.Tensor(0.73..., shape=(), dtype=float32) + >>> y = tf.math.sigmoid(-1.0) >>> print(y) - tf.Tensor(4.5397872e-05, shape=(), dtype=float32) + tf.Tensor(0.26..., shape=(), dtype=float32) @compatibility(scipy) Equivalent to scipy.special.expit From 492ad53d612f1de38341ee8fd9aaa40fe76a6ccd Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Fri, 10 Jan 2020 11:42:41 -0500 Subject: [PATCH 3/4] Addresses changes --- tensorflow/python/ops/math_ops.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tensorflow/python/ops/math_ops.py b/tensorflow/python/ops/math_ops.py index 442f4976e0b153..f07a7bede7d692 100644 --- a/tensorflow/python/ops/math_ops.py +++ b/tensorflow/python/ops/math_ops.py @@ -3203,7 +3203,7 @@ def _accumulate_n_grad(op, grad): def sigmoid(x, name=None): """Computes sigmoid of `x` element-wise. - Specifically, `y = 1 / (1 + exp(-x))`. + Specifically, computes `y = 1 / (1 + exp(-x))`. The sigmoid function is a function that outputs between `[0, 1]` and is often used as the logistic activation function of the last layer in a @@ -3213,7 +3213,7 @@ def sigmoid(x, name=None): are negative, the function outputs a value `< 0.5` (and as `x` approaches negative infinity, the value approaches `0`). At `x = 0`, the value is `0.5`. Due to this behavior, the sigmoid function is often used to map a tensor to - a list of probabilities (since probabilities, as well, are between `[0, 1]`). + a list of probabilities (since probabilities are also between `[0, 1]`). Args: x: A Tensor with type `float16`, `float32`, `float64`, `complex64`, or @@ -3225,11 +3225,9 @@ def sigmoid(x, name=None): Usage Example: - >>> y = tf.math.sigmoid(1.0) - >>> print(y) + >>> tf.math.sigmoid(1.0) tf.Tensor(0.73..., shape=(), dtype=float32) - >>> y = tf.math.sigmoid(-1.0) - >>> print(y) + >>> tf.math.sigmoid(-1.0) tf.Tensor(0.26..., shape=(), dtype=float32) @compatibility(scipy) From 2c3e7140e000160cdca09db05d13adacf918888c Mon Sep 17 00:00:00 2001 From: Qwerty71 <33108072+Qwerty71@users.noreply.github.com> Date: Thu, 16 Jan 2020 00:31:45 -0500 Subject: [PATCH 4/4] Update math_ops.py --- tensorflow/python/ops/math_ops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/ops/math_ops.py b/tensorflow/python/ops/math_ops.py index f07a7bede7d692..1a75dedb00c4e2 100644 --- a/tensorflow/python/ops/math_ops.py +++ b/tensorflow/python/ops/math_ops.py @@ -3226,9 +3226,9 @@ def sigmoid(x, name=None): Usage Example: >>> tf.math.sigmoid(1.0) - tf.Tensor(0.73..., shape=(), dtype=float32) + >>> tf.math.sigmoid(-1.0) - tf.Tensor(0.26..., shape=(), dtype=float32) + @compatibility(scipy) Equivalent to scipy.special.expit