-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge v3.0 pre-release into master, prepare for full v3.0 release (#2685
- Loading branch information
Showing
292 changed files
with
13,732 additions
and
7,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include sentence_transformers/model_card_template.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
<!--- BADGES: START ---> | ||
[](https://huggingface.co/models?library=sentence-transformers) | ||
[][#github-license] | ||
[][#pypi-package] | ||
[][#pypi-package] | ||
[][#conda-forge-package] | ||
[][#conda-forge-package] | ||
[][#docs-package] | ||
<!--- | ||
[][#pypi-package] | ||
[][#conda-forge-package] | ||
---> | ||
<!-- [][#pypi-package] --> | ||
|
||
[#github-license]: https://github.com/UKPLab/sentence-transformers/blob/master/LICENSE | ||
[#pypi-package]: https://pypi.org/project/sentence-transformers/ | ||
|
@@ -20,38 +16,24 @@ | |
|
||
This framework provides an easy method to compute dense vector representations for **sentences**, **paragraphs**, and **images**. The models are based on transformer networks like BERT / RoBERTa / XLM-RoBERTa etc. and achieve state-of-the-art performance in various tasks. Text is embedded in vector space such that similar text are closer and can efficiently be found using cosine similarity. | ||
|
||
We provide an increasing number of **[state-of-the-art pretrained models](https://www.sbert.net/docs/pretrained_models.html)** for more than 100 languages, fine-tuned for various use-cases. | ||
We provide an increasing number of **[state-of-the-art pretrained models](https://www.sbert.net/docs/sentence_transformer/pretrained_models.html)** for more than 100 languages, fine-tuned for various use-cases. | ||
|
||
Further, this framework allows an easy **[fine-tuning of custom embeddings models](https://www.sbert.net/docs/training/overview.html)**, to achieve maximal performance on your specific task. | ||
Further, this framework allows an easy **[fine-tuning of custom embeddings models](https://www.sbert.net/docs/sentence_transformer/training_overview.html)**, to achieve maximal performance on your specific task. | ||
|
||
For the **full documentation**, see **[www.SBERT.net](https://www.sbert.net)**. | ||
|
||
The following publications are integrated in this framework: | ||
|
||
- [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084) (EMNLP 2019) | ||
- [Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation](https://arxiv.org/abs/2004.09813) (EMNLP 2020) | ||
- [Augmented SBERT: Data Augmentation Method for Improving Bi-Encoders for Pairwise Sentence Scoring Tasks](https://arxiv.org/abs/2010.08240) (NAACL 2021) | ||
- [The Curse of Dense Low-Dimensional Information Retrieval for Large Index Sizes](https://arxiv.org/abs/2012.14210) (arXiv 2020) | ||
- [TSDAE: Using Transformer-based Sequential Denoising Auto-Encoder for Unsupervised Sentence Embedding Learning](https://arxiv.org/abs/2104.06979) (arXiv 2021) | ||
- [BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models](https://arxiv.org/abs/2104.08663) (arXiv 2021) | ||
- [Matryoshka Representation Learning](https://arxiv.org/abs/2205.13147) (arXiv 2022) | ||
|
||
## Installation | ||
|
||
We recommend **Python 3.8** or higher, **[PyTorch 1.11.0](https://pytorch.org/get-started/locally/)** or higher and **[transformers v4.32.0](https://github.com/huggingface/transformers)** or higher. The code does **not** work with Python 2.7. | ||
We recommend **Python 3.8+**, **[PyTorch 1.11.0+](https://pytorch.org/get-started/locally/)**, and **[transformers v4.34.0+](https://github.com/huggingface/transformers)**. | ||
|
||
**Install with pip** | ||
|
||
Install the *sentence-transformers* with `pip`: | ||
|
||
``` | ||
pip install -U sentence-transformers | ||
``` | ||
|
||
**Install with conda** | ||
|
||
You can install the *sentence-transformers* with `conda`: | ||
|
||
``` | ||
conda install -c conda-forge sentence-transformers | ||
``` | ||
|
@@ -73,8 +55,6 @@ If you want to use a GPU / CUDA, you must install PyTorch with the matching CUDA | |
|
||
See [Quickstart](https://www.sbert.net/docs/quickstart.html) in our documenation. | ||
|
||
[This example](https://github.com/UKPLab/sentence-transformers/tree/master/examples/applications/computing-embeddings/computing_embeddings.py) shows you how to use an already trained Sentence Transformer model to embed sentences for another task. | ||
|
||
First download a pretrained model. | ||
|
||
````python | ||
|
@@ -87,58 +67,52 @@ Then provide some sentences to the model. | |
|
||
````python | ||
sentences = [ | ||
"This framework generates embeddings for each input sentence", | ||
"Sentences are passed as a list of string.", | ||
"The quick brown fox jumps over the lazy dog.", | ||
"The weather is lovely today.", | ||
"It's so sunny outside!", | ||
"He drove to the stadium.", | ||
] | ||
sentence_embeddings = model.encode(sentences) | ||
embeddings = model.encode(sentences) | ||
print(embeddings.shape) | ||
# => (3, 384) | ||
```` | ||
|
||
And that's it already. We now have a list of numpy arrays with the embeddings. | ||
And that's already it. We now have a numpy arrays with the embeddings, one for each text. We can use these to compute similarities. | ||
|
||
````python | ||
for sentence, embedding in zip(sentences, sentence_embeddings): | ||
print("Sentence:", sentence) | ||
print("Embedding:", embedding) | ||
print("") | ||
similarities = model.similarity(embeddings, embeddings) | ||
print(similarities) | ||
# tensor([[1.0000, 0.6660, 0.1046], | ||
# [0.6660, 1.0000, 0.1411], | ||
# [0.1046, 0.1411, 1.0000]]) | ||
```` | ||
|
||
## Pre-Trained Models | ||
|
||
We provide a large list of [Pretrained Models](https://www.sbert.net/docs/pretrained_models.html) for more than 100 languages. Some models are general purpose models, while others produce embeddings for specific use cases. Pre-trained models can be loaded by just passing the model name: `SentenceTransformer('model_name')`. | ||
|
||
[» Full list of pretrained models](https://www.sbert.net/docs/pretrained_models.html) | ||
We provide a large list of [Pretrained Models](https://www.sbert.net/docs/sentence_transformer/pretrained_models.html) for more than 100 languages. Some models are general purpose models, while others produce embeddings for specific use cases. Pre-trained models can be loaded by just passing the model name: `SentenceTransformer('model_name')`. | ||
|
||
## Training | ||
|
||
This framework allows you to fine-tune your own sentence embedding methods, so that you get task-specific sentence embeddings. You have various options to choose from in order to get perfect sentence embeddings for your specific task. | ||
|
||
See [Training Overview](https://www.sbert.net/docs/training/overview.html) for an introduction how to train your own embedding models. We provide [various examples](https://github.com/UKPLab/sentence-transformers/tree/master/examples/training) how to train models on various datasets. | ||
See [Training Overview](https://www.sbert.net/docs/sentence_transformer/training_overview.html) for an introduction how to train your own embedding models. We provide [various examples](https://github.com/UKPLab/sentence-transformers/tree/master/examples/training) how to train models on various datasets. | ||
|
||
Some highlights are: | ||
- Support of various transformer networks including BERT, RoBERTa, XLM-R, DistilBERT, Electra, BART, ... | ||
- Multi-Lingual and multi-task learning | ||
- Evaluation during training to find optimal model | ||
- [20+ loss-functions](https://www.sbert.net/docs/package_reference/losses.html) allowing to tune models specifically for semantic search, paraphrase mining, semantic similarity comparison, clustering, triplet loss, contrastive loss. | ||
|
||
## Performance | ||
|
||
Our models are evaluated extensively on 15+ datasets including challening domains like Tweets, Reddit, emails. They achieve by far the **best performance** from all available sentence embedding methods. Further, we provide several **smaller models** that are **optimized for speed**. | ||
|
||
[» Full list of pretrained models](https://www.sbert.net/docs/pretrained_models.html) | ||
- [20+ loss-functions](https://www.sbert.net/docs/package_reference/sentence_transformer/losses.html) allowing to tune models specifically for semantic search, paraphrase mining, semantic similarity comparison, clustering, triplet loss, contrastive loss, etc. | ||
|
||
## Application Examples | ||
|
||
You can use this framework for: | ||
|
||
- [Computing Sentence Embeddings](https://www.sbert.net/examples/applications/computing-embeddings/README.html) | ||
- [Semantic Textual Similarity](https://www.sbert.net/docs/usage/semantic_textual_similarity.html) | ||
- [Semantic Search](https://www.sbert.net/examples/applications/semantic-search/README.html) | ||
- [Retrieve & Re-Rank](https://www.sbert.net/examples/applications/retrieve_rerank/README.html) | ||
- [Clustering](https://www.sbert.net/examples/applications/clustering/README.html) | ||
- [Paraphrase Mining](https://www.sbert.net/examples/applications/paraphrase-mining/README.html) | ||
- [Translated Sentence Mining](https://www.sbert.net/examples/applications/parallel-sentence-mining/README.html) | ||
- [Semantic Search](https://www.sbert.net/examples/applications/semantic-search/README.html) | ||
- [Retrieve & Re-Rank](https://www.sbert.net/examples/applications/retrieve_rerank/README.html) | ||
- [Text Summarization](https://www.sbert.net/examples/applications/text-summarization/README.html) | ||
- [Translated Sentence Mining](https://www.sbert.net/examples/applications/parallel-sentence-mining/README.html) | ||
- [Multilingual Image Search, Clustering & Duplicate Detection](https://www.sbert.net/examples/applications/image-search/README.html) | ||
|
||
and many more use-cases. | ||
|
@@ -193,7 +167,7 @@ If you use one of the multilingual models, feel free to cite our publication [Ma | |
|
||
Please have a look at [Publications](https://www.sbert.net/docs/publications.html) for our different publications that are integrated into SentenceTransformers. | ||
|
||
Contact person: Tom Aarsen, [[email protected]](mailto:[email protected]) | ||
Maintainer: [Tom Aarsen](https://github.com/tomaarsen), 🤗 Hugging Face | ||
|
||
https://www.ukp.tu-darmstadt.de/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
|
||
docs: | ||
sphinx-build -c . -a -E .. _build | ||
sphinx-build -c . -a -E .. _build | ||
|
||
docs-quick: | ||
sphinx-build -c . .. _build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
|
||
import sphinx | ||
|
||
|
||
__version__ = "0.5.0" | ||
__version_full__ = __version__ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.