Package: text-transformers
Sentence Transformers: Multilingual Sentence, Paragraph, and Image Embeddings using BERT & Co.This framework provides an easy method to compute dense vector representations forsentences,paragraphs, andimages. 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 ofstate-of-the-art pretrained modelsfor more than 100 languages, fine-tuned for various use-cases.Further, this framework allows an easyfine-tuning of custom embeddings models, to achieve maximal performance on your specific task.For thefull documentation, seewww.SBERT.net.The following publications are integrated in this framework:Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks(EMNLP 2019)Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation(EMNLP 2020)Augmented SBERT: Data Augmentation Method for Improving Bi-Encoders for Pairwise Sentence Scoring Tasks(NAACL 2021)The Curse of Dense Low-Dimensional Information Retrieval for Large Index Sizes(arXiv 2020)TSDAE: Using Transformer-based Sequential Denoising Auto-Encoder for Unsupervised Sentence Embedding Learning(arXiv 2021)BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models(arXiv 2021)InstallationWe recommendPython 3.6or higher,PyTorch 1.6.0or higher andtransformers v4.6.0or higher. The code doesnotwork with Python 2.7.Install with pipInstall thesentence-transformerswithpip:pip install -U sentence-transformersInstall with condaYou can install thesentence-transformerswithconda:conda install -c conda-forge sentence-transformersInstall from sourcesAlternatively, you can also clone the latest version from therepositoryand install it directly from the source code:pip install -e .PyTorch with CUDAIf you want to use a GPU / CUDA, you must install PyTorch with the matching CUDA Version. FollowPyTorch - Get Startedfor further details how to install PyTorch.Getting StartedSeeQuickstartin our documenation.This exampleshows you how to use an already trained Sentence Transformer model to embed sentences for another task.First download a pretrained model.fromsentence_transformersimportSentenceTransformermodel=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.forsentence,embeddinginzip(sentences,sentence_embeddings):print("Sentence:",sentence)print("Embedding:",embedding)print("")Pre-Trained ModelsWe provide a large list ofPretrained Modelsfor 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 modelsTrainingThis 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.SeeTraining Overviewfor an introduction how to train your own embedding models. We providevarious exampleshow 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 learningEvaluation during training to find optimal model10+ loss-functionsallowing to tune models specifically for semantic search, paraphrase mining, semantic similarity comparison, clustering, triplet loss, contrastive loss.PerformanceOur models are evaluated extensively on 15+ datasets including challening domains like Tweets, Reddit, emails. They achieve by far thebest performancefrom all available sentence embedding methods. Further, we provide severalsmaller modelsthat areoptimized for speed.» Full list of pretrained modelsApplication ExamplesYou can use this framework for:Computing Sentence EmbeddingsSemantic Textual SimilarityClusteringParaphrase MiningTranslated Sentence MiningSemantic SearchRetrieve & Re-RankText SummarizationMultilingual Image Search, Clustering & Duplicate Detectionand many more use-cases.For all examples, seeexamples/applications.Citing & AuthorsIf you find this repository helpful, feel free to cite our publicationSentence-BERT: Sentence Embeddings using Siamese BERT-Networks:@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",}If you use one of the multilingual models, feel free to cite our publicationMaking Monolingual Sentence Embeddings Multilingual using Knowledge Distillation:@inproceedings{reimers-2020-multilingual-sentence-bert,title="Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation",author="Reimers, Nils and Gurevych, Iryna",booktitle="Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing",month="11",year="2020",publisher="Association for Computational Linguistics",url="https://arxiv.org/abs/2004.09813",}Please have a look atPublicationsfor our different publications that are integrated into SentenceTransformers.Contact person:Nils Reimers,info@nils-reimers.dehttps://www.ukp.tu-darmstadt.de/Don't hesitate to send us an e-mail or report an issue, if something is broken (and it shouldn't be) or if you have further questions.This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.