The original TFHub version of the model is referenced in other models here E.g.
https://huggingface.co/vprelovac/universal-sentence-encoder-multilingual-3
This model is a full precision version of the TFHub original, in ONNX format.
It uses the
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.
Post-processing (E.g. pooling, normalization) is also implemented within the ONNX model, so no separate processing is necessary.
1import onnxruntime as ort
2from onnxruntime_extensions import get_library_path
3from os import cpu_count
4
5sentences = ["hello world"]
6
7def load_onnx_model(model_filepath):
8 _options = ort.SessionOptions()
9 _options.inter_op_num_threads, _options.intra_op_num_threads = cpu_count(), cpu_count()
10 _options.register_custom_ops_library(get_library_path())
11 _providers = ["CPUExecutionProvider"] # could use ort.get_available_providers()
12 return ort.InferenceSession(path_or_bytes=model_filepath, sess_options=_options, providers=_providers)
13
14model = load_onnx_model("filepath_for_model_dot_onnx")
15
16model_outputs = model.run(output_names=["outputs"], input_feed={"inputs": sentences})[0]
17print(model_outputs)