Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 18
How to use kiel2/Kiel-2-Poly with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("kiel2/Kiel-2-Poly")
sentences = [
"But Close wondered whether the package would be worth the cost of licensing the third-party software , along with Salesforce.com 's rental price .",
"Close also questions whether it would be worth the cost of licensing third-party software , along with Salesforce.com 's rental price .",
"No tumors were detected ; rather , empty cavities and scar tissue were found in their place .",
"A race observer sits in the passenger seat of the follow vehicle to record any broken rules and also keep track of the car 's time ."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]Kiel-2-Poly is a specialized multilingual text embedding model based on sentence-transformers/paraphrase-multilingual-mpnet-base-v2.
This is a sentence-transformers model that maps sentences and paragraphs across multiple languages into a 768-dimensional dense vector space optimized for cross-lingual semantic similarity, retrieval, and clustering tasks.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
)
Direct Usage (Sentence Transformers)
First, install the Sentence Transformers library:
Bash
pip install -U sentence-transformers
Then load your model and run inference:
Python
from sentence_transformers import SentenceTransformer
# Load your model from the Hugging Face Hub
model = SentenceTransformer("kiel2/Kiel-2-Poly")
# Run inference
sentences = [
'" Any decision on Charleroi will have huge implications for regional airports in France , " he said .',
'" A bad decision on Charleroi would have huge implications for state-owned regional airports in France .',
"He said the ferry 's crew will be interviewed and tested for drugs and alcohol .",
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
Citation
Code snippet
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "[https://arxiv.org/abs/1908.10084](https://arxiv.org/abs/1908.10084)",
}