Jia Huei Tan commited on
Commit
fb9e68c
·
1 Parent(s): 2b9703e

Update README

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md CHANGED
@@ -1,3 +1,45 @@
1
  ---
 
 
 
 
 
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - feature-extraction
5
+ - sentence-similarity
6
+ language: en
7
  license: mit
8
  ---
9
+
10
+ # ONNX Conversion of [BAAI/bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5)
11
+
12
+ - ONNX model for CPU with O3 optimisation
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ import torch.nn.functional as F
18
+ from optimum.onnxruntime import ORTModelForFeatureExtraction
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
+
27
+ model_name = "EmbeddedLLM/bge-base-en-v1.5-onnx-o3-cpu"
28
+ device = "cpu"
29
+ provider = "CPUExecutionProvider"
30
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
31
+ model = ORTModelForFeatureExtraction.from_pretrained(
32
+ model_name, use_io_binding=True, provider=provider, device_map=device
33
+ )
34
+ inputs = tokenizer(
35
+ sentences,
36
+ padding=True,
37
+ truncation=True,
38
+ return_tensors="pt",
39
+ max_length=model.config.max_position_embeddings,
40
+ )
41
+ inputs = inputs.to(device)
42
+ embeddings = model(**inputs).last_hidden_state[:, 0]
43
+ embeddings = F.normalize(embeddings, p=2, dim=1)
44
+ print(embeddings.cpu().numpy().shape)
45
+ ```