JunWangSpace commited on
Commit
28ae26f
Β·
verified Β·
1 Parent(s): 5037165

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -35,3 +35,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  adviser/tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
  embedder/tokenizer.json filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  adviser/tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
  embedder/tokenizer.json filter=lfs diff=lfs merge=lfs -text
38
+ figures/intro.png filter=lfs diff=lfs merge=lfs -text
39
+ figures/method.png filter=lfs diff=lfs merge=lfs -text
40
+ figures/mmeb-v2.png filter=lfs diff=lfs merge=lfs -text
41
+ figures/zero-shot.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - TIGER-Lab/MMEB-train
5
+ language:
6
+ - en
7
+ base_model:
8
+ - Qwen/Qwen3-VL-4B-Instruct
9
+ library_name: transformers
10
+ tags:
11
+ - Retrieval
12
+ - Multimodal
13
+ - Embedding
14
+ - Chain-of-Thought
15
+ - Reinforcement-Learning
16
+ pipeline_tag: image-text-to-text
17
+ ---
18
+
19
+ <div align="center">
20
+
21
+ <h1>UniME-R1-4B: Learning from Failures for Unified Multimodal Retrieval</h1>
22
+
23
+ <a href="#">Zelong Sun*</a>,</span>
24
+ <a href="#">Jun Wang*</a>,</span>
25
+ <a href="#">Kaicheng Yang</a>,</span>
26
+ <a href="#">Tiancheng Gu</a>,</span>
27
+ Ziyong Feng,</span>
28
+ <a href="#">Zhiwu Lu</a></span>
29
+
30
+ Glint Lab
31
+
32
+ [![GitHub](https://img.shields.io/badge/⭐-GitHub-black?logo=github)](https://github.com/deepglint/UniME-R1)
33
+ [![Paper](https://img.shields.io/badge/πŸ“„-Paper-b31b1b.svg)]()
34
+ [![Model](https://img.shields.io/badge/πŸ€—-UniME--R1_Models-yellow)](https://huggingface.co/DeepGlint-AI)
35
+ </div>
36
+
37
+ UniME-R1 is an **Embedder–Adviser** framework that learns to reason over *retrieved candidates* (not the query alone) and generate **Retrieval-Centric Chain-of-Thought (RC-CoT)** to correct retrieval failures. This repository ships the **4B-scale** pair: a Qwen3-VL-4B dual-mode Embedder and the Qwen3-VL-4B retrieval-aware Adviser β€” the best-performing configuration in the paper.
38
+
39
+ ## πŸ’‘ Highlights
40
+
41
+ - **Retrieval-Centric CoT (RC-CoT)** β€” The Adviser analyzes the *actual* top-k retrieved candidates to diagnose model-specific confusion, then emits `<cot_focus>` (which discriminative cues are missing) and `<cot_answer>` (a concise corrected query) to redirect retrieval.
42
+
43
+ <div align="center">
44
+ <img src="figures/intro.png" width="95%">
45
+ </div>
46
+
47
+ - **Dual-Mode Embedder** β€” A single VLM backbone produces two embeddings via special tokens: `<dis_emb>` for fast discriminative retrieval and `<gen_emb>` for RC-CoT-enhanced re-retrieval. Candidates are encoded **once** with `<dis_emb>` and reused across both paths β€” no candidate-side CoT, no index rebuilding.
48
+ - **Adaptive Rerank-or-Retrieve** β€” The Adviser predicts whether a match exists in the top-k set. If yes, it reranks; if not, it appends RC-CoT to the query and re-retrieves over the full corpus.
49
+ - **Retrieval-Oriented GRPO** β€” The Adviser is optimized with a 4-component reward (format / NDCG rerank / CoT-embedding quality / judge decision) that calls a **frozen Embedder API** to score the Adviser's CoT against mined hard negatives, so the RL signal reflects real end-to-end retrieval quality.
50
+
51
+ <div align="center">
52
+ <img src="figures/method.png" width="100%">
53
+ </div>
54
+
55
+ ## 🧱 Model Components
56
+
57
+ This release contains two sub-directories:
58
+
59
+ | Component | Backbone | Format | Notes |
60
+ |-----------|----------|--------|-------|
61
+ | **Embedder** (`embedder/`) | Qwen3-VL-4B-Instruct | LoRA (DoRA, r=16, Ξ±=64) + `new_token_embeddings.pt` | Adds `<dis_emb>` / `<gen_emb>` tokens; pooling at the special-token position |
62
+ | **Adviser** (`adviser/`) | Qwen3-VL-4B-Instruct | Full merged weights (bf16) | Outputs 5 structured XML fields; served with vLLM |
63
+
64
+ ```
65
+ β”œβ”€β”€ adviser/ # Qwen3-VL-4B Adviser (full weights, vLLM-ready)
66
+ β”‚ β”œβ”€β”€ model-0000{1,2}-of-00002.safetensors
67
+ β”‚ β”œβ”€β”€ config.json / generation_config.json
68
+ β”‚ β”œβ”€β”€ preprocessor_config.json / video_preprocessor_config.json
69
+ β”‚ └── tokenizer.json / chat_template.jinja
70
+ └── embedder/ # Qwen3-VL-4B Embedder (LoRA adapter)
71
+ β”œβ”€β”€ adapter_config.json
72
+ β”œβ”€β”€ adapter_model.safetensors
73
+ β”œβ”€β”€ new_token_embeddings.pt # trained <dis_emb>/<gen_emb> embeddings
74
+ β”œβ”€β”€ config.json
75
+ └── preprocessor_config.json / video_preprocessor_config.json
76
+ ```
77
+
78
+ > The Embedder is released as a **PEFT/LoRA adapter** β€” load it on top of `Qwen/Qwen3-VL-4B-Instruct`. The two special tokens (`<dis_emb>`=151670, `<gen_emb>`=151669) and their embeddings are provided via `added_tokens.json` + `new_token_embeddings.pt`.
79
+
80
+ The Adviser always emits five structured fields:
81
+
82
+ | Field | Role |
83
+ |-------|------|
84
+ | `<rerank_think>` | Candidate-by-candidate relevance analysis |
85
+ | `<rerank_list>` | Predicted candidate ordering (JSON array, 0-based) |
86
+ | `<rerank_judge>` | Path decision: best-match ID, or `-1` if none matches |
87
+ | `<cot_focus>` | Retrieval-failure diagnosis β€” which discriminative cues are confused |
88
+ | `<cot_answer>` | Concise refined query text for re-retrieval |
89
+
90
+ ## πŸš€ Quick Start
91
+
92
+ ```bash
93
+ git clone https://github.com/deepglint/UniME-R1.git
94
+ cd UniME-R1
95
+ ```
96
+
97
+ ```bash
98
+ conda create -n vlm2vec python=3.10 -y
99
+ conda activate vlm2vec
100
+
101
+ # Install torch matching your CUDA first, e.g.:
102
+ # pip install torch==2.5.1 torchvision --index-url https://download.pytorch.org/whl/cu121
103
+ # pip install flash-attn==2.7.3 --no-build-isolation
104
+
105
+ pip install -r Embedder/requirements.txt
106
+ ```
107
+
108
+ ### πŸ” Embedder-only evaluation (direct `<dis_emb>` retrieval)
109
+
110
+ ```bash
111
+ cd Embedder
112
+ bash shell/eval/eval.sh image "../models/UniME-R1-4B/embedder"
113
+ ```
114
+
115
+ ### 🎯 Full Adviser evaluation (rerank + RC-CoT iterative retrieval)
116
+
117
+ Serve the Adviser via vLLM, then run the unified evaluation:
118
+
119
+ ```bash
120
+ vllm serve models/UniME-R1-4B/adviser --tensor-parallel-size 8 --port 9000
121
+
122
+ cd RL/eval
123
+ export EMBEDDER_CHECKPOINT="../../models/UniME-R1-4B/embedder"
124
+ export ADVISER_MODEL="Qwen3-VL-4B-Instruct"
125
+ export ADVISER_URL="http://127.0.0.1:9000/v1"
126
+ bash eval.sh image # image | visdoc | video | uvrb | image_caption
127
+ ```
128
+
129
+ ## πŸ“Š Results
130
+
131
+ ### πŸ† MMEB-V2
132
+
133
+ UniME-R1 achieves the best overall performance at both model scales. Notably, the 2B model already outperforms all medium-size (4B–7B) baselines, indicating the gains stem from the framework rather than model scale alone.
134
+
135
+ <div align="center">
136
+ <img src="figures/mmeb-v2.png" width="95%">
137
+ </div>
138
+
139
+ ### 🌈 Zero-shot General Retrieval
140
+
141
+ <div align="center">
142
+ <img src="figures/zero-shot.png" width="90%">
143
+ </div>
144
+
145
+ ## πŸ–ŠοΈ Citation
146
+
147
+ If you find this repository useful, please use the following BibTeX entry for citation.
148
+
149
+ ```bibtex
150
+ @misc{unime-r1,
151
+ title = {Learning from Failures: Retrieval-Centric CoT via Hard Negatives for Unified Multimodal Retrieval},
152
+ author = {Sun, Zelong and Wang, Jun and Yang, Kaicheng and Gu, Tiancheng and Feng, Ziyong and Lu, Zhiwu},
153
+ year = {2025},
154
+ url = {https://github.com/deepglint/UniME-R1}
155
+ }
156
+ ```
157
+
158
+ <div align="center">
159
+ ⭐ Don't forget to star this repository if you find it helpful!
160
+ </div>
figures/intro.png ADDED

Git LFS Details

  • SHA256: b111914d4e7674e48aa3c63b8b188439b9095c2e8667bb71dc6a2a83bc44165a
  • Pointer size: 131 Bytes
  • Size of remote file: 552 kB
figures/method.png ADDED

Git LFS Details

  • SHA256: b239b7b2869c5418a7e5d51da7215b1f107da57dbf348eba7de1185abf33d39d
  • Pointer size: 131 Bytes
  • Size of remote file: 697 kB
figures/mmeb-v2.png ADDED

Git LFS Details

  • SHA256: a1832425bf8a30ffb7e1642fd71d6da1a68635304ed56182ccdea15cbb5a2ba6
  • Pointer size: 131 Bytes
  • Size of remote file: 400 kB
figures/zero-shot.png ADDED

Git LFS Details

  • SHA256: ef2e6ba2f8900331969adc598e0996084dd7ded253b2e048c58669d0c6c06919
  • Pointer size: 131 Bytes
  • Size of remote file: 167 kB