-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MLTransform #26795
Merged
Merged
MLTransform #26795
Changes from 27 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
6c641ec
Initial work on MLTransform and ProcessHandler
AnandInguva 9c93dc0
Support for containers: List, Dict[str, np.ndarray]
AnandInguva 89e889d
Add min, max, artifacts for scale_0_to_1
AnandInguva 5548103
Add more transform functions and artifacts
AnandInguva f5d050a
Add generic type annotations
AnandInguva 6681916
Add unit tests
AnandInguva 3be1cfd
Add support for saving intermediate results for a transform
AnandInguva 6caba7e
Add schema to the output PCollection
AnandInguva 901a74c
Remove MLTransformOutput and return Row instead with schema
AnandInguva 361e0bb
Convert primitive type to list using a DoFn. Remove FixedLenFeatureSpec
AnandInguva 681d164
Add append_transform to the ProcessHandler
AnandInguva eac8b3f
Remove param self.has_artifacts, add artifact_location to handler..an…
AnandInguva 011d5d1
Move tensorflow import into the try except catch
AnandInguva def7eb4
Add type annotations for the data transforms
AnandInguva 1a0a0ed
Add tft test in tox.ini
AnandInguva 2393254
Add step name for TFTProcessHandler
AnandInguva f25618e
Remove unsupported tft versions
AnandInguva 4256c99
Fix mypy
AnandInguva df73361
Refactor TFTProcessHandlerDict to TFTProcessHandlerSchema
AnandInguva 4497bb5
Update doc for data processing transforms
AnandInguva 77b3634
Fix checking the typing container types
AnandInguva baf1ae7
Refactor code
AnandInguva 044f509
Fail TFTProcessHandler on a non-global window PColl
AnandInguva c312aef
Remove underscore
AnandInguva 68a2529
Remove high level functions
AnandInguva e6ef468
Add TFIDF
AnandInguva 2be4ba6
Fix tests with new changes[WIP]
AnandInguva 7a290e2
Fix tests
AnandInguva c2a1fae
Refactor class name to CamelCase and remove kwrags
AnandInguva 21dadb1
use is_default instead of isinstance
AnandInguva df05169
Remove falling back to staging location for artifact location
AnandInguva 42fd6c4
Add TFIDF tests
AnandInguva 5c6dcb4
Remove __str__
AnandInguva 43d24ad
Refactor skip statement
AnandInguva 618b2fa
Add utils for fetching artifacts on compute and apply vocab
AnandInguva a814650
Make ProcessHandler internal class
AnandInguva 0a61955
Only run analyze stage when transform_fn(artifacts) is not computed b…
AnandInguva 33f8fb2
Fail if pipeline has non default window during artifact producing stage
AnandInguva bc22e9f
Add support for Dict, recordbatch and introduce artifact_mode
AnandInguva 4e07f7d
Hide process_handler from user. Make TFTProcessHandler as default
AnandInguva eeed56c
Refactor few tests
AnandInguva 9eed989
Comment a test
AnandInguva 3453b9f
Save raw_data_meta_data so that it can be used during consume stage
AnandInguva 3e8f198
Refactor code
AnandInguva e8a3686
Add test on artifacts
AnandInguva 72ea029
Fix imports
AnandInguva 55b04e8
Add tensorflow_metadata to pydocs
AnandInguva b65ff05
Merge remote-tracking branch 'upstream/master' into mltransform
AnandInguva 00fb944
Fix test
AnandInguva f11d02b
Add TFIDF to import
AnandInguva 7b2200f
Add basic example
AnandInguva bca2dda
Remove redundant logging statements
AnandInguva 295a80d
Add test for multiple columns on MLTransform
AnandInguva 1d0b5b1
Add todo about what to do when new process handler is introduced
AnandInguva 64bba5e
Add abstractmethod decorator
AnandInguva 034a066
Edit Error message
AnandInguva 1eef0e7
Update docs, error messages
AnandInguva 4ed94c7
Remove record batch input/output arg
AnandInguva 2e6c5ac
Modify generic types
AnandInguva bf81d46
Fix import sort
AnandInguva 0860489
Merge remote-tracking branch 'upstream/master' into mltransform
AnandInguva 1dcdaa8
Fix mypy errors - best effort
AnandInguva bb9336a
Fix tests
AnandInguva 17a4eb1
Add TFTOperation doc
AnandInguva 20f416d
Rename tft_transform to tft
AnandInguva ba33cb7
Fix hadler_test
AnandInguva f0c023b
Fix base_test
AnandInguva a315091
Fix pydocs
AnandInguva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Generic | ||
from typing import TypeVar | ||
|
||
import apache_beam as beam | ||
|
||
# TODO: Abstract methods are not getting pickled with dill. | ||
# https://github.com/uqfoundation/dill/issues/332 | ||
# import abc | ||
|
||
__all__ = ['MLTransform', 'ProcessHandler'] | ||
|
||
TransformedDatasetT = TypeVar('TransformedDatasetT') | ||
TransformedMetadataT = TypeVar('TransformedMetadataT') | ||
|
||
# Input/Output types to the MLTransform. | ||
ExampleT = TypeVar('ExampleT') | ||
MLTransformOutputT = TypeVar('MLTransformOutputT') | ||
|
||
# Input to the process data. This could be same or different from ExampleT. | ||
damccorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ProcessInputT = TypeVar('ProcessInputT') | ||
# Output of the process data. This could be same or different | ||
# from MLTransformOutputT | ||
ProcessOutputT = TypeVar('ProcessOutputT') | ||
|
||
# Input to the apply() method of BaseOperation. | ||
OperationInputT = TypeVar('OperationInputT') | ||
# Output of the apply() method of BaseOperation. | ||
OperationOutputT = TypeVar('OperationOutputT') | ||
|
||
|
||
class BaseOperation(Generic[OperationInputT, OperationOutputT]): | ||
def apply( | ||
self, inputs: OperationInputT, column_name: str, *args, | ||
**kwargs) -> OperationOutputT: | ||
""" | ||
Define any processing logic in the apply() method. | ||
processing logics are applied on inputs and returns a transformed | ||
output. | ||
Args: | ||
inputs: input data. | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class ProcessHandler(Generic[ProcessInputT, ProcessOutputT]): | ||
def process_data( | ||
self, pcoll: beam.PCollection[ProcessInputT] | ||
) -> beam.PCollection[ProcessOutputT]: | ||
""" | ||
Logic to process the data. This will be the entrypoint in | ||
beam.MLTransform to process incoming data. | ||
""" | ||
raise NotImplementedError | ||
|
||
def append_transform(self, transform: BaseOperation): | ||
raise NotImplementedError | ||
|
||
|
||
class MLTransform(beam.PTransform[beam.PCollection[ExampleT], | ||
beam.PCollection[MLTransformOutputT]], | ||
Generic[ExampleT, MLTransformOutputT, ]): | ||
AnandInguva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def __init__( | ||
self, | ||
process_handler: ProcessHandler[ExampleT, MLTransformOutputT], | ||
): | ||
""" | ||
Args: | ||
process_handler: A ProcessHandler instance that defines the logic to | ||
process the data. | ||
""" | ||
self._process_handler = process_handler | ||
|
||
def expand( | ||
self, pcoll: beam.PCollection[ExampleT] | ||
) -> beam.PCollection[MLTransformOutputT]: | ||
""" | ||
This is the entrypoint for the MLTransform. This method will | ||
invoke the process_data() method of the ProcessHandler instance | ||
to process the incoming data. | ||
|
||
process_data takes in a PCollection and applies the PTransforms | ||
necessary to process the data and returns a PCollection of | ||
transformed data. | ||
Args: | ||
pcoll: A PCollection of ExampleT type. | ||
Returns: | ||
A PCollection of MLTransformOutputT type. | ||
""" | ||
return self._process_handler.process_data(pcoll) | ||
|
||
def with_transform(self, transform: BaseOperation): | ||
""" | ||
Add a transform to the MLTransform pipeline. | ||
Args: | ||
transform: A BaseOperation instance. | ||
Returns: | ||
A MLTransform instance. | ||
""" | ||
self._process_handler.append_transform(transform) | ||
return self |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this TODO still apply? What are the consequences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not relevant anymore. I tried today and I wasn't able to reproduce it now