Implement MLTransform One-Hot Encoding benchmark pipeline#38404
Implement MLTransform One-Hot Encoding benchmark pipeline#38404aIbrahiim wants to merge 3 commits intoapache:masterfrom
Conversation
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 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 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
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 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.
| 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) |
There was a problem hiding this comment.
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.
| transformed_data = ( | ||
| raw_data | ||
| | 'MLTransform' >> ml_transform | ||
| | 'FormatOutput' >> beam.Map(format_json_output)) |
There was a problem hiding this comment.
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.
| 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)) |
| else: | ||
| parse_input_fn = lambda line: parse_text_line(line, categorical_columns) |
There was a problem hiding this comment.
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.
| 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) |
| 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)) |
There was a problem hiding this comment.
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)))|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
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:
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, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.