Feature Extraction
sentence-transformers
Safetensors
Transformers
qwen3
text-generation
sentence-similarity
text-embeddings-inference
Instructions to use Qwen/Qwen3-Embedding-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Qwen/Qwen3-Embedding-4B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Qwen/Qwen3-Embedding-4B") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers
How to use Qwen/Qwen3-Embedding-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Qwen/Qwen3-Embedding-4B")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Embedding-4B") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Embedding-4B") - Notebooks
- Google Colab
- Kaggle
ONNX Conversion
#10
by shuttie - opened
A copy of https://huggingface.co/Qwen/Qwen3-Embedding-0.6B/discussions/18 but for the 4B model.
This is a SBERT-based ONNX conversion of the model.
Code used:
from sentence_transformers import (
SentenceTransformer,
export_dynamic_quantized_onnx_model,
)
model = SentenceTransformer("Qwen/Qwen3-Embedding-4B", backend="onnx")
model.save_pretrained("export")
for tpe in ["arm64", "avx2", "avx512", "avx512_vnni"]:
export_dynamic_quantized_onnx_model(model, tpe, "export")
Note that latest stable optimum version as for today (1.25.3) does not yet support onnx conversion of qwen3-based models, but it's available in master. So you need to have the following requirements.txt:
sentence-transformers
optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
Also a side note: exporting optimized model does not work due to lack of Qwen3 onnx optimization support in Optimum.
shuttie changed pull request status to open