AnandInguva commented on code in PR #30002:
URL: https://github.com/apache/beam/pull/30002#discussion_r1464102420


##########
sdks/python/apache_beam/yaml/yaml_ml.py:
##########
@@ -0,0 +1,65 @@
+#
+# 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 module defines yaml wrappings for some ML transforms."""
+
+from typing import Any
+from typing import List
+from typing import Optional
+
+import apache_beam as beam
+from apache_beam.yaml import options
+
+try:
+  from apache_beam.ml.transforms import tft
+  from apache_beam.ml.transforms.base import MLTransform
+  # TODO(robertwb): Is this all of them?

Review Comment:
   There are embeddings present at 
https://github.com/apache/beam/tree/330a632fefbe2aca5dbf220295e19621a9ae307a/sdks/python/apache_beam/ml/transforms/embeddings



##########
sdks/python/apache_beam/yaml/yaml_ml.py:
##########
@@ -0,0 +1,65 @@
+#
+# 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 module defines yaml wrappings for some ML transforms."""
+
+from typing import Any
+from typing import List
+from typing import Optional
+
+import apache_beam as beam
+from apache_beam.yaml import options
+
+try:
+  from apache_beam.ml.transforms import tft
+  from apache_beam.ml.transforms.base import MLTransform
+  # TODO(robertwb): Is this all of them?
+  _transform_constructors = tft.__dict__
+except ImportError:
+  tft = None
+
+
+def _config_to_obj(spec):
+  if 'type' not in spec:
+    raise ValueError(r"Missing type in ML transform spec {spec}")
+  if 'config' not in spec:
+    raise ValueError(r"Missing config in ML transform spec {spec}")
+  constructor = _transform_constructors.get(spec['type'])
+  if constructor is None:
+    raise ValueError("Unknown ML transform type: %r" % spec['type'])
+  return constructor(**spec['config'])
+
+
[email protected]_fn
+def ml_transform(
+    pcoll,
+    write_artifact_location: Optional[str] = None,
+    read_artifact_location: Optional[str] = None,
+    transforms: Optional[List[Any]] = None):
+  if tft is None:

Review Comment:
   for embeddings based transforms, this might not be relevant. 
   
   Also, the modules (tft, embeddings(sentence-transformers)) throw error when 
they are not installed. We can remove this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to