koursaris commited on
Commit
b8a92eb
·
verified ·
1 Parent(s): b172aef

Upload sentence-transformers/msmarco-MiniLM-L12-cos-v5 model files

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ library_name: sentence-transformers
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - transformers
10
+ pipeline_tag: sentence-similarity
11
+ ---
12
+
13
+ # msmarco-MiniLM-L12-cos-v5
14
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for **semantic search**. It has been trained on 500k (query, answer) pairs from the [MS MARCO Passages dataset](https://github.com/microsoft/MSMARCO-Passage-Ranking). For an introduction to semantic search, have a look at: [SBERT.net - Semantic Search](https://www.sbert.net/examples/applications/semantic-search/README.html)
15
+
16
+
17
+ ## Usage (Sentence-Transformers)
18
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
19
+
20
+ ```
21
+ pip install -U sentence-transformers
22
+ ```
23
+
24
+ Then you can use the model like this:
25
+ ```python
26
+ from sentence_transformers import SentenceTransformer, util
27
+
28
+ query = "How many people live in London?"
29
+ docs = ["Around 9 Million people live in London", "London is known for its financial district"]
30
+
31
+ #Load the model
32
+ model = SentenceTransformer('sentence-transformers/msmarco-MiniLM-L12-cos-v5')
33
+
34
+ #Encode query and documents
35
+ query_emb = model.encode(query)
36
+ doc_emb = model.encode(docs)
37
+
38
+ #Compute dot score between query and all document embeddings
39
+ scores = util.dot_score(query_emb, doc_emb)[0].cpu().tolist()
40
+
41
+ #Combine docs & scores
42
+ doc_score_pairs = list(zip(docs, scores))
43
+
44
+ #Sort by decreasing score
45
+ doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
46
+
47
+ #Output passages & scores
48
+ for doc, score in doc_score_pairs:
49
+ print(score, doc)
50
+ ```
51
+
52
+
53
+ ## Usage (HuggingFace Transformers)
54
+ Without [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 correct pooling-operation on-top of the contextualized word embeddings.
55
+
56
+ ```python
57
+ from transformers import AutoTokenizer, AutoModel
58
+ import torch
59
+ import torch.nn.functional as F
60
+
61
+ #Mean Pooling - Take average of all tokens
62
+ def mean_pooling(model_output, attention_mask):
63
+ token_embeddings = model_output.last_hidden_state #First element of model_output contains all token embeddings
64
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
65
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
66
+
67
+
68
+ #Encode text
69
+ def encode(texts):
70
+ # Tokenize sentences
71
+ encoded_input = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')
72
+
73
+ # Compute token embeddings
74
+ with torch.no_grad():
75
+ model_output = model(**encoded_input, return_dict=True)
76
+
77
+ # Perform pooling
78
+ embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
79
+
80
+ # Normalize embeddings
81
+ embeddings = F.normalize(embeddings, p=2, dim=1)
82
+
83
+ return embeddings
84
+
85
+
86
+ # Sentences we want sentence embeddings for
87
+ query = "How many people live in London?"
88
+ docs = ["Around 9 Million people live in London", "London is known for its financial district"]
89
+
90
+ # Load model from HuggingFace Hub
91
+ tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/msmarco-MiniLM-L12-cos-v5")
92
+ model = AutoModel.from_pretrained("sentence-transformers/msmarco-MiniLM-L12-cos-v5")
93
+
94
+ #Encode query and docs
95
+ query_emb = encode(query)
96
+ doc_emb = encode(docs)
97
+
98
+ #Compute dot score between query and all document embeddings
99
+ scores = torch.mm(query_emb, doc_emb.transpose(0, 1))[0].cpu().tolist()
100
+
101
+ #Combine docs & scores
102
+ doc_score_pairs = list(zip(docs, scores))
103
+
104
+ #Sort by decreasing score
105
+ doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
106
+
107
+ #Output passages & scores
108
+ for doc, score in doc_score_pairs:
109
+ print(score, doc)
110
+ ```
111
+
112
+ ## Technical Details
113
+
114
+ In the following some technical details how this model must be used:
115
+
116
+ | Setting | Value |
117
+ | --- | :---: |
118
+ | Dimensions | 768 |
119
+ | Produces normalized embeddings | Yes |
120
+ | Pooling-Method | Mean pooling |
121
+ | Suitable score functions | dot-product (`util.dot_score`), cosine-similarity (`util.cos_sim`), or euclidean distance |
122
+
123
+ Note: When loaded with `sentence-transformers`, this model produces normalized embeddings with length 1. In that case, dot-product and cosine-similarity are equivalent. dot-product is preferred as it is faster. Euclidean distance is proportional to dot-product and can also be used.
124
+
125
+ ## Citing & Authors
126
+
127
+ This model was trained by [sentence-transformers](https://www.sbert.net/).
128
+
129
+ If 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):
130
+ ```bibtex
131
+ @inproceedings{reimers-2019-sentence-bert,
132
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
133
+ author = "Reimers, Nils and Gurevych, Iryna",
134
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
135
+ month = "11",
136
+ year = "2019",
137
+ publisher = "Association for Computational Linguistics",
138
+ url = "http://arxiv.org/abs/1908.10084",
139
+ }
140
+ ```
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "old_models/msmarco-MiniLM-L-12-v3/0_Transformer",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1536,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "transformers_version": "4.7.0",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 30522
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
6
+ }
7
+ }
flax_model.msgpack ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc545410e357acc8d666a3dd2ab33a9b3cd922eb4a9b94436f0790b399e8b3d4
3
+ size 133447149
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de1a3145d5bdeebb9d7a8294f05603adfb395cbf67c174697c6e42918f8ae17f
3
+ size 133466304
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:619fcdd0026b6e2ed2d5c54d93dbe0efe84a65662474adde564b08aa92820eeb
3
+ size 133126567
onnx/model_O1.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49c165363f5f3918d46ff61dbc442d1077eaaddeb3e9a81c9201639510420649
3
+ size 133037320
onnx/model_O2.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9f0832be9f373b715e3fdb6342a65946afc14192ef24a240fb22cb8f944f719
3
+ size 132970874
onnx/model_O3.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:930322e845a6107a2ba1b564523d2c72fa6e69169d1a64ea2aa64a4d1685f864
3
+ size 132970729
onnx/model_O4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34e29ab54d673289fbb9178474e60f47fb60c497a3c08e2e7e1a95cd509fcbca
3
+ size 66578744
onnx/model_qint8_arm64.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:782aecc94bd11a9d17a5dc7136970c9fa5397827f789937075feada2a3458d21
3
+ size 34118638
onnx/model_qint8_avx512.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:782aecc94bd11a9d17a5dc7136970c9fa5397827f789937075feada2a3458d21
3
+ size 34118638
onnx/model_qint8_avx512_vnni.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:782aecc94bd11a9d17a5dc7136970c9fa5397827f789937075feada2a3458d21
3
+ size 34118638
onnx/model_quint8_avx2.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:550222139953f6eb9de5046e07396244a27393e50f25d4319fc505cbcf15a22f
3
+ size 34160110
openvino/openvino_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98681a746c2465cfa12e483c7545ffe16a7768be493bfb75291b25beb7f63913
3
+ size 132852880
openvino/openvino_model.xml ADDED
The diff for this file is too large to render. See raw diff
 
openvino/openvino_model_qint8_quantized.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb59513b412cef1acd8d55609f398ff9b51ed89051f630b733f32b68af2bff8c
3
+ size 33818048
openvino/openvino_model_qint8_quantized.xml ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b17442e1b4a5db687084be01f47d35f683f35ffadbfe26ca42622fec51d013a8
3
+ size 133518577
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 384,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tf_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:babd8eaec24a64d327fa18a0e455567d953b766d4dfcc68daa699b07304eba29
3
+ size 133724136
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "name_or_path": "old_models/msmarco-MiniLM-L-12-v3/0_Transformer", "do_basic_tokenize": true, "never_split": null, "special_tokens_map_file": "old_models/msmarco-MiniLM-L-12-v3/0_Transformer/special_tokens_map.json"}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff