You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, embedding normalization in SentenceTransformer can be achieved in two ways:
Adding a Normalize module to the model pipeline
Manually normalizing embeddings post-encode
Both approaches work but can add complexity and may not align seamlessly with production deployment workflows.
Feature Request:
Add normalize_embeddings as an argument to SentenceTransformer.__init__ that would be passed through to encode methods, similar to how truncate_dim works. This would provide a cleaner, built-in way to control normalization behavior.
Current Workarounds:
Currently, we need to either:
How should this interact with models that already include a Normalize module? Should we:
Skip additional normalization if a Normalize module is present?
Allow override via the normalize_embeddings parameter?
Raise a warning to avoid redundancy?
Should this behavior be configurable in the config_sentence_transformers.json file, like other model options?
Use Case:
When deploying embedding models to production serving endpoints (e.g., Databricks via MLflow), having normalization as a built-in configurable parameter would:
Eliminate the need to wrap or subclass models.
Reduce the risk of unnormalized embeddings in similarity or clustering tasks, which can drastically impact performance.
Align with production-friendly design by providing a clean and intuitive API for normalization.
Example Usage
fromsentence_transformersimportSentenceTransformer# Normalize embeddings during encodingmodel=SentenceTransformer(
model_name_or_path="jinaai/jina-embeddings-v2-base-code",
trust_remote_code=True,
normalize_embeddings=True
)
embeddings=model.encode(["This is a test sentence."])
If this feature makes sense, I'd be happy to contribute by working on a PR or incorporating any guidance and feedback on the request.
The text was updated successfully, but these errors were encountered:
Currently, embedding normalization in SentenceTransformer can be achieved in two ways:
Both approaches work but can add complexity and may not align seamlessly with production deployment workflows.
Feature Request:
Add
normalize_embeddings
as an argument toSentenceTransformer.__init__
that would be passed through to encode methods, similar to howtruncate_dim
works. This would provide a cleaner, built-in way to control normalization behavior.Current Workarounds:
Currently, we need to either:
Example Subclass Workaround
Questions for Discussion:
How should this interact with models that already include a Normalize module? Should we:
Normalize
module is present?normalize_embeddings
parameter?Should this behavior be configurable in the
config_sentence_transformers.json
file, like other model options?Use Case:
When deploying embedding models to production serving endpoints (e.g., Databricks via MLflow), having normalization as a built-in configurable parameter would:
Example Usage
If this feature makes sense, I'd be happy to contribute by working on a PR or incorporating any guidance and feedback on the request.
The text was updated successfully, but these errors were encountered: