Skip to content

Implement MLTransform One-Hot Encoding benchmark pipeline#38404

Open
aIbrahiim wants to merge 3 commits intoapache:masterfrom
aIbrahiim:mltransform-onehot-benchmark
Open

Implement MLTransform One-Hot Encoding benchmark pipeline#38404
aIbrahiim wants to merge 3 commits intoapache:masterfrom
aIbrahiim:mltransform-onehot-benchmark

Conversation

@aIbrahiim
Copy link
Copy Markdown
Contributor

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@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 introduces a new benchmark pipeline for categorical feature encoding using Apache Beam's MLTransform. The changes include the pipeline implementation, supporting test suites, and the necessary infrastructure to integrate performance tracking and cost estimation into the Beam website's performance dashboard.

Highlights

  • New MLTransform Pipeline: Implemented a categorical encoding pipeline using MLTransform's ComputeAndApplyVocabulary transform to convert categorical features into integer indices.
  • Testing and Benchmarking: Added comprehensive unit and integration tests, along with a new Dataflow benchmark to track throughput, latency, and cost metrics.
  • Documentation and Metrics: Updated the project website to include a new performance dashboard page and configured Looker metrics for the new benchmark.
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.

Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/beam_Inference_Python_Benchmarks_Dataflow.yml
    • .github/workflows/load-tests-pipeline-options/beam_Inference_Python_Benchmarks_Dataflow_MLTransform_One_Hot_Encoding_Batch.txt
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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 a new example and benchmark for MLTransform One-Hot Encoding in the Python SDK, including performance tracking and documentation updates. Review feedback points out several issues: unit tests for a non-existent function that cause failures, the need for a filter to handle missing columns and prevent pipeline crashes, and opportunities to optimize synthetic data generation and improve logging for text-based inputs.

Comment on lines +83 to +95
def test_validate_columns_present_all_present(self):
"""Test column validation when all columns are present."""
element = {'category': 'a', 'color': 'b', 'size': 'c'}
result = mltransform_one_hot_encoding.validate_columns_present(
element, ['category', 'color'])
self.assertTrue(result)

def test_validate_columns_present_missing(self):
"""Test column validation when some columns are missing."""
element = {'category': 'a'}
result = mltransform_one_hot_encoding.validate_columns_present(
element, ['category', 'color'])
self.assertFalse(result)
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.

critical

These tests for validate_columns_present are failing because the function does not exist in the mltransform_one_hot_encoding module. This validation logic is an implementation detail of the pipeline and its behavior is better tested via an end-to-end test like test_pipeline_with_missing_columns. These unit tests should be removed.

Comment on lines +186 to +189
transformed_data = (
raw_data
| 'MLTransform' >> ml_transform
| 'FormatOutput' >> beam.Map(format_json_output))
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

The pipeline will fail if input records are missing any of the specified categorical_columns, as MLTransform requires all columns to be present. The tests suggest that invalid records should be filtered out. To make the pipeline more robust, a beam.Filter transform should be added to remove records with missing columns before they are processed by MLTransform.

Suggested change
transformed_data = (
raw_data
| 'MLTransform' >> ml_transform
| 'FormatOutput' >> beam.Map(format_json_output))
transformed_data = (
raw_data
| 'ValidateAndFilterColumns' >> beam.Filter(
lambda element: all(col in element for col in categorical_columns))
| 'MLTransform' >> ml_transform
| 'FormatOutput' >> beam.Map(format_json_output))

Comment on lines +157 to +158
else:
parse_input_fn = lambda line: parse_text_line(line, categorical_columns)
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

When input_format is text, the pipeline implicitly uses only the first categorical column, which might be unexpected for users who provide multiple columns. To improve clarity and prevent potential confusion, it's good practice to log a warning in this scenario.

Suggested change
else:
parse_input_fn = lambda line: parse_text_line(line, categorical_columns)
else:
if len(categorical_columns) > 1:
logging.warning(
'Input format is "text" but multiple categorical columns are '
'specified. Only the first column "%s" will be used for '
'parsing.', categorical_columns[0])
parse_input_fn = lambda line: parse_text_line(line, categorical_columns)

Comment on lines +168 to +175
raw_data = (
pipeline
| 'GenerateSyntheticData' >> beam.Create([None])
| 'ExpandSyntheticIndexes' >> beam.FlatMap(lambda _: range(num_records))
| 'BuildSyntheticRecord' >> beam.Map(
lambda idx: json.dumps(generate_synthetic_record(
idx, categorical_columns)))
| 'ParseSyntheticJSON' >> beam.Map(parse_json_line))
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

The current method for generating synthetic data is inefficient. It creates a single element, expands it to the desired number of records, converts each record to a JSON string, and then parses it back into a dictionary. This can be simplified and made more performant by directly generating the dictionaries.

    raw_data = (
        pipeline
        | 'GenerateIndexes' >> beam.Create(range(num_records))
        | 'BuildSyntheticRecord' >> beam.Map(
            lambda idx: generate_synthetic_record(idx, categorical_columns)))

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

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

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.

1 participant