CodeGoat24 commited on
Commit
72774ca
·
verified ·
1 Parent(s): 2d3007d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +99 -3
README.md CHANGED
@@ -1,3 +1,99 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - CodeGoat24/HPD
5
+ - CodeGoat24/LiFT-HRA
6
+ - CodeGoat24/OIP
7
+ - CodeGoat24/EvalMuse
8
+ - CodeGoat24/ShareGPTVideo-DPO
9
+ - CodeGoat24/VideoFeedback
10
+ - CodeGoat24/LLaVA-Critic-113k
11
+ - CodeGoat24/VideoDPO
12
+ base_model:
13
+ - lmms-lab/llava-onevision-qwen2-7b-ov
14
+ ---
15
+
16
+
17
+ # Unified-Reward-7B
18
+
19
+ ## Model Summary
20
+
21
+ `Unified-Reward-7b` is the first unified reward model for multimodal understanding and generation assessment, enabling both pairwise ranking and pointwise scoring, which can be employed for vision model preference alignment.
22
+
23
+ For further details, please refer to the following resources:
24
+ - 📰 Paper:
25
+ - 🪐 Project Page: https://codegoat24.github.io/UnifiedReward/
26
+ - 🤗 Model Collections: https://huggingface.co/collections/CodeGoat24/unifiedreward-models-67c3008148c3a380d15ac63a
27
+ - 🤗 Dataset Collections: https://huggingface.co/collections/CodeGoat24/unifiedreward-training-data-67c300d4fd5eff00fa7f1ede
28
+ - 👋 Point of Contact: [Yibin Wang](https://codegoat24.github.io)
29
+
30
+
31
+ ### Quick Start
32
+
33
+ ~~~python
34
+ # pip install git+https://github.com/LLaVA-VL/LLaVA-NeXT.git
35
+ from llava.model.builder import load_pretrained_model
36
+ from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
37
+ from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
38
+ from llava.conversation import conv_templates, SeparatorStyle
39
+
40
+ from PIL import Image
41
+ import requests
42
+ import copy
43
+ import torch
44
+
45
+ import sys
46
+ import warnings
47
+ import os
48
+
49
+
50
+ warnings.filterwarnings("ignore")
51
+ pretrained = "CodeGoat24/UnifiedReward"
52
+ model_name = "llava_qwen"
53
+ device = "cuda"
54
+ device_map = "auto"
55
+ 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
56
+
57
+ model.eval()
58
+
59
+ url = "https://github.com/LLaVA-VL/blog/blob/main/2024-10-03-llava-critic/static/images/critic_img_seven.png?raw=True"
60
+ image = Image.open(requests.get(url, stream=True).raw)
61
+ image_tensor = process_images([image], image_processor, model.config)
62
+ image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
63
+
64
+ conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
65
+
66
+ # pairwise ranking
67
+ critic_prompt = "Given an image and a corresponding question, please serve as an unbiased and fair judge to evaluate the quality of the answers provided by a Large Multimodal Model (LMM). Determine which answer is better and explain your reasoning with specific details. Your task is provided as follows:\nQuestion: [What this image presents?]\nThe first response: [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.]\nThe second response: [This is a handwritten number seven.]\nASSISTANT:\n"
68
+
69
+ # pointwise scoring
70
+ # critic_prompt = "Given an image and a corresponding question, please serve as an unbiased and fair judge to evaluate the quality of answer answers provided by a Large Multimodal Model (LMM). Score the response out of 100 and explain your reasoning with specific details. Your task is provided as follows:\nQuestion: [What this image presents?]\nThe LMM response: [This is a handwritten number seven.]\nASSISTANT:\n "
71
+
72
+ question = DEFAULT_IMAGE_TOKEN + "\n" + critic_prompt
73
+ conv = copy.deepcopy(conv_templates[conv_template])
74
+ conv.append_message(conv.roles[0], question)
75
+ conv.append_message(conv.roles[1], None)
76
+ prompt_question = conv.get_prompt()
77
+
78
+ input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
79
+ image_sizes = [image.size]
80
+
81
+
82
+ cont = model.generate(
83
+ input_ids,
84
+ images=image_tensor,
85
+ image_sizes=image_sizes,
86
+ do_sample=False,
87
+ temperature=0,
88
+ max_new_tokens=4096,
89
+ )
90
+ text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
91
+ print(text_outputs[0])
92
+ ~~~
93
+
94
+
95
+ ## Citation
96
+
97
+ ```
98
+
99
+ ```