-
Notifications
You must be signed in to change notification settings - Fork 118
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
Enhanced Docstrings and Examples in /ops/function.py, /ops/math.py and /ops/nn.py. #736
Conversation
Thank you for your patience, I'm starting to understand GitHub slowly :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
keras_core/ops/function.py
Outdated
@@ -180,7 +180,7 @@ def map_graph(inputs, outputs): | |||
|
|||
Returns: | |||
A tuple `(nodes, nodes_by_depth, operations, operations_by_depth)`. | |||
- nodes: list of Node instances. | |||
- network_nodes:dict mapping the unique node keys to the Node instances |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space after :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
keras_core/ops/math.py
Outdated
>>> segment_ids = keras_core.ops.convert_to_tensor([0, 1, 0, 1, 0, 1]) | ||
>>> segment_sum(data, segment_ids) | ||
array([9 12], shape=(2,), dtype=int32) | ||
>>> data = keras_core.ops.convert_to_tensor([1,2,10,20,100,200]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the issue with the initial code example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was that the example does not work with the JAX backend.
`ValueError: Argument 'num_segments' must be set when using the JAX backend. Received: num_segments=None
So, I have changed it to an easier-to-understand example, and now it is working with all backends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good -- please make sure to format the code in the black
style, e.g. spaces after ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, Now i am using pip install black and this tool https://black.vercel.app/
keras_core/ops/math.py
Outdated
>>> segment_max(data, segment_ids) | ||
array([9 12], shape=(2,), dtype=int32) | ||
""" | ||
>>> data = keras_core.ops.convert_to_tensor([1,2,10,20,100,200]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, the problem was that the example didn't work with the JAX backend. It raised a ValueError: Argument 'num_segments' must be set when using the JAX backend. Received: num_segments=None.
The second issue was that the output is incorrect; it seemed as if it was copied from segment_sum.
To address these, I've modified the example to make it more understandable, and it now functions correctly with all backends."
keras_core/ops/math.py
Outdated
>>> rsqrt(x) | ||
""" | ||
|
||
>>> data = keras_core.ops.convert_to_tensor([1.0,10.0,100.0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use spaces are ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
keras_core/ops/math.py
Outdated
|
||
>>> data = keras_core.ops.convert_to_tensor([1.0,10.0,100.0]) | ||
>>> keras_core.ops.rsqrt(data) | ||
Array([1. , 0.31622776, 0.1 ], dtype=float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use array
(lowercase) and trim whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
keras_core/ops/nn.py
Outdated
@@ -1501,6 +1501,31 @@ def compute_output_spec(self, inputs): | |||
] | |||
) | |||
def multi_hot(inputs, num_tokens, axis=-1, dtype=None): | |||
""" | |||
Encodes integer labels as multi-hot vectors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I will be more than happy to write, enhance, and check all the docstrings. Additionally, I'll add examples that are easy to understand and compatible with all backends. Please let me know if that sounds good. @fchollet |
keras_core/ops/math.py
Outdated
>>> segment_ids = keras_core.ops.convert_to_tensor([0, 1, 0, 1, 0, 1]) | ||
>>> segment_sum(data, segment_ids) | ||
array([9 12], shape=(2,), dtype=int32) | ||
>>> data = keras_core.ops.convert_to_tensor([1,2,10,20,100,200]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good -- please make sure to format the code in the black
style, e.g. spaces after ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
keras_core/ops/math.py
Outdated
>>> segment_ids = keras_core.ops.convert_to_tensor([0, 1, 0, 1, 0, 1]) | ||
>>> segment_sum(data, segment_ids) | ||
array([9 12], shape=(2,), dtype=int32) | ||
>>> data = keras_core.ops.convert_to_tensor([1,2,10,20,100,200]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, Now i am using pip install black and this tool https://black.vercel.app/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Great now I am using black python library and this website https://black.vercel.app/ for formatting. |
My next step will be to check all the functions docstring and then discuss with you a standard way to write them even the order including examples and reference and so on |
Once you have installed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!
keras_core/ops/math.py
Outdated
>>> segment_ids = keras_core.ops.convert_to_tensor([0, 1, 0, 1, 0, 1]) | ||
>>> segment_max(data, segment_ids) | ||
array([9 12], shape=(2,), dtype=int32) | ||
>>> data = keras_core.ops.convert_to_tensor([1, 2, 10, 20, 100, 200]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unindent: the code example should have the indent as the rest of the docstring
keras_core/ops/math.py
Outdated
@@ -688,16 +690,17 @@ def stft( | |||
class Rsqrt(Operation): | |||
"""Computes reciprocal of square root of x element-wise. | |||
|
|||
Args: | |||
x: input tensor | |||
Args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, fix indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Main Changes:
My target to add very easy to understand examples.