Add new SentenceTransformer model with an onnx backend

#12
by gosshh - opened

Hello!

This pull request has been automatically generated from the push_to_hub method from the Sentence Transformers library.

Full Model Architecture:

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: ORTModelForFeatureExtraction 
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
  (2): Dense({'in_features': 768, 'out_features': 768, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh'})
  (3): Normalize()
)

Tip:

Consider testing this pull request before merging by loading the model from this PR with the revision argument:

from sentence_transformers import SentenceTransformer

# TODO: Fill in the PR number
pr_number = 2
model = SentenceTransformer(
    "sentence-transformers/LaBSE",
    revision=f"refs/pr/{pr_number}",
    backend="onnx",
)

# Verify that everything works as expected
embeddings = model.encode(["The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium."])
print(embeddings.shape)

similarities = model.similarity(embeddings, embeddings)
print(similarities)

I have added the onnx optimized version of sentence-transformers/LaBSE model.

Sentence Transformers org

Hello!

I cherry-picked the models from this PR in https://huggingface.co/sentence-transformers/LaBSE/commit/ac91d6745aefb758c373ef4d37a13ff5e04ad876, as I'm wary about updating e.g. the config for a newer transformers version, as it might break for people on old versions.

Thanks a bunch, you should be able to do this now:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("sentence-transformers/LaBSE", backend="onnx")

embeddings = model.encode(["The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium."])
print(embeddings.shape)

similarities = model.similarity(embeddings, embeddings)
print(similarities)
  • Tom Aarsen
tomaarsen changed pull request status to closed

Sign up or log in to comment