Update README.md
Browse files
README.md
CHANGED
@@ -4,4 +4,110 @@ datasets:
|
|
4 |
- lmms-lab/llava-critic-113k
|
5 |
base_model:
|
6 |
- lmms-lab/llava-onevision-qwen2-7b-ov
|
|
|
|
|
7 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- lmms-lab/llava-critic-113k
|
5 |
base_model:
|
6 |
- lmms-lab/llava-onevision-qwen2-7b-ov
|
7 |
+
tags:
|
8 |
+
- multimodal
|
9 |
---
|
10 |
+
|
11 |
+
# LLaVA-Critic-7B
|
12 |
+
|
13 |
+
## Model Summary
|
14 |
+
|
15 |
+
`llava-critic-7b` is the first open-source large multimodal model (LMM) designed as a generalist evaluator for assessing model performance across diverse multimodal scenarios. Built on the foundation of `llava-onevision-7b-ov`, it has been finetuned on [LLaVA-Critic-113k](https://huggingface.co/datasets/lmms-lab/llava-critic-113k) dataset to develop its "critic" capacities.
|
16 |
+
|
17 |
+
LLaVA-Critic excels in two primary scenarios:
|
18 |
+
- 1️⃣ LMM-as-a-Judge: It delivers judgement closely aligned with human, and provides concrete, image-grounded reasons. An open-source alternative to GPT for evaluations.
|
19 |
+
- 2️⃣ Preference Learning: Reliable reward signals power up visual chat, leading to LLaVA-OV-Chat [7B](https://huggingface.co/lmms-lab/llava-onevision-qwen2-7b-ov-chat)/[72B](https://huggingface.co/lmms-lab/llava-onevision-qwen2-72b-ov-chat).
|
20 |
+
|
21 |
+
For further details, please refer to the following resources:
|
22 |
+
- 📰 Paper: https://arxiv.org/abs/2410.02712
|
23 |
+
- 🪐 Project Page: https://llava-vl.github.io/blog/2024-10-03-llava-critic/
|
24 |
+
- 📦 Datasets: https://huggingface.co/datasets/lmms-lab/llava-critic-113k
|
25 |
+
- 🤗 Model Collections: https://huggingface.co/collections/lmms-lab/llava-critic-66fe3ef8c6e586d8435b4af8
|
26 |
+
- 👋 Point of Contact: [Tianyi Xiong](https://tyxiong23.github.io/)
|
27 |
+
|
28 |
+
|
29 |
+
## Use
|
30 |
+
|
31 |
+
### Intended Use
|
32 |
+
|
33 |
+
The model demonstrates general capacities in providing quantitative judgments and qualitative justifications for evaluating LMM-generated responses. It mainly focuses on two evaluation settings:
|
34 |
+
- *Pointwise scoring*, where it assigns a score to an individual candidate response.
|
35 |
+
- *Pairwise ranking*, where it compares two candidate responses to determine their relative quality.
|
36 |
+
|
37 |
+
### Quick Start
|
38 |
+
|
39 |
+
~~~python
|
40 |
+
# pip install git+https://github.com/LLaVA-VL/LLaVA-NeXT.git
|
41 |
+
from llava.model.builder import load_pretrained_model
|
42 |
+
from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
|
43 |
+
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
|
44 |
+
from llava.conversation import conv_templates, SeparatorStyle
|
45 |
+
|
46 |
+
from PIL import Image
|
47 |
+
import requests
|
48 |
+
import copy
|
49 |
+
import torch
|
50 |
+
|
51 |
+
import sys
|
52 |
+
import warnings
|
53 |
+
import os
|
54 |
+
|
55 |
+
|
56 |
+
warnings.filterwarnings("ignore")
|
57 |
+
pretrained = "lmms-lab/llava-critic-7b"
|
58 |
+
model_name = "llava_qwen"
|
59 |
+
device = "cuda"
|
60 |
+
device_map = "auto"
|
61 |
+
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
|
62 |
+
|
63 |
+
model.eval()
|
64 |
+
|
65 |
+
url = "https://github.com/LLaVA-VL/blog/blob/main/2024-10-03-llava-critic/static/images/critic_img_seven.png?raw=True"
|
66 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
67 |
+
image_tensor = process_images([image], image_processor, model.config)
|
68 |
+
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
|
69 |
+
|
70 |
+
conv_template = "qwen_1_5" # Make sure you use correct chat template for different models
|
71 |
+
|
72 |
+
# pairwise ranking
|
73 |
+
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"
|
74 |
+
|
75 |
+
# pointwise scoring
|
76 |
+
# 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 "
|
77 |
+
|
78 |
+
question = DEFAULT_IMAGE_TOKEN + "\n" + critic_prompt
|
79 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
80 |
+
conv.append_message(conv.roles[0], question)
|
81 |
+
conv.append_message(conv.roles[1], None)
|
82 |
+
prompt_question = conv.get_prompt()
|
83 |
+
|
84 |
+
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
|
85 |
+
image_sizes = [image.size]
|
86 |
+
|
87 |
+
|
88 |
+
cont = model.generate(
|
89 |
+
input_ids,
|
90 |
+
images=image_tensor,
|
91 |
+
image_sizes=image_sizes,
|
92 |
+
do_sample=False,
|
93 |
+
temperature=0,
|
94 |
+
max_new_tokens=4096,
|
95 |
+
)
|
96 |
+
text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
|
97 |
+
print(text_outputs[0])
|
98 |
+
~~~
|
99 |
+
|
100 |
+
|
101 |
+
## Citation
|
102 |
+
|
103 |
+
```
|
104 |
+
@article{xiong2024llavacritic,
|
105 |
+
title={LLaVA-Critic: Learning to Evaluate Multimodal Models},
|
106 |
+
author={Xiong, Tianyi and Wang, Xiyao and Guo, Dong and Ye, Qinghao and Fan, Haoqi and Gu, Quanquan and Huang, Heng and Li, Chunyuan},
|
107 |
+
year={2024},
|
108 |
+
eprint={2410.02712},
|
109 |
+
archivePrefix={arXiv},
|
110 |
+
primaryClass={cs.CV},
|
111 |
+
url={https://arxiv.org/abs/2410.02712},
|
112 |
+
}
|
113 |
+
```
|