8000 `tensorflow`: add `tensorflow.keras.activations` members by hoel-bagard · Pull Request #11444 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

tensorflow: add tensorflow.keras.activations members #11444

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

Merged

Conversation

hoel-bagard
Copy link
Contributor

No description provided.

This comment has been minimized.

@hoel-bagard hoel-bagard marked this pull request as ready for review February 18, 2024 14:19

This comment has been minimized.

This comment has been minimized.

threshold: FloatTensorCompatible | FloatDataSequence = 0.0,
) -> Tensor: ...
def selu(x: _ActivationInput) -> Tensor: ...
def serialize(activation: Callable[..., Any], use_legacy_format: bool = False) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can also return a dict:

In [15]: tensorflow.keras.activations.serialize(len)
Out[15]: 
{'module': 'builtins',
 'class_name': 'builtin_function_or_method',
 'config': 'len',
 'registered_name': 'builtin_function_or_method'}

In [16]: tensorflow.keras.activations.serialize(lambda: 42)
/Users/jelle/py/venvs/py311/lib/python3.11/site-packages/keras/src/activations.py:549: UserWarning: The object being serialized includes a `lambda`. This is unsafe. In order to reload the object, you will have to pass `safe_mode=False` to the loading function. Please avoid using `lambda` in the future, and use named Python functions instead. This is the `lambda` being serialized: tensorflow.keras.activations.serialize(lambda: 42)

  fn_config = serialization_lib.serialize_keras_object(activation)
Out[16]: 
{'value': ('4wAAAAAAAAAAAAAAAAEAAAADAAAA8wYAAACXAGQBUwApAk7pKgAAAKkAcgMAAADzAAAAAPofPGlw\neXRob24taW5wdXQtMTYtYjFiYzU1YjgzOGViPvoIPGxhbWJkYT5yBgAAAAEAAABzBgAAAIAAqHKA\nAHIEAAAA\n',
  None,
  None)}

In [17]: tensorflow.keras.activations.serialize(os.path.exists)
Out[17]: 
{'module': 'builtins',
 'class_name': 'function',
 'config': 'exists',
 'registered_name': 'function'}

Copy link
Contributor Author
@hoel-bagard hoel-bagard Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra Thanks for pointing it out, I've fixed it in d25b89f. Do you have a method / tool to find this kind of errors ?
For this particular function, looking at the source code would have made it clear that the return type could be a dict. Is it how you found out about it ?

When doing the TensorFlow stubs, I usually try a few inputs, but I can't test everything, so I often rely on what the docs say 😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just by trying it out. I didn't do that for all functions, I think at first I was mostly curious what this function would do with a builtin.

This comment has been minimized.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit ea2002d into python:main Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0