Commit
•
3962c71
0
Parent(s):
initial commit
Browse files- .gitattributes +2 -0
- .gitignore +1 -0
- README.md +66 -0
- convert.py +18 -0
- pytorch_model.onnx +3 -0
- requirements.txt +4 -0
- vocab.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
2 |
+
vocab.txt filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
README.md
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- sentence-transformers
|
4 |
+
- feature-extraction
|
5 |
+
- sentence-similarity
|
6 |
+
language: en
|
7 |
+
license: apache-2.0
|
8 |
+
datasets:
|
9 |
+
- s2orc
|
10 |
+
- flax-sentence-embeddings/stackexchange_xml
|
11 |
+
- ms_marco
|
12 |
+
- gooaq
|
13 |
+
- yahoo_answers_topics
|
14 |
+
- code_search_net
|
15 |
+
- search_qa
|
16 |
+
- eli5
|
17 |
+
- snli
|
18 |
+
- multi_nli
|
19 |
+
- wikihow
|
20 |
+
- natural_questions
|
21 |
+
- trivia_qa
|
22 |
+
- embedding-data/sentence-compression
|
23 |
+
- embedding-data/flickr30k-captions
|
24 |
+
- embedding-data/altlex
|
25 |
+
- embedding-data/simple-wiki
|
26 |
+
- embedding-data/QQP
|
27 |
+
- embedding-data/SPECTER
|
28 |
+
- embedding-data/PAQ_pairs
|
29 |
+
- embedding-data/WikiAnswers
|
30 |
+
|
31 |
+
---
|
32 |
+
|
33 |
+
# ONNX version of sentence-transormers/all-MiniLM-L6-v2
|
34 |
+
|
35 |
+
This is a sentence-transformers model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. The ONNX version of this model is made for the [Metarank](https://github.com/metarank/metarank) re-ranker
|
36 |
+
to do semantic similarity.
|
37 |
+
|
38 |
+
Check out the [main Metarank docs](https://docs.metarank.ai) on how to configure it.
|
39 |
+
|
40 |
+
TLDR:
|
41 |
+
```yaml
|
42 |
+
- type: field_match
|
43 |
+
name: title_query_match
|
44 |
+
rankingField: ranking.query
|
45 |
+
itemField: item.title
|
46 |
+
distance: cos
|
47 |
+
method:
|
48 |
+
type: bert
|
49 |
+
model: metarank/all-MiniLM-L6-v2
|
50 |
+
```
|
51 |
+
|
52 |
+
## Building the model
|
53 |
+
|
54 |
+
```shell
|
55 |
+
$> pip install -r requirements.txt
|
56 |
+
$> python convert.py
|
57 |
+
|
58 |
+
============= Diagnostic Run torch.onnx.export version 2.0.0+cu117 =============
|
59 |
+
verbose: False, log level: Level.ERROR
|
60 |
+
======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================
|
61 |
+
|
62 |
+
```
|
63 |
+
|
64 |
+
## License
|
65 |
+
|
66 |
+
Apache 2.0
|
convert.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import torch
|
3 |
+
|
4 |
+
max_seq_length=128
|
5 |
+
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/ms-marco-MiniLM-L-6-v2')
|
7 |
+
model.eval()
|
8 |
+
|
9 |
+
inputs = {"input_ids": torch.ones(1, max_seq_length, dtype=torch.int64),
|
10 |
+
"attention_mask": torch.ones(1, max_seq_length, dtype=torch.int64),
|
11 |
+
"token_type_ids": torch.ones(1, max_seq_length, dtype=torch.int64)}
|
12 |
+
|
13 |
+
symbolic_names = {0: 'batch_size', 1: 'max_seq_len'}
|
14 |
+
|
15 |
+
torch.onnx.export(model, args=tuple(inputs.values()), f='pytorch_model.onnx', export_params=True,
|
16 |
+
input_names=['input_ids', 'attention_mask', 'token_type_ids'], output_names=['last_hidden_state'],
|
17 |
+
dynamic_axes={'input_ids': symbolic_names, 'attention_mask': symbolic_names, 'token_type_ids': symbolic_names})
|
18 |
+
|
pytorch_model.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c5859df0aba64ad0439c47fd76c21ab6ff16d41289470b3f86c532b3896f14b
|
3 |
+
size 90996922
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers==2.2.2
|
2 |
+
torch==2.0.0
|
3 |
+
onnx==1.13.1
|
4 |
+
huggingface_hub==0.13.3
|
vocab.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:07eced375cec144d27c900241f3e339478dec958f92fddbc551f295c992038a3
|
3 |
+
size 231508
|