Added Criteo TFT fill_in_missing helper#39011
Conversation
|
/gemini review |
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 improves the maintainability of the Criteo TFT preprocessing pipeline by abstracting common sparse-to-dense conversion logic into a reusable helper function. This change reduces code duplication and simplifies the preprocessing workflow while ensuring robust handling of missing feature values through newly added unit tests. Highlights
New Features🧠 You can now enable Memory (public preview) 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. 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 the 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 counterproductive. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function fill_in_missing to handle missing values in a rank 2 SparseTensor for the Criteo TFT benchmark, replacing duplicate boilerplate code in preprocessing_fn. It also adds a comprehensive suite of unit tests for this new helper. The review feedback suggests using tf.stack to construct the dense_shape for tf.SparseTensor to avoid potential graph tracing issues when mixing symbolic Tensors and Python integers.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| feature = tf.sparse.to_dense( | ||
| tf.SparseTensor( | ||
| feature.indices, feature.values, [feature.dense_shape[0], 1]), | ||
| default_value=default_value) |
There was a problem hiding this comment.
Using a mixed-type list like [feature.dense_shape[0], 1] as the dense_shape argument for tf.SparseTensor can cause issues during TensorFlow graph tracing (e.g., with tf.function or when exporting models in TFX/TFT), because the list contains a symbolic Tensor and a Python int.
It is safer and more robust to use tf.stack to construct the 1D shape tensor.
| feature = tf.sparse.to_dense( | |
| tf.SparseTensor( | |
| feature.indices, feature.values, [feature.dense_shape[0], 1]), | |
| default_value=default_value) | |
| feature = tf.sparse.to_dense( | |
| tf.SparseTensor( | |
| feature.indices, | |
| feature.values, | |
| tf.stack([feature.dense_shape[0], 1])), | |
| default_value=default_value) |
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function fill_in_missing in criteo.py to handle missing values in sparse tensors, replacing duplicate boilerplate code, and adds comprehensive unit tests in criteo_test.py. The reviewer raised a valid concern regarding a potential runtime crash in fill_in_missing if the input SparseTensor has a column dimension greater than 1, and suggested using tft.sparse_tensor_to_dense_with_shape to safely handle shape alignment.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| feature = tf.sparse.to_dense( | ||
| tf.SparseTensor( | ||
| feature.indices, feature.values, [feature.dense_shape[0], 1]), | ||
| default_value=default_value) | ||
| return tf.squeeze(feature, axis=1) |
There was a problem hiding this comment.
Reconstructing the SparseTensor with a hardcoded shape of [feature.dense_shape[0], 1] can cause runtime crashes if the input SparseTensor has a column dimension greater than 1 (i.e., feature.dense_shape[1] > 1). This can happen if any row in the batch contains more than one value, or if the sparse tensor is parsed with a larger static/dynamic column dimension. In such cases, feature.indices may contain column indices >= 1, which will be out of bounds for the new shape [batch_size, 1], leading to an InvalidArgumentError during tf.sparse.to_dense.\n\nUsing tft.sparse_tensor_to_dense_with_shape is much safer and more robust as it correctly handles shape alignment, padding, and truncation.
feature = tft.sparse_tensor_to_dense_with_shape(\n feature, [None, 1], default_value=default_value)\n return tf.squeeze(feature, axis=1)|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
assign set of reviewers |
|
Assigning reviewers: R: @jrmccluskey for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Added a fill_in_missing helper for Criteo TFT preprocessing to convert optional sparse features into dense rank-1 tensors with default values.
added tests for present, missing, and all-missing sparse inputs.
addresses #24902