iLampard commited on
Commit
caad463
·
verified ·
1 Parent(s): 7f26d79

Upload CoREB-Reranker (merged Qwen3-Reranker-4B + LoRA)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,99 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen3-Reranker-4B
4
+ tags:
5
+ - code-search
6
+ - reranker
7
+ - code-retrieval
8
+ - peft
9
+ - lora
10
+ language:
11
+ - en
12
+ - code
13
+ datasets:
14
+ - hq-bench/coreb
15
+ pipeline_tag: text-classification
16
+ library_name: transformers
17
+ ---
18
+
19
+ [![Project Page](https://img.shields.io/badge/Project-Page-blue)](https://hq-bench.github.io/coreb-page/)
20
+ [![arXiv](https://img.shields.io/badge/arXiv-2605.04615-b31b1b.svg)](https://arxiv.org/abs/2605.04615)
21
+ [![Dataset](https://img.shields.io/badge/HuggingFace-Dataset-yellow)](https://huggingface.co/datasets/hq-bench/coreb)
22
+ [![Code](https://img.shields.io/badge/GitHub-Code-black)](https://github.com/hq-bench/coreb)
23
+
24
+ # CoREB-Reranker
25
+
26
+ **CoREB-Reranker** is a code reranker fine-tuned from [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B) via LoRA on the [CoREB](https://huggingface.co/datasets/hq-bench/coreb) benchmark training set. It is the **only reranker we evaluate that achieves consistent gains across all three code search tasks** (text-to-code, code-to-text, and code-to-code).
27
+
28
+ ## Highlights
29
+
30
+ - Fine-tuned from Qwen3-Reranker-4B using LoRA (rank=16, alpha=16) on **3.1M training samples** from CoREB v202602
31
+ - Evaluated on CoREB v202603 (problem-disjoint from training set, no data leakage)
32
+ - Achieves **positive reranking delta on all three tasks**, unlike all off-the-shelf rerankers tested
33
+
34
+ ## Reranking Results (nDCG@10 Delta %)
35
+
36
+ Reranking delta on CoREB v202603, using GemEmb-2 as the first-stage retriever:
37
+
38
+ | Reranker | Text-to-Code | Code-to-Text | Code-to-Code |
39
+ |----------|:---:|:---:|:---:|
40
+ | Jina Reranker v2 | -8.3 | -22.4 | -8.8 |
41
+ | Jina Reranker v3 | -2.2 | -5.0 | -0.1 |
42
+ | Qwen3-Reranker-0.6B | -0.6 | -8.2 | -2.3 |
43
+ | Qwen3-Reranker-4B | -0.1 | -3.2 | +3.3 |
44
+ | **CoREB-Reranker (ours)** | **+1.5** | **+0.5** | **+4.0** |
45
+
46
+ ## Training Details
47
+
48
+ - **Base model**: [Qwen/Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B)
49
+ - **Method**: LoRA (rank=16, alpha=16, dropout=0.05)
50
+ - **Target modules**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
51
+ - **Training data**: CoREB v202602 with graded relevance qrels (rel=2 positives, rel=1 hard negatives, easy negatives sampled from corpus)
52
+ - **Evaluation data**: CoREB v202603 (problem-disjoint from training; covers a different contest time window)
53
+ - **Training samples**: ~3.1M (3,803 queries × ~32 candidates each, across text-to-code, code-to-text, and code-to-code tasks)
54
+ - **Top-k retrieval for reranking**: 128
55
+
56
+ ## Usage
57
+
58
+ CoREB-Reranker follows the same usage pattern as Qwen3-Reranker. Given a query and a list of candidate documents from first-stage retrieval, the reranker scores each query-document pair:
59
+
60
+ ```python
61
+ from transformers import AutoModelForCausalLM, AutoTokenizer
62
+
63
+ model_id = "hq-bench/coreb-code-reranker"
64
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
65
+ model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
66
+
67
+ # Format as Qwen3-Reranker input
68
+ query = "binary search implementation"
69
+ document = "def binary_search(arr, target):\n lo, hi = 0, len(arr) - 1\n ..."
70
+
71
+ 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'
72
+ suffix = "<|im_end|>\n<|im_start|>assistant\n"
73
+ instruct = "Given a code search query, does the following code snippet match the query intent?"
74
+
75
+ prompt = f"{prefix}<Instruct>: {instruct}\n<Query>: {query}\n<Document>: {document}{suffix}"
76
+
77
+ inputs = tokenizer(prompt, return_tensors="pt")
78
+ outputs = model(**inputs)
79
+
80
+ # Score is the logit difference between "yes" and "no" tokens
81
+ yes_id = tokenizer.convert_tokens_to_ids("yes")
82
+ no_id = tokenizer.convert_tokens_to_ids("no")
83
+ logits = outputs.logits[0, -1, :]
84
+ score = logits[yes_id] - logits[no_id]
85
+ print(f"Relevance score: {score.item():.4f}")
86
+ ```
87
+
88
+ For batch reranking with the CoREB evaluation pipeline, see the [CoREB repository](https://github.com/hq-bench/coreb).
89
+
90
+ ## Citation
91
+
92
+ ```bibtex
93
+ @article{xue2026coreb,
94
+ title={Beyond Retrieval: A Multitask Benchmark and Reranker for Code Search},
95
+ author={Xue, Siqiao and Liao, Zihan and Qin, Jin and Zhang, Ziyin and Mu, Yixiang and Zhou, Fan and Yu, Hang},
96
+ journal={arXiv preprint arXiv:2605.04615},
97
+ year={2026}
98
+ }
99
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set instruction = messages | selectattr("role", "eq", "system") | map(attribute="content") | first | default("Given a web search query, retrieve relevant passages that answer the query") -%}
2
+ {%- set query_text = messages | selectattr("role", "eq", "query") | map(attribute="content") | first -%}
3
+ {%- set document_text = messages | selectattr("role", "eq", "document") | map(attribute="content") | first -%}
4
+ <|im_start|>system
5
+ Judge 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|>
6
+ <|im_start|>user
7
+ <Instruct>: {{ instruction }}
8
+ <Query>: {{ query_text }}
9
+ <Document>: {{ document_text }}<|im_end|>
10
+ <|im_start|>assistant
11
+ <think>
12
+
13
+ </think>
14
+
15
+
config.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "dtype": "bfloat16",
9
+ "eos_token_id": 151645,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 2560,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 9728,
15
+ "layer_types": [
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention"
52
+ ],
53
+ "max_position_embeddings": 40960,
54
+ "max_window_layers": 36,
55
+ "model_type": "qwen3",
56
+ "num_attention_heads": 32,
57
+ "num_hidden_layers": 36,
58
+ "num_key_value_heads": 8,
59
+ "pad_token_id": null,
60
+ "rms_norm_eps": 1e-06,
61
+ "rope_parameters": {
62
+ "rope_theta": 1000000,
63
+ "rope_type": "default"
64
+ },
65
+ "sliding_window": null,
66
+ "tie_word_embeddings": true,
67
+ "transformers_version": "5.6.0",
68
+ "use_cache": true,
69
+ "use_sliding_window": false,
70
+ "vocab_size": 151669
71
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.6.0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3222f8eae96b717d299dadad3099a85f35db32b3b73baa57bd6e96c02fbb35e
3
+ size 8043615040
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
3
+ size 11422650
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "is_local": false,
9
+ "local_files_only": false,
10
+ "model_max_length": 131072,
11
+ "pad_token": "<|endoftext|>",
12
+ "split_special_tokens": false,
13
+ "tokenizer_class": "Qwen2Tokenizer",
14
+ "unk_token": null
15
+ }