Views
No views yet

| Model Type | Models | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
|---|---|---|---|---|---|---|---|
| Text Embedding | Qwen3-Embedding-0.6B | 0.6B | 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-0.6B | 0.6B | 28 | 32K | - | - | Yes |
| Text Reranking | Qwen3-Reranker-4B | 4B | 36 | 32K | - | - | Yes |
| Text Reranking | Qwen3-Reranker-8B | 8B | 36 | 32K | - | - | Yes |
Note:
MRL Supportindicates whether the embedding model supports custom dimensions for the final embedding.Instruction Awarenotes 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.
KeyError: 'qwen3'1# Requires transformers>=4.51.0
2import torch
3from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM
4
5def format_instruction(instruction, query, doc):
6 if instruction is None:
7 instruction = 'Given a web search query, retrieve relevant passages that answer the query'
8 output = "<Instruct>: {instruction}\n<Query>: {query}\n<Document>: {doc}".format(instruction=instruction,query=query, doc=doc)
9 return output
10
11def process_inputs(pairs):
12 inputs = tokenizer(
13 pairs, padding=False, truncation='longest_first',
14 return_attention_mask=False, max_length=max_length - len(prefix_tokens) - len(suffix_tokens)
15 )
16 for i, ele in enumerate(inputs['input_ids']):
17 inputs['input_ids'][i] = prefix_tokens + ele + suffix_tokens
18 inputs = tokenizer.pad(inputs, padding=True, return_tensors="pt", max_length=max_length)
19 for key in inputs:
20 inputs[key] = inputs[key].to(model.device)
21 return inputs
22
23@torch.no_grad()
24def compute_logits(inputs, **kwargs):
25 batch_scores = model(**inputs).logits[:, -1, :]
26 true_vector = batch_scores[:, token_true_id]
27 false_vector = batch_scores[:, token_false_id]
28 batch_scores = torch.stack([false_vector, true_vector], dim=1)
29 batch_scores = torch.nn.functional.log_softmax(batch_scores, dim=1)
30 scores = batch_scores[:, 1].exp().tolist()
31 return scores
32
33tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Reranker-8B", padding_side='left')
34
35model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-8B").eval()
36# We recommend enabling flash_attention_2 for better acceleration and memory saving.
37# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Reranker-8B", torch_dtype=torch.float16, attn_implementation="flash_attention_2").cuda().eval()
38
39token_false_id = tokenizer.convert_tokens_to_ids("no")
40token_true_id = tokenizer.convert_tokens_to_ids("yes")
41max_length = 8192
42
43prefix = "<|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"
44suffix = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"
45prefix_tokens = tokenizer.encode(prefix, add_special_tokens=False)
46suffix_tokens = tokenizer.encode(suffix, add_special_tokens=False)
47
48task = 'Given a web search query, retrieve relevant passages that answer the query'
49
50queries = ["What is the capital of China?",
51 "Explain gravity",
52]
53
54documents = [
55 "The capital of China is Beijing.",
56 "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
57]
58
59pairs = [format_instruction(task, query, doc) for query, doc in zip(queries, documents)]
60
61# Tokenize the input texts
62inputs = process_inputs(pairs)
63scores = compute_logits(inputs)
64
65print("scores: ", scores)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%.| Model | Param | MTEB-R | CMTEB-R | MMTEB-R | MLDR | MTEB-Code | FollowIR |
|---|---|---|---|---|---|---|---|
| Qwen3-Embedding-0.6B | 0.6B | 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 | 0.6B | 57.03 | 72.16 | 58.36 | 59.51 | 41.38 | -0.01 |
| Qwen3-Reranker-0.6B | 0.6B | 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-0.6B.
@misc{qwen3-embedding,
title = {Qwen3-Embedding},
url = {https://qwenlm.github.io/blog/qwen3/},
author = {Qwen Team},
month = {May},
year = {2025}
}