-
Notifications
You must be signed in to change notification settings - Fork 74.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tf.keras.backend.sqrt(tf.constant(-1.0)) is 0 which is misleading and tf.sqrt(tf.constant(-1.0)) is 'nan' which is the way it should be. #34165
Comments
As you can see from the source code tf.keras.backend.sqrt clips the input value to zero if its less than 0 and to infinity if its equal to infinity as shown by the function here. This is the reason why the output is zero But in tf.sqrt the sqrt function is from gen_math_ops.py which has a different behaviour i.e., behaviour similar to numpy and thats the reason why its value is defaulted to NaN |
But developers usually expect the tensorflow to return nan when tf.sqrt( negative numbers) is done, as thats the norm unlike returning 0, which defies the name of the function. Or, I would request you to update the documentation just to avoid the confusion as tensorflow is moving towards keras. |
Sure @saikumarGadde |
@MarkDaoust Is this issue is solved? Thanks. |
@saikumarGadde: Yes, you have a point but: we need to be very conservative about changing the behavior of existing functions. Also and what is the goal of using At this point That's why fchollet removed the documentation for these in: 91e5ad0#diff-e329ed6b8d30dca9a441689005047035 https://www.tensorflow.org/api_docs/python/tf/keras/backend?version=nightly The functions will still be available in the package but they are undocumented to communicate that they should not be used. |
System information
Describe the current behavior
tf.keras.backend.sqrt(tf.constant(-1.0)) returns 0 as clip_by_value is being done in the source code (Which is highly misleading, as can be seen only in the source and not in the function document) whereas tf.sqrt(tf.constant(-1.0)) returns 'nan' which is the expected behavior of any sqrt function. This causes some bugs which are very difficult to track.
Describe the expected behavior
Make sqrt functions return only the expected behavior and remove the clip_by_value.
Code to reproduce the issue
import tensorflow as tf
tf.enable_eager_execution()
tf.keras.backend.sqrt(tf.constant(-1.0)).numpy()
tf.sqrt(tf.constant(-1.0)).numpy()
Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
The text was updated successfully, but these errors were encountered: