Jia Huei Tan commited on
Commit
52f64c5
1 Parent(s): e365f1a

Update README

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