fix(softmax): validate mask shape matches inputs shape#22295
fix(softmax): validate mask shape matches inputs shape#22295hertschuh merged 2 commits intokeras-team:masterfrom
Conversation
Summary of ChangesHello @rstar327, 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 addresses a potential silent failure in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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.
Code Review
This pull request adds a validation check in the Softmax layer to ensure that the mask has the same shape as the inputs. If the shapes do not match, a ValueError is raised. This prevents silent broadcasting and incorrect output shapes. A corresponding test case is also added to verify this behavior. The change is correct and well-tested. I have one suggestion to improve the readability of the error message to better align with the Keras API design guidelines.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22295 +/- ##
==========================================
- Coverage 82.94% 82.94% -0.01%
==========================================
Files 594 595 +1
Lines 65361 66085 +724
Branches 10213 10316 +103
==========================================
+ Hits 54211 54811 +600
- Misses 8526 8658 +132
+ Partials 2624 2616 -8
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:
|
hertschuh
left a comment
There was a problem hiding this comment.
Thanks for working on this!
|
Done, updated validation to allow broadcastable masks while disallowing masks larger than inputs. |
Summary
Softmax.call()whenmaskis providednumpy.where, producing wrong output shapeValueErrorwith a clear message when shapes don't matchFixes #19722