Qwen3-Reranker-4B-Seq-Cls
This is a copy of the Qwen3-Reranker-4B model, part of the Qwen3 Reranker series, modified as a sequence classification model instead. See Updated Usage for details on how to use it, or Original Usage for the original usage.
See this discussion for details on the conversion approach.
Highlights
The Qwen3 Embedding model series is the latest proprietary model of the Qwen family, specifically designed for text embedding and ranking tasks. Building upon the dense foundational models of the Qwen3 series, it provides a comprehensive range of text embeddings and reranking models in various sizes (4B, 4B, and 8B). This series inherits the exceptional multilingual capabilities, long-text understanding, and reasoning skills of its foundational model. The Qwen3 Embedding series represents significant advancements in multiple text embedding and ranking tasks, including text retrieval, code retrieval, text classification, text clustering, and bitext mining.
Exceptional Versatility: The embedding model has achieved state-of-the-art performance across a wide range of downstream application evaluations. The 8B size embedding model ranks No.1 in the MTEB multilingual leaderboard (as of June 5, 2025, score 70.58), while the reranking model excels in various text retrieval scenarios.
Comprehensive Flexibility: The Qwen3 Embedding series offers a full spectrum of sizes (from 4B to 8B) for both embedding and reranking models, catering to diverse use cases that prioritize efficiency and effectiveness. Developers can seamlessly combine these two modules. Additionally, the embedding model allows for flexible vector definitions across all dimensions, and both embedding and reranking models support user-defined instructions to enhance performance for specific tasks, languages, or scenarios.
Multilingual Capability: The Qwen3 Embedding series offer support for over 100 languages, thanks to the multilingual capabilites of Qwen3 models. This includes various programming languages, and provides robust multilingual, cross-lingual, and code retrieval capabilities.
Model Overview
Qwen3-Reranker-4B has the following features:
- Model Type: Text Reranking
- Supported Languages: 100+ Languages
- Number of Paramaters: 4B
- Context Length: 32k
For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our blog, GitHub.
Qwen3 Embedding Series Model list
Model Type | Models | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
---|---|---|---|---|---|---|---|
Text Embedding | Qwen3-Embedding-4B | 4B | 28 | 32K | 1024 | Yes | Yes |
Text Embedding | Qwen3-Embedding-4B | 4B | 36 | 32K | 2560 | Yes | Yes |
Text Embedding | Qwen3-Embedding-8B | 8B | 36 | 32K | 4096 | Yes | Yes |
Text Reranking | Qwen3-Reranker-4B | 4B | 28 | 32K | - | - | Yes |
Text Reranking | Qwen3-Reranker-4B | 4B | 36 | 32K | - | - | Yes |
Text Reranking | Qwen3-Reranker-8B | 8B | 36 | 32K | - | - | Yes |
Note:
MRL Support
indicates whether the embedding model supports custom dimensions for the final embedding.Instruction Aware
notes whether the embedding or reranking model supports customizing the input instruction according to different tasks.- Our evaluation indicates that, for most downstream tasks, using instructions (instruct) typically yields an improvement of 1% to 5% compared to not using them. Therefore, we recommend that developers create tailored instructions specific to their tasks and scenarios. In multilingual contexts, we also advise users to write their instructions in English, as most instructions utilized during the model training process were originally written in English.
Usage
With Transformers versions earlier than 4.51.0, you may encounter the following error:
KeyError: 'qwen3'
import numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"zhiqing/Qwen3-Reranker-4B-seq-cls-ONNX",
padding_side="left",
trust_remote_code=True,
)
PREFIX = '<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be "yes" or "no".<|im_end|>\n<|im_start|>user\n'
SUFFIX = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
DEFAULT_INS = "Given a web search query, retrieve relevant passages that answer the query"
def format_instruction(instruction, query, doc):
instruction = instruction or DEFAULT_INS
return f"{PREFIX}<Instruct>: {instruction}\n<Query>: {query}\n<Document>: {doc}{SUFFIX}"
queries = [
"Which planet is known as the Red Planet?",
]
documents = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
]
if len(queries) != len(documents):
if len(queries) == 1:
queries = queries * len(documents)
elif len(documents) == 1:
documents = documents * len(queries)
else:
raise ValueError("Length mismatch: either provide equal-length lists or one of them must have length 1.")
pairs = [format_instruction(DEFAULT_INS, q, d) for q, d in zip(queries, documents)]
enc = tokenizer(
pairs,
padding=True,
truncation=True,
max_length=8192,
return_tensors="np",
)
inputs = {
"input_ids": enc["input_ids"].astype(np.int64),
"attention_mask": enc["attention_mask"].astype(np.int64),
}
sess = ort.InferenceSession(
"Qwen3-Reranker-4B-seq-cls-ONNX/model.onnx",
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)
logits = sess.run(None, inputs)[0].squeeze(-1)
scores = 1 / (1 + np.exp(-logits))
preds = (scores > 0.5).tolist()
print("logits :", logits.tolist())
print("scores :", scores.tolist())
print("yes/no :", preds)
๐ Tip: We recommend that developers customize the instruct
according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an instruct
on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
Evaluation
Model | Param | MTEB-R | CMTEB-R | MMTEB-R | MLDR | MTEB-Code | FollowIR |
---|---|---|---|---|---|---|---|
Qwen3-Embedding-4B | 4B | 61.82 | 71.02 | 64.64 | 50.26 | 75.41 | 5.09 |
Jina-multilingual-reranker-v2-base | 0.3B | 58.22 | 63.37 | 63.73 | 39.66 | 58.98 | -0.68 |
gte-multilingual-reranker-base | 0.3B | 59.51 | 74.08 | 59.44 | 66.33 | 54.18 | -1.64 |
BGE-reranker-v2-m3 | 4B | 57.03 | 72.16 | 58.36 | 59.51 | 41.38 | -0.01 |
Qwen3-Reranker-4B | 4B | 65.80 | 71.31 | 66.36 | 67.28 | 73.42 | 5.41 |
Qwen3-Reranker-4B | 1.7B | 69.76 | 75.94 | 72.74 | 69.97 | 81.20 | 14.84 |
Qwen3-Reranker-8B | 8B | 69.02 | 77.45 | 72.94 | 70.19 | 81.22 | 8.05 |
Note:
- Evaluation results for reranking models. We use the retrieval subsets of MTEB(eng, v2), MTEB(cmn, v1), MMTEB and MTEB (Code), which are MTEB-R, CMTEB-R, MMTEB-R and MTEB-Code.
- All scores are our runs based on the top-100 candidates retrieved by dense embedding model Qwen3-Embedding-4B.
Citation
If you find our work helpful, feel free to give us a cite.
@misc{qwen3-embedding,
title = {Qwen3-Embedding},
url = {https://qwenlm.github.io/blog/qwen3/},
author = {Qwen Team},
month = {May},
year = {2025}
}
- Downloads last month
- 4
Model tree for zhiqing/Qwen3-Reranker-4B-seq-cls-ONNX
Base model
Qwen/Qwen3-4B-Base