Views
No views yet


###Task Description:
An instruction (might include an Input inside it), a response to evaluate, a reference answer that gets a score of 5, an image and a score rubric representing an evaluation criterion is given.
1. Write a detailed feedback that assess the quality of the response strictly based on the given score rubric, not evaluating in general.
2. After writing a feedback, write a score that is an integer between 1 and 5. You should refer to the score rubric.
3. The output format should look as follows: \"Feedback: (write a feedback for criteria) [RESULT] (an integer number between 1 and 5)\"
4. Please do not generate any other opening, closing, and explanations.
###The instruction to evaluate:
{instruction}
###Response to evaluate:
{response}
###Reference Answer (Score 5):
{reference_answer}
###Score Rubrics:
[{criteria_description}]
Score 1: {score1_description}
Score 2: {score2_description}
Score 3: {score3_description}
Score 4: {score4_description}
Score 5: {score5_description}
###Feedback: transformers:1import argparse
2import torch
3import os
4import json
5from tqdm import tqdm
6import shortuuid
7
8from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
9from llava.conversation import conv_templates, SeparatorStyle
10from llava.model.builder import load_pretrained_model
11from llava.utils import disable_torch_init
12from llava.mm_utils import tokenizer_image_token, get_model_name_from_path, KeywordsStoppingCriteria
13
14from PIL import Image
15import math
16
17
18def split_list(lst, n):
19 """Split a list into n (roughly) equal-sized chunks"""
20 chunk_size = math.ceil(len(lst) / n) # integer division
21 return [lst[i:i+chunk_size] for i in range(0, len(lst), chunk_size)]
22
23
24def get_chunk(lst, n, k):
25 chunks = split_list(lst, n)
26 return chunks[k]
27
28
29def eval_model(args):
30 # Model
31 disable_torch_init()
32 model_path = 'kaist-ai/prometheus-vision-13b-v1.0'
33 model_name = 'llava-v1.5'
34 tokenizer, model, image_processor, context_len = load_pretrained_model(model_path, args.model_base, model_name)
35
36 questions = [json.loads(q) for q in open(os.path.expanduser(args.question_file), "r")]
37 questions = get_chunk(questions, args.num_chunks, args.chunk_idx)
38 answers_file = os.path.expanduser(args.answers_file)
39 os.makedirs(os.path.dirname(answers_file), exist_ok=True)
40 ans_file = open(answers_file, "w")
41 for line in tqdm(questions):
42 idx = line["question_id"]
43 image_file = line["image"]
44 qs = line["text"]
45 cur_prompt = qs
46 if model.config.mm_use_im_start_end:
47 qs = DEFAULT_IM_START_TOKEN + DEFAULT_IMAGE_TOKEN + DEFAULT_IM_END_TOKEN + '\n' + qs
48 else:
49 qs = DEFAULT_IMAGE_TOKEN + '\n' + qs
50
51 conv = conv_templates[args.conv_mode].copy()
52 conv.append_message(conv.roles[0], qs)
53 conv.append_message(conv.roles[1], None)
54 prompt = conv.get_prompt()
55
56 input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).cuda()
57
58 image = Image.open(os.path.join(args.image_folder, image_file))
59 image_tensor = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0]
60
61 stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
62 keywords = [stop_str]
63 stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
64
65 with torch.inference_mode():
66 output_ids = model.generate(
67 input_ids,
68 images=image_tensor.unsqueeze(0).half().cuda(),
69 do_sample=True if args.temperature > 0 else False,
70 temperature=args.temperature,
71 top_p=args.top_p,
72 num_beams=args.num_beams,
73 # no_repeat_ngram_size=3,
74 max_new_tokens=1024,
75 use_cache=True)
76
77 input_token_len = input_ids.shape[1]
78 n_diff_input_output = (input_ids != output_ids[:, :input_token_len]).sum().item()
79 if n_diff_input_output > 0:
80 print(f'[Warning] {n_diff_input_output} output_ids are not the same as the input_ids')
81 outputs = tokenizer.batch_decode(output_ids[:, input_token_len:], skip_special_tokens=True)[0]
82 outputs = outputs.strip()
83 if outputs.endswith(stop_str):
84 outputs = outputs[:-len(stop_str)]
85 outputs = outputs.strip()
86
87 ans_id = shortuuid.uuid()
88 ans_file.write(json.dumps({"question_id": idx,
89 "prompt": cur_prompt,
90 "text": outputs,
91 "answer_id": ans_id,
92 "model_id": model_name,
93 "metadata": {}}) + "\n")
94 ans_file.flush()
95 ans_file.close()
96
97if __name__ == "__main__":
98 parser = argparse.ArgumentParser()
99 parser.add_argument("--model-path", type=str, default="facebook/opt-350m")
100 parser.add_argument("--model-base", type=str, default=None)
101 parser.add_argument("--image-folder", type=str, default="")
102 parser.add_argument("--question-file", type=str, default="tables/question.jsonl")
103 parser.add_argument("--answers-file", type=str, default="answer.jsonl")
104 parser.add_argument("--conv-mode", type=str, default="llava_v1")
105 parser.add_argument("--num-chunks", type=int, default=1)
106 parser.add_argument("--chunk-idx", type=int, default=0)
107 parser.add_argument("--temperature", type=float, default=0.2)
108 parser.add_argument("--top_p", type=float, default=None)
109 parser.add_argument("--num_beams", type=int, default=1)
110 args = parser.parse_args()
111
112 eval_model(args)
1131@misc{lee2024prometheusvision,
2 title={Prometheus-Vision: Vision-Language Model as a Judge for Fine-Grained Evaluation},
3 author={Seongyun Lee and Seungone Kim and Sue Hyun Park and Geewook Kim and Minjoon Seo},
4 year={2024},
5 eprint={2401.06591},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}