Skip to content

Commit 69473af

Browse files
committed
embeddings: use scale test validation
1 parent 0ebfdf8 commit 69473af

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

sdks/python/apache_beam/ml/transforms/embeddings/open_ai_it_test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
from apache_beam.ml.transforms import base
2525
from apache_beam.ml.transforms.base import MLTransform
2626

27-
try:
28-
from sdks.python.apache_beam.ml.transforms.embeddings.open_ai import OpenAITextEmbeddings
29-
except ImportError:
30-
OpenAITextEmbeddings = None
27+
from apache_beam.ml.transforms.embeddings.open_ai import OpenAITextEmbeddings
3128

3229
# pylint: disable=ungrouped-imports
3330
try:
3431
import tensorflow_transform as tft
32+
from apache_beam.ml.transforms.tft import ScaleTo01
3533
except ImportError:
3634
tft = None
3735

@@ -76,6 +74,7 @@ def test_embeddings_with_scale_to_0_1(self):
7674
columns=[test_query_column],
7775
api_key=self.api_key,
7876
)
77+
scale_config = ScaleTo01(columns=['embedding'])
7978
with beam.Pipeline() as pipeline:
8079
transformed_pcoll = (
8180
pipeline
@@ -84,10 +83,12 @@ def test_embeddings_with_scale_to_0_1(self):
8483
}])
8584
| "MLTransform" >> MLTransform(
8685
write_artifact_location=self.artifact_location).with_transform(
87-
embedding_config))
86+
embedding_config)).with_transform(scale_config)
8887

8988
def assert_element(element):
90-
assert max(element.feature_1) == 1
89+
embedding_values = element.embedding
90+
assert 0 <= max(embedding_values) <= 1
91+
assert 0 <= min(embedding_values) <= 1
9192

9293
_ = (transformed_pcoll | beam.Map(assert_element))
9394

@@ -186,7 +187,7 @@ def test_with_int_data_types(self):
186187
write_artifact_location=self.artifact_location).with_transform(
187188
embedding_config))
188189

189-
def test_with_artifact_location(self): # pylint: disable=line-too-long
190+
def test_with_artifact_location(self):
190191
"""Local artifact location test"""
191192
secondary_artifact_location = tempfile.mkdtemp(
192193
prefix='_openai_secondary_test')
@@ -231,7 +232,7 @@ def assert_element(element):
231232
# Clean up the temporary directory
232233
shutil.rmtree(secondary_artifact_location)
233234

234-
def test_mltransform_to_ptransform_with_openai(self): # pylint: disable=line-too-long
235+
def test_mltransform_to_ptransform_with_openai(self):
235236
transforms = [
236237
OpenAITextEmbeddings(
237238
columns=['x'],

0 commit comments

Comments
 (0)