Jia Huei Tan commited on
Commit
369dd1f
1 Parent(s): ab67c14

Update README

Browse files
Files changed (1) hide show
  1. README.md +46 -0
README.md CHANGED
@@ -1,3 +1,49 @@
1
  ---
 
 
 
 
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-similarity
5
+ language: en
6
  license: apache-2.0
7
  ---
8
+
9
+ # ONNX Conversion of [cross-encoder/ms-marco-TinyBERT-L-2](https://huggingface.co/cross-encoder/ms-marco-TinyBERT-L-2)
10
+
11
+ - ONNX model for CPU with O3 optimisation
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from itertools import product
17
+
18
+ from optimum.onnxruntime import ORTModelForSequenceClassification
19
+ from transformers import AutoTokenizer
20
+
21
+ sentences = [
22
+ "The llama (/ˈlɑːmə/) (Lama glama) is a domesticated South American camelid.",
23
+ "The alpaca (Lama pacos) is a species of South American camelid mammal.",
24
+ "The vicuña (Lama vicugna) (/vɪˈkuːnjə/) is one of the two wild South American camelids.",
25
+ ]
26
+ queries = ["What is a llama?", "What is a harimau?", "How to fly a kite?"]
27
+ pairs = list(product(queries, sentences))
28
+
29
+ model_name = "EmbeddedLLM/ms-marco-TinyBERT-L-2-v2-onnx-o3-cpu"
30
+ device = "cpu"
31
+ provider = "CPUExecutionProvider"
32
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
33
+ model = ORTModelForSequenceClassification.from_pretrained(
34
+ model_name, use_io_binding=True, provider=provider, device_map=device
35
+ )
36
+ inputs = tokenizer(
37
+ pairs,
38
+ padding=True,
39
+ truncation=True,
40
+ return_tensors="pt",
41
+ max_length=model.config.max_position_embeddings,
42
+ )
43
+ inputs = inputs.to(device)
44
+ scores = model(**inputs).logits.cpu().numpy()
45
+ # Sort most similar to least
46
+ pairs = sorted(zip(pairs, scores), key=lambda x: x[1], reverse=True)
47
+ for ps in pairs:
48
+ print(ps)
49
+ ```