Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,65 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
- ar
|
5 |
+
- zh
|
6 |
+
- fr
|
7 |
+
- de
|
8 |
+
- it
|
9 |
+
- ja
|
10 |
+
- ko
|
11 |
+
- nl
|
12 |
+
- pl
|
13 |
+
- pt
|
14 |
+
- es
|
15 |
+
- th
|
16 |
+
- tr
|
17 |
+
- ru
|
18 |
+
tags:
|
19 |
+
- feature-extraction
|
20 |
+
- onnx
|
21 |
+
- use
|
22 |
+
- text-embedding
|
23 |
+
- tensorflow-hub
|
24 |
license: apache-2.0
|
25 |
+
inference: false
|
26 |
+
widget:
|
27 |
+
- text: Thank goodness ONNX is available, it is lots faster!
|
28 |
---
|
29 |
+
### Universal Sentence Encoder Multilingual v3
|
30 |
+
|
31 |
+
ONNX version of [https://tfhub.dev/google/universal-sentence-encoder-multilingual/3](https://tfhub.dev/google/universal-sentence-encoder-multilingual/3)
|
32 |
+
|
33 |
+
The original TFHub version of the model is referenced in other models here E.g. [https://huggingface.co/vprelovac/universal-sentence-encoder-large-5](https://huggingface.co/vprelovac/universal-sentence-encoder-large-5)
|
34 |
+
|
35 |
+
### Overview
|
36 |
+
|
37 |
+
See overview and license details at [https://tfhub.dev/google/universal-sentence-encoder-multilingual/3](https://tfhub.dev/google/universal-sentence-encoder-multilingual/3)
|
38 |
+
|
39 |
+
This model is a full precision version of the TFHub original, in ONNX format.
|
40 |
+
|
41 |
+
It uses the [ONNXRuntime Extensions](https://github.com/microsoft/onnxruntime-extensions) to embed the tokenizer within the ONNX model, so no seperate tokenizer is needed, and text is fed directly into the ONNX model.
|
42 |
+
|
43 |
+
Post-processing (E.g. pooling, normalization) is also implemented within the ONNX model, so no separate processing is necessary.
|
44 |
+
|
45 |
+
### How to use
|
46 |
+
|
47 |
+
```python
|
48 |
+
import onnxruntime as ort
|
49 |
+
from onnxruntime_extensions import get_library_path
|
50 |
+
from os import cpu_count
|
51 |
+
|
52 |
+
sentences = ["hello world"]
|
53 |
+
|
54 |
+
def load_onnx_model(model_filepath):
|
55 |
+
_options = ort.SessionOptions()
|
56 |
+
_options.inter_op_num_threads, _options.intra_op_num_threads = cpu_count(), cpu_count()
|
57 |
+
_options.register_custom_ops_library(get_library_path())
|
58 |
+
_providers = ["CPUExecutionProvider"] # could use ort.get_available_providers()
|
59 |
+
return ort.InferenceSession(path_or_bytes=model_filepath, sess_options=_options, providers=_providers)
|
60 |
+
|
61 |
+
model = load_onnx_model("filepath_for_model_dot_onnx")
|
62 |
+
|
63 |
+
model_outputs = model.run(output_names=["outputs"], input_feed={"inputs": sentences})[0]
|
64 |
+
print(model_outputs)
|
65 |
+
```
|