Skip to content

Instantly share code, notes, and snippets.

@frutik
Last active September 22, 2024 11:43
Show Gist options
  • Save frutik/3b810324109af7d820f598d2d4501002 to your computer and use it in GitHub Desktop.
Save frutik/3b810324109af7d820f598d2d4501002 to your computer and use it in GitHub Desktop.
import onnxruntime as ort
from transformers import AutoTokenizer
session = ort.InferenceSession('./bge-small-en/model.onnx')
tokenizer = AutoTokenizer.from_pretrained("./bge-small-en")
inputs = tokenizer("hello world.", padding="longest", return_tensors="np")
inputs_onnx = {key: ort.OrtValue.ortvalue_from_numpy(value) for key, value in inputs.items()}
outputs = session.run(None, inputs_onnx)
print(f"Number of Dense Vectors: {len(outputs[0])}")
print(f"Dense Vector Length: {len(outputs[0][0])}")
import onnxruntime as ort
import numpy as np
from transformers import AutoTokenizer
session = ort.InferenceSession('./multilingual-e5-small/model.onnx')
tokenizer = AutoTokenizer.from_pretrained("./multilingual-e5-small")
inputs = tokenizer("hello world.", padding="longest", return_tensors="np")
inputs["token_type_ids"] = np.zeros_like(inputs["input_ids"])
inputs_onnx = {key: ort.OrtValue.ortvalue_from_numpy(value) for key, value in inputs.items()}
outputs = session.run(None, inputs_onnx)
tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment