-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Fix noise_shape validation in keras.layers.Dropout #21819
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @Abhinavexists, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the stability and predictability of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces input validation for the noise_shape parameter in the Dropout layer, which is a great addition for improving the layer's robustness. The implementation is clean and handles various invalid inputs correctly by raising ValueError with descriptive messages. I have one suggestion to refine an error message to be more precise, aligning it even better with the code's behavior and the Keras API design guidelines. Overall, this is a valuable improvement.
| raise ValueError( | ||
| f"Invalid value received for argument `noise_shape`. " | ||
| f"Expected a tuple or list of integers. " | ||
| f"Received: noise_shape={noise_shape}" | ||
| ) |
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 error message here states that noise_shape is expected to be a "tuple or list of integers". However, the code correctly attempts to convert any iterable to a tuple by calling tuple(noise_shape). To avoid potential confusion for users who might pass another valid iterable type (like a set or a generator), it would be more accurate to mention "iterable" in the error message. This change would make the feedback more precise, which is encouraged by the Keras API design guidelines.1
| raise ValueError( | |
| f"Invalid value received for argument `noise_shape`. " | |
| f"Expected a tuple or list of integers. " | |
| f"Received: noise_shape={noise_shape}" | |
| ) | |
| raise ValueError( | |
| f"Invalid value received for argument `noise_shape`. " | |
| f"Expected an iterable of integers (e.g., a tuple or list). " | |
| f"Received: noise_shape={noise_shape}" | |
| ) |
Style Guide References
Footnotes
-
Error messages should be contextual, informative, and actionable. A good error message should clearly and precisely state what was expected to help the user fix the issue. ↩
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21819 +/- ##
==========================================
- Coverage 82.67% 82.66% -0.02%
==========================================
Files 577 577
Lines 59429 59444 +15
Branches 9315 9321 +6
==========================================
+ Hits 49131 49137 +6
- Misses 7898 7904 +6
- Partials 2400 2403 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix: #21768
added input validation for the noise_shape parameter in
keras.layers.Dropoutto prevent invalid values from being passed at layer initialization time.This is an initial implementation focusing on basic validation logic. The implementation
intentionally:
iteration)