Sentence Similarity
Transformers
Safetensors
sentence-transformers
English
Chinese
Vietnamese
qwen3
feature-extraction
embedding
text-embedding
quantization
bitsandbytes
bnb-4bit
text-embeddings-inference
4-bit precision
Instructions to use dinhhungitsoft/Qwen3-Embedding-4B-bnb4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dinhhungitsoft/Qwen3-Embedding-4B-bnb4 with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("dinhhungitsoft/Qwen3-Embedding-4B-bnb4") model = AutoModel.from_pretrained("dinhhungitsoft/Qwen3-Embedding-4B-bnb4", device_map="auto") - sentence-transformers
How to use dinhhungitsoft/Qwen3-Embedding-4B-bnb4 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("dinhhungitsoft/Qwen3-Embedding-4B-bnb4") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Qwen3-Embedding-4B-bnb4
This is a 4-bit quantized version of Qwen/Qwen3-Embedding-4B using BitsAndBytes NF4 quantization.
Model Details
- Base Model: Qwen/Qwen3-Embedding-4B
- Quantization Method: BitsAndBytes 4-bit (NF4)
- Quantization Configuration:
bnb_4bit_quant_type: "nf4"bnb_4bit_use_double_quant: Truebnb_4bit_compute_dtype: float16
- Model Size: ~2.5GB (down from ~8GB original)
- Use Case: Text embedding for semantic search, retrieval, and similarity tasks
Performance
Tested on Vietnamese corpus (100 documents) with 20 queries:
- Accuracy@1: 90%
- MRR: 94.17%
- Recall@3: 100%
- Recall@5: 100%
Usage
With Transformers + BitsAndBytes
from transformers import AutoTokenizer, AutoModel
import torch
model_name = "dinhhungitsoft/Qwen3-Embedding-4B-bnb4"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
device_map="auto"
)
def embed(texts):
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt", max_length=512)
inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model(**inputs)
embeddings = outputs.last_hidden_state[:, 0, :] # CLS token
# Normalize embeddings
embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
return embeddings.cpu().numpy()
texts = ["Hà Nội là thủ đô của Việt Nam", "Paris is the capital of France"]
embeddings = embed(texts)
print(embeddings.shape) # (2, embedding_dim)
With vLLM (Recommended for serving)
docker run -d \
--gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-p 8000:8000 \
--ipc=host \
vllm/vllm-openai:latest \
--model dinhhungitsoft/Qwen3-Embedding-4B-bnb4 \
--trust-remote-code \
--gpu-memory-utilization 0.6 \
--max-model-len 4096
Then query via OpenAI-compatible API:
import requests
response = requests.post(
"http://localhost:8000/v1/embeddings",
json={
"model": "dinhhungitsoft/Qwen3-Embedding-4B-bnb4",
"input": ["Your text here"]
}
)
embeddings = response.json()["data"][0]["embedding"]
Languages
Optimized for:
- English
- Chinese
- Vietnamese
- And other languages supported by Qwen3
Hardware Requirements
- GPU Memory: ~3-4GB VRAM (vs ~8GB for full precision)
- Recommended: NVIDIA GPU with CUDA support
- Tested on: RTX 3050 8GB
Limitations
- Quantization may result in minor accuracy loss compared to full precision
- Requires BitsAndBytes library for loading
- Best performance with NVIDIA GPUs
Citation
If you use this model, please cite the original Qwen3 model:
@article{qwen3,
title={Qwen3 Technical Report},
author={Qwen Team},
year={2024}
}
License
Apache 2.0 (inherited from base model)
- Downloads last month
- 57