nreimers commited on
Commit
b94ae8f
1 Parent(s): 83beb4f
README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Sentence Embeddings Models trained on Paraphrases
2
+ This model is from the [sentence-transformers](https://github.com/UKPLab/sentence-transformers)-repository. It was trained on millions of paraphrase sentences. Further details on SBERT can be found in the paper: [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084)
3
+
4
+ This model is the multilingual version of distilroberta-base-paraphrase-v1, trained on parallel data for 50+ languages.
5
+
6
+ ## Usage (HuggingFace Models Repository)
7
+
8
+ You can use the model directly from the model repository to compute sentence embeddings:
9
+ ```python
10
+ from transformers import AutoTokenizer, AutoModel
11
+ import torch
12
+
13
+
14
+ #Mean Pooling - Take attention mask into account for correct averaging
15
+ def mean_pooling(model_output, attention_mask):
16
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
17
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
18
+ sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
19
+ sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
20
+ return sum_embeddings / sum_mask
21
+
22
+
23
+
24
+ #Sentences we want sentence embeddings for
25
+ sentences = ['This framework generates embeddings for each input sentence',
26
+ 'Sentences are passed as a list of string.',
27
+ 'The quick brown fox jumps over the lazy dog.']
28
+
29
+ #Load AutoModel from huggingface model repository
30
+ tokenizer = AutoTokenizer.from_pretrained("model_name")
31
+ model = AutoModel.from_pretrained("model_name")
32
+
33
+ #Tokenize sentences
34
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=128, return_tensors='pt')
35
+
36
+ #Compute token embeddings
37
+ with torch.no_grad():
38
+ model_output = model(**encoded_input)
39
+
40
+ #Perform pooling. In this case, mean pooling
41
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
42
+ ```
43
+
44
+ ## Usage (Sentence-Transformers)
45
+ Using this model becomes more convenient when you have [sentence-transformers](https://github.com/UKPLab/sentence-transformers) installed:
46
+ ```
47
+ pip install -U sentence-transformers
48
+ ```
49
+
50
+ Then you can use the model like this:
51
+ ```python
52
+ from sentence_transformers import SentenceTransformer
53
+ model = SentenceTransformer('model_name')
54
+ sentences = ['This framework generates embeddings for each input sentence',
55
+ 'Sentences are passed as a list of string.',
56
+ 'The quick brown fox jumps over the lazy dog.']
57
+ sentence_embeddings = model.encode(sentences)
58
+
59
+ print("Sentence embeddings:")
60
+ print(sentence_embeddings)
61
+ ```
62
+
63
+
64
+ ## Citing & Authors
65
+ If you find this model helpful, feel free to cite our publication [Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation](https://arxiv.org/abs/2004.09813):
66
+ ```
67
+ @inproceedings{reimers-2020-multilingual-sentence-bert,
68
+ title = "Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation",
69
+ author = "Reimers, Nils and Gurevych, Iryna",
70
+ booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing",
71
+ month = "11",
72
+ year = "2020",
73
+ publisher = "Association for Computational Linguistics",
74
+ url = "https://arxiv.org/abs/2004.09813",
75
+ }
76
+ ```
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "XLMRobertaModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "eos_token_id": 2,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "xlm-roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "output_past": true,
20
+ "pad_token_id": 1,
21
+ "type_vocab_size": 1,
22
+ "vocab_size": 250002
23
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a0145d0622caa7b0cb061f69ae55b3faa1afd35cdb0a348cfd6b7a0212da40f
3
+ size 1112256686
sentence_bert_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "max_seq_length": 128
3
+ }
sentencepiece.bpe.model ADDED
Binary file (5.07 MB). View file
 
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": "<mask>"}
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"model_max_length": 512, "special_tokens_map_file": "input_models/johngiorgi-declutr-small-all-paraphrase-multilingual/0_Transformer/special_tokens_map.json", "full_tokenizer_file": null}