Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,121 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- CodeGoat24/HPD
|
5 |
+
- CodeGoat24/OIP
|
6 |
+
- CodeGoat24/EvalMuse
|
7 |
+
- CodeGoat24/ShareGPTVideo-DPO
|
8 |
+
- CodeGoat24/LLaVA-Critic-113k
|
9 |
+
- CodeGoat24/VideoDPO
|
10 |
+
- CodeGoat24/Text-2-Video-Human-Preferences
|
11 |
+
- CodeGoat24/OpenAI-4o_t2i_human_preference
|
12 |
+
- CodeGoat24/ImageGen_Reward_Cold_Start
|
13 |
+
base_model:
|
14 |
+
- CodeGoat24/UnifiedReward-7b
|
15 |
+
---
|
16 |
+
|
17 |
+
## Model Summary
|
18 |
+
|
19 |
+
`Unified-Reward-Think-7b` is the first unified multimodal CoT reward model, capable of multi-dimensional, step-by-step long-chain reasoning for both visual understanding and generation reward tasks.
|
20 |
+
|
21 |
+
For further details, please refer to the following resources:
|
22 |
+
<!-- - 📰 Paper: https://arxiv.org/pdf/2503.05236 -->
|
23 |
+
- 🪐 Project Page: https://codegoat24.github.io/UnifiedReward/think
|
24 |
+
- 🤗 Model Collections: https://huggingface.co/collections/CodeGoat24/unifiedreward-models-67c3008148c3a380d15ac63a
|
25 |
+
- 🤗 Dataset Collections: https://huggingface.co/collections/CodeGoat24/unifiedreward-training-data-67c300d4fd5eff00fa7f1ede
|
26 |
+
- 👋 Point of Contact: [Yibin Wang](https://codegoat24.github.io)
|
27 |
+
|
28 |
+
### Quick Start
|
29 |
+
All inference codes are provided in our [github](https://github.com/CodeGoat24/UnifiedReward/tree/main/UnifiedReward-Think).
|
30 |
+
|
31 |
+
We take image understanding assessment as example here:
|
32 |
+
~~~python
|
33 |
+
# pip install git+https://github.com/LLaVA-VL/LLaVA-NeXT.git
|
34 |
+
from llava.model.builder import load_pretrained_model
|
35 |
+
from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
|
36 |
+
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
|
37 |
+
from llava.conversation import conv_templates, SeparatorStyle
|
38 |
+
|
39 |
+
from PIL import Image
|
40 |
+
import requests
|
41 |
+
import copy
|
42 |
+
import torch
|
43 |
+
|
44 |
+
import sys
|
45 |
+
import warnings
|
46 |
+
import os
|
47 |
+
|
48 |
+
|
49 |
+
warnings.filterwarnings("ignore")
|
50 |
+
pretrained = "CodeGoat24/UnifiedReward-Think-7b"
|
51 |
+
model_name = "llava_qwen"
|
52 |
+
device = "cuda"
|
53 |
+
device_map = "auto"
|
54 |
+
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map) # Add any other thing you want to pass in llava_model_args
|
55 |
+
|
56 |
+
model.eval()
|
57 |
+
|
58 |
+
url = "https://github.com/LLaVA-VL/blog/blob/main/2024-10-03-llava-critic/static/images/critic_img_seven.png?raw=True"
|
59 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
60 |
+
image_tensor = process_images([image], image_processor, model.config)
|
61 |
+
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
|
62 |
+
|
63 |
+
conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
|
64 |
+
Query = 'What does this image present?'
|
65 |
+
R1 = 'The image is a black and white sketch of a line that appears to be in the shape of a cross. The line is a simple and straightforward representation of the cross shape, with two straight lines intersecting at a point.'
|
66 |
+
R2 = 'This is a handwritten number seven.'
|
67 |
+
|
68 |
+
question = ("<image>\nGiven a question and a reference image, please analyze in detail the two provided answers (Answer 1 and Answer 2). " \
|
69 |
+
"Evaluate them based on the following three core dimensions:\n" \
|
70 |
+
"1. Semantic accuracy: How well the answer reflects the visual content of the image\n" \
|
71 |
+
"2. Correctness: Whether the answer is logically and factually correct\n" \
|
72 |
+
"3. Clarity: Whether the answer is clearly and fluently expressed\n" \
|
73 |
+
"You may also consider additional dimensions if you find them relevant (e.g., reasoning ability, attention to detail, multimodal grounding, etc.). " \
|
74 |
+
"For each dimension, provide a score from 1 to 10 for both answers, and briefly explain your reasoning. " \
|
75 |
+
"Then, compute the total score for each answer by explicitly adding the scores for all dimensions and showing the full calculation. " \
|
76 |
+
"Enclose your full reasoning within <think> and </think> tags. " \
|
77 |
+
"Then, in the <answer> tag, output exactly one of the following: 'Answer 1 is better' or 'Answer 2 is better'. No other text is allowed in the <answer> section.\n\n" \
|
78 |
+
"Example format:\n" \
|
79 |
+
"<think>\n" \
|
80 |
+
"1. Semantic accuracy: Answer 1 (9/10) - ...; Answer 2 (7/10) - ...\n" \
|
81 |
+
"2. Correctness: Answer 1 (8/10) - ...; Answer 2 (7/10) - ...\n" \
|
82 |
+
"3. Clarity: Answer 1 (9/10) - ...; Answer 2 (8/10) - ...\n" \
|
83 |
+
"[Additional dimensions if any]: Answer 1 (6/10) - ...; Answer 2 (7/10) - ...\n" \
|
84 |
+
"Total score:\nAnswer 1: 9+8+9+6=32\nAnswer 2: 7+7+8+7=29\n" \
|
85 |
+
"</think>\n" \
|
86 |
+
"<answer>Answer 1 is better</answer>\n\n" \
|
87 |
+
"**Note: In the example above, scores and the final answer are placeholders meant only to demonstrate the format. Your actual evaluation should be based on the quality of two given answers.**\n\n"
|
88 |
+
f"Your task is provided as follows:\nQuestion: [{Query}]\nAnswer 1: [{R1}]\nAnswer 2: [{R2}]")
|
89 |
+
|
90 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
91 |
+
conv.append_message(conv.roles[0], question)
|
92 |
+
conv.append_message(conv.roles[1], None)
|
93 |
+
prompt_question = conv.get_prompt()
|
94 |
+
|
95 |
+
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
|
96 |
+
image_sizes = [image.size]
|
97 |
+
|
98 |
+
|
99 |
+
cont = model.generate(
|
100 |
+
input_ids,
|
101 |
+
images=image_tensor,
|
102 |
+
image_sizes=image_sizes,
|
103 |
+
do_sample=False,
|
104 |
+
temperature=0,
|
105 |
+
max_new_tokens=4096,
|
106 |
+
)
|
107 |
+
text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
|
108 |
+
print(text_outputs[0])
|
109 |
+
~~~
|
110 |
+
|
111 |
+
|
112 |
+
## Citation
|
113 |
+
|
114 |
+
```
|
115 |
+
@article{UnifiedReward,
|
116 |
+
title={Unified Multimodal Chain-of-Thought Reward Model through Reinforcement Fine-Tuning.},
|
117 |
+
author={Wang, Yibin and Li, Zhimin and Zang, Yuhang and Wang, Chunyu and Lu, Qinglin and Jin, Cheng and Wang, Jiaqi},
|
118 |
+
journal={arXiv preprint arXiv:},
|
119 |
+
year={2025}
|
120 |
+
}
|
121 |
+
```
|