Last active
September 22, 2024 11:43
-
-
Save frutik/3b810324109af7d820f598d2d4501002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])}") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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