CoolFace
Modelpublic

sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2

sourceHugging Faceapache-2.0updated 8mo agoView on Hugging Face
1.4klikes45.7mdownloads
README.md156 linesDownload Raw Back to root
1---2language:3- multilingual4- ar5- bg6- ca7- cs8- da9- de10- el11- en12- es13- et14- fa15- fi16- fr17- gl18- gu19- he20- hi21- hr22- hu23- hy24- id25- it26- ja27- ka28- ko29- ku30- lt31- lv32- mk33- mn34- mr35- ms36- my37- nb38- nl39- pl40- pt41- ro42- ru43- sk44- sl45- sq46- sr47- sv48- th49- tr50- uk51- ur52- vi53license: apache-2.054library_name: sentence-transformers55tags:56- sentence-transformers57- feature-extraction58- sentence-similarity59- transformers60language_bcp47:61- fr-ca62- pt-br63- zh-cn64- zh-tw65pipeline_tag: sentence-similarity66---67 68# sentence-transformers/paraphrase-multilingual-MiniLM-L12-v269 70This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.71 72 73 74## Usage (Sentence-Transformers)75 76Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:77 78```79pip install -U sentence-transformers80```81 82Then you can use the model like this:83 84```python85from sentence_transformers import SentenceTransformer86sentences = ["This is an example sentence", "Each sentence is converted"]87 88model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')89embeddings = model.encode(sentences)90print(embeddings)91```92 93 94 95## Usage (HuggingFace Transformers)96Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.97 98```python99from transformers import AutoTokenizer, AutoModel100import torch101 102 103# Mean Pooling - Take attention mask into account for correct averaging104def mean_pooling(model_output, attention_mask):105    token_embeddings = model_output[0] #First element of model_output contains all token embeddings106    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()107    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)108 109 110# Sentences we want sentence embeddings for111sentences = ['This is an example sentence', 'Each sentence is converted']112 113# Load model from HuggingFace Hub114tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')115model = AutoModel.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')116 117# Tokenize sentences118encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')119 120# Compute token embeddings121with torch.no_grad():122    model_output = model(**encoded_input)123 124# Perform pooling. In this case, max pooling.125sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])126 127print("Sentence embeddings:")128print(sentence_embeddings)129```130 131 132 133## Full Model Architecture134```135SentenceTransformer(136  (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel 137  (1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})138)139```140 141## Citing & Authors142 143This model was trained by [sentence-transformers](https://www.sbert.net/). 144        145If you find this model helpful, feel free to cite our publication [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084):146```bibtex 147@inproceedings{reimers-2019-sentence-bert,148    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",149    author = "Reimers, Nils and Gurevych, Iryna",150    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",151    month = "11",152    year = "2019",153    publisher = "Association for Computational Linguistics",154    url = "http://arxiv.org/abs/1908.10084",155}156```