Yes! The model you're referring to — prdev/mini-gte — is a lightweight sentence embedding model based on MiniLM and trained to be compatible with GTE embeddings (used for semantic search, particularly efficient in low-resource environments).
We can convert this model to ONNX using the Hugging Face transformers library along with the optimum package, which supports ONNX export.
✅ Steps to Export prdev/mini-gte to ONNX:
🔧 1. Install dependencies
You’ll need transformers, optimum, onnx, and optionally onnxruntime to run the model.
pip install transformers optimum[exporters] onnx onnxruntime
🧠 2. Python Script to Export to ONNX
from transformers import AutoTokenizer, AutoModel
from optimum.exporters.onnx import main_export
from pathlib import Path
# Model name
model_name = "prdev/mini-gte"
# Output directory
output_dir = Path("onnx_model")
# Exporter CLI style via main_export
main_export(
model_name_or_path=model_name,
output=output_dir,
task="feature-extraction", # For sentence embeddings
opset=13, # ONNX opset version (13 for compatibility)
)
This will save the ONNX version of the model in ./onnx_model.
📦 Output Files
After running, you’ll get files like:
model.onnx – The exported model
config.json – Configuration
tokenizer_config.json, vocab.txt, etc. – Tokenizer files (if applicable)
🧪 (Optional) Run Inference with ONNXRuntime
import onnxruntime as ort
from transformers import AutoTokenizer
import numpy as np
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("prdev/mini-gte")
# Encode input
inputs = tokenizer("This is a test sentence", return_tensors="np", padding=True, truncation=True)
# ONNX session
session = ort.InferenceSession("onnx_model/model.onnx")
# Run inference
inputs_onnx = {k: v for k, v in inputs.items()}
outputs = session.run(None, inputs_onnx)
# Extract embeddings
embeddings = outputs[0]
print("Embeddings shape:", embeddings.shape)
Notes:
task="feature-extraction" is suitable for sentence encoders like mini-gte.
- If you only need the pooled sentence embedding, you may want to post-process the final hidden states (e.g., CLS pooling or mean pooling).
Would you like a mean-pooling wrapper ONNX model too (i.e., to export sentence embeddings directly)?