Fix one_hot symbolic output shape for IndexLookup#22350
Conversation
Ensure IndexLookup/StringLookup report correct symbolic output shapes for one_hot with nested inputs and add regression tests.
|
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, 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 critical bug where 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
Activity
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 fixes an issue with the symbolic output shape for IndexLookup layers when output_mode="one_hot" is used with nested inputs. The changes correctly preserve the input dimensions in the output shape. The added tests are good and cover the reported issue.
I've found a potential issue with an edge case that is not covered by the new tests. The logic in compute_output_shape for one_hot mode might be inconsistent with the runtime behavior implemented in encode_categorical_inputs when the last dimension of the input shape is 1. My review comment includes a suggestion to address this for better consistency.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
hertschuh
left a comment
There was a problem hiding this comment.
I think the change is correct, however the tests are failing. Can you look into this?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22350 +/- ##
==========================================
+ Coverage 76.76% 82.94% +6.18%
==========================================
Files 595 595
Lines 65839 66084 +245
Branches 10277 10314 +37
==========================================
+ Hits 50540 54813 +4273
+ Misses 12879 8657 -4222
- Partials 2420 2614 +194
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:
|
f0f49e8 to
0bdc7a8
Compare
0bdc7a8 to
7a4021b
Compare
|
@hertschuh Please review my PR, All checks are passed |
|
@hertschuh , Could you check my updates |
|
@hertschuh , Please review my PR |
Summary
Fixes #22336
StringLookupandIntegerLookupwithoutput_mode="one_hot"were returning the wrong symbolic output shape for nested (higher-rank) inputs. Eager execution was correct, but building a model withkeras.Input()produced(None, depth)instead of(None, d1, d2, ..., depth).Changes
keras/src/layers/preprocessing/index_lookup.pyUpdated
compute_output_shape():one_hot: keep all input dimensions and append vocabulary depth →input_shape + (depth,).multi_hot,count,tf_idf: treat the last dimension as the sample dimension →input_shape[:-1] + (depth,).Tests
index_lookup_test.py: regression tests for one_hot symbolic shape and consistency withcompute_output_shape/compute_output_spec.string_lookup_test.py: regression test for StringLookup one_hot with nested input (issue repro).