ForkDeepInfraDeepInfrapublished Feb 28, 2023seen 5d

deepinfra/sentence-transformers

forked from huggingface/sentence-transformers

Open original ↗

Captured source

source ↗
published Feb 28, 2023seen 5dcaptured 8hhttp 200method plain

deepinfra/sentence-transformers

Description: Multilingual Sentence & Image Embeddings with BERT

License: Apache-2.0

Stars: 0

Forks: 0

Open issues: 0

Created: 2023-02-28T16:01:59Z

Pushed: 2023-02-28T16:03:55Z

Default branch: master

Fork: yes

Parent repository: huggingface/sentence-transformers

Archived: no

README:

[#github-license]: https://github.com/UKPLab/sentence-transformers/blob/master/LICENSE [#pypi-package]: https://pypi.org/project/sentence-transformers/ [#conda-forge-package]: https://anaconda.org/conda-forge/sentence-transformers [#docs-package]: https://www.sbert.net/

Sentence Transformers: Multilingual Sentence, Paragraph, and Image Embeddings using BERT & Co.

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 task. Text is embedding in vector space such that similar text is close 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.

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.

For the full documentation, see [www.SBERT.net](https://www.sbert.net).

The following publications are integrated in this framework:

Installation

We recommend Python 3.6 or higher, [PyTorch 1.6.0](https://pytorch.org/get-started/locally/) or higher and [transformers v4.6.0](https://github.com/huggingface/transformers) or higher. The code does not work with Python 2.7.

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

Install from sources

Alternatively, you can also clone the latest version from the repository and install it directly from the source code:

pip install -e .

PyTorch with CUDA

If you want to use a GPU / CUDA, you must install PyTorch with the matching CUDA Version. Follow PyTorch - Get Started for further details how to install PyTorch.

Getting Started

See Quickstart in our documenation.

This example shows you how to use an already trained Sentence Transformer model to embed sentences for another task.

First download a pretrained model.

from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')

Then provide some sentences to the model.

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.']
sentence_embeddings = model.encode(sentences)

And that's it already. We now have a list of numpy arrays with the embeddings.

for sentence, embedding in zip(sentences, sentence_embeddings):
print("Sentence:", sentence)
print("Embedding:", embedding)
print("")

Pre-Trained Models

We provide a large list of Pretrained Models 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

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 for an introduction how to train your own embedding models. We provide various examples 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
  • 10+ loss-functions 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

Application Examples

You can use this framework for:

Excerpt shown — open the source for the full document.