Skip to content

Added Criteo TFT fill_in_missing helper#39011

Open
lalitx17 wants to merge 3 commits into
apache:masterfrom
lalitx17:fix-criteo-tft-fill-in-missing
Open

Added Criteo TFT fill_in_missing helper#39011
lalitx17 wants to merge 3 commits into
apache:masterfrom
lalitx17:fix-criteo-tft-fill-in-missing

Conversation

@lalitx17

Copy link
Copy Markdown
Contributor

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

@lalitx17 lalitx17 marked this pull request as ready for review June 18, 2026 01:34
Copilot AI review requested due to automatic review settings June 18, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lalitx17

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 Helper Function: Introduced a fill_in_missing helper function to standardize the conversion of optional sparse features into dense rank-1 tensors with default values.
  • Code Refactoring: Updated the Criteo TFT preprocessing logic to utilize the new helper function, replacing redundant boilerplate code.
  • Testing: Added comprehensive unit tests covering present, missing, and all-missing sparse input scenarios.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment on lines +51 to +54
feature = tf.sparse.to_dense(
tf.SparseTensor(
feature.indices, feature.values, [feature.dense_shape[0], 1]),
default_value=default_value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment on lines +51 to +55
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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)

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@lalitx17

Copy link
Copy Markdown
Contributor Author

assign set of reviewers

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants