liferoad commented on code in PR #31536:
URL: https://github.com/apache/beam/pull/31536#discussion_r1631153064
##########
sdks/python/apache_beam/ml/transforms/embeddings/huggingface.py:
##########
@@ -153,6 +154,45 @@ def get_ptransform_for_processing(self, **kwargs) ->
beam.PTransform:
))
+class SentenceTransformerImageEmbeddings(EmbeddingsManager):
+ def __init__(self, model_name: str, columns: List[str], **kwargs):
+ """
+ Embedding config for sentence-transformers. This config can be used with
+ MLTransform to embed image data. Models are loaded using the RunInference
+ PTransform with the help of ModelHandler.
+
+ Args:
+ model_name: Name of the model to use. The model should be hosted on
+ HuggingFace Hub or compatible with sentence_transformers. See
+
https://www.sbert.net/docs/sentence_transformer/pretrained_models.html#image-text-models
# pylint: disable=line-too-long
+ for a list of sentence_transformers models.
+ columns: List of columns to be embedded.
+ min_batch_size: The minimum batch size to be used for inference.
+ max_batch_size: The maximum batch size to be used for inference.
+ large_model: Whether to share the model across processes.
+ """
+ super().__init__(columns, **kwargs)
+ self.model_name = model_name
+
+ def get_model_handler(self):
+ return _SentenceTransformerModelHandler(
+ model_class=SentenceTransformer,
+ model_name=self.model_name,
+ load_model_args=self.load_model_args,
+ min_batch_size=self.min_batch_size,
+ max_batch_size=self.max_batch_size,
+ large_model=self.large_model)
+
+ def get_ptransform_for_processing(self, **kwargs) -> beam.PTransform:
+ # wrap the model handler in a _TextEmbeddingHandler since
Review Comment:
`_TextEmbeddingHandler`?
and do we need to create `SentenceTransformerImageEmbeddings`? shall we just
add `image_model:bool` in `SentenceTransformerEmbeddings`? or can we infer the
model type automatically and then call either `_ImageEmbeddingHandler` or
`_TextEmbeddingHandler`?
--
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]