koursaris commited on
Commit
03b9547
·
verified ·
1 Parent(s): 977e470

Upload sentence-transformers/msmarco-MiniLM-L6-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-L6-cos-v5
14
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 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-L6-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-L6-cos-v5")
92
+ model = AutoModel.from_pretrained("sentence-transformers/msmarco-MiniLM-L6-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 | 384 |
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-6-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": 6,
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:4ce670108f3abe4a1513aa973c696e273397db899a983deecdd86a987f9a63dc
3
+ size 90856603
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7a1183a824b1550ff3d650aa6661f45af5d8ce3056bc1b379d22ca4026b73e1
3
+ size 90868370
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:224b2aa11d6c029d9bea9ec96b9e1ec5b8f774ca4cf1ef70f63d9928b2d79fb8
3
+ size 90405214
onnx/model_O1.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f93931e8accaab4fae6c60573f95817d61ec3c5649905878d7f74f228ba3c433
3
+ size 90360328
onnx/model_O2.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71a9ded7a9b2d699b60ff602ca30a95ab98421d3415f38c77ce3766abe312d17
3
+ size 90326566
onnx/model_O3.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dd144da054836b8c25ddb2d8a23a71cd3de0e10ce8f185bc7c15d6d44ed09a0
3
+ size 90326497
onnx/model_O4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d03058ed2c7f3ce097357c36870b5e326b7d22e8baf6dbd44a55dbedad8e956a
3
+ size 45212349
onnx/model_qint8_arm64.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad079b2f50c403660a89403f9bc736fbcf1e48383ae215f2cdd2251e9f2388fb
3
+ size 23026053
onnx/model_qint8_avx512.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad079b2f50c403660a89403f9bc736fbcf1e48383ae215f2cdd2251e9f2388fb
3
+ size 23026053
onnx/model_qint8_avx512_vnni.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad079b2f50c403660a89403f9bc736fbcf1e48383ae215f2cdd2251e9f2388fb
3
+ size 23026053
onnx/model_quint8_avx2.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2578fe468be66a09175308364d26f6bc47bd0c75d4a16d2e5ff27f3e7ad2a2fd
3
+ size 23046789
openvino/openvino_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1dfea90336af59564351015c7818ab9c552919f93bee8fa8dcee430e3bb7e30c
3
+ size 90265744
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:a23cbdb861ded4c9f1c2b90377dcf39a90374adc66ad4f28707aee4b8e963d04
3
+ size 22933664
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:5e3a29b2fc7bce0f6b0bdd35dcd6e6d1c1dd5fc191561d0b9c5d3aadf3891e0b
3
+ size 90895153
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:5f4f194a925d21f972ae6149d1f9a94dae43886a3fff1886977a950c6862fcd9
3
+ size 91005696
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-6-v3/0_Transformer", "do_basic_tokenize": true, "never_split": null, "special_tokens_map_file": "old_models/msmarco-MiniLM-L-6-v3/0_Transformer/special_tokens_map.json"}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff