evalscope 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of evalscope might be problematic. Click here for more details.
- evalscope/api/benchmark/__init__.py +1 -1
- evalscope/api/benchmark/adapters/__init__.py +2 -0
- evalscope/api/benchmark/adapters/default_data_adapter.py +7 -4
- evalscope/api/benchmark/adapters/image_edit_adapter.py +82 -0
- evalscope/api/benchmark/adapters/multi_choice_adapter.py +5 -2
- evalscope/api/benchmark/adapters/text2image_adapter.py +12 -10
- evalscope/api/benchmark/adapters/vision_language_adapter.py +8 -0
- evalscope/api/benchmark/benchmark.py +62 -2
- evalscope/api/benchmark/meta.py +9 -0
- evalscope/api/dataset/dataset.py +6 -6
- evalscope/api/dataset/loader.py +2 -1
- evalscope/api/evaluator/cache.py +24 -1
- evalscope/api/evaluator/evaluator.py +5 -0
- evalscope/api/evaluator/state.py +17 -1
- evalscope/api/messages/__init__.py +1 -0
- evalscope/api/messages/chat_message.py +52 -2
- evalscope/api/metric/scorer.py +15 -7
- evalscope/api/mixin/__init__.py +1 -1
- evalscope/api/mixin/llm_judge_mixin.py +2 -0
- evalscope/api/mixin/sandbox_mixin.py +204 -0
- evalscope/api/model/generate_config.py +1 -6
- evalscope/api/model/model.py +5 -2
- evalscope/api/tool/tool_info.py +1 -1
- evalscope/app/app.py +3 -0
- evalscope/app/ui/single_model.py +3 -3
- evalscope/app/utils/data_utils.py +7 -7
- evalscope/app/utils/env_utils.py +12 -0
- evalscope/app/utils/text_utils.py +14 -12
- evalscope/arguments.py +8 -4
- evalscope/backend/opencompass/backend_manager.py +0 -2
- evalscope/backend/rag_eval/utils/embedding.py +9 -1
- evalscope/benchmarks/ai2d/ai2d_adapter.py +53 -0
- evalscope/benchmarks/amc/amc_adapter.py +46 -0
- evalscope/benchmarks/bbh/bbh_adapter.py +43 -17
- evalscope/benchmarks/bfcl/bfcl_adapter.py +142 -7
- evalscope/benchmarks/bfcl/generation.py +9 -9
- evalscope/benchmarks/ceval/ceval_adapter.py +1 -2
- evalscope/benchmarks/data_collection/data_collection_adapter.py +23 -19
- evalscope/benchmarks/drop/drop_adapter.py +1 -1
- evalscope/benchmarks/frames/frames_adapter.py +2 -1
- evalscope/benchmarks/general_arena/general_arena_adapter.py +5 -1
- evalscope/benchmarks/healthbench/healthbench_adapter.py +282 -0
- evalscope/benchmarks/healthbench/utils.py +102 -0
- evalscope/benchmarks/humaneval/humaneval_adapter.py +19 -35
- evalscope/benchmarks/humaneval/utils.py +235 -0
- evalscope/benchmarks/ifeval/instructions_util.py +2 -3
- evalscope/benchmarks/image_edit/__init__.py +0 -0
- evalscope/benchmarks/image_edit/gedit/__init__.py +0 -0
- evalscope/benchmarks/image_edit/gedit/gedit_adapter.py +138 -0
- evalscope/benchmarks/image_edit/gedit/utils.py +372 -0
- evalscope/benchmarks/image_edit/gedit/vie_prompts.py +406 -0
- evalscope/benchmarks/live_code_bench/evaluate_utils.py +13 -6
- evalscope/benchmarks/live_code_bench/live_code_bench_adapter.py +60 -37
- evalscope/benchmarks/live_code_bench/sandbox_evaluate_utils.py +220 -0
- evalscope/benchmarks/math_500/math_500_adapter.py +0 -1
- evalscope/benchmarks/math_vista/__init__.py +0 -0
- evalscope/benchmarks/math_vista/math_vista_adapter.py +129 -0
- evalscope/benchmarks/minerva_math/__init__.py +0 -0
- evalscope/benchmarks/minerva_math/minerva_math_adapter.py +48 -0
- evalscope/benchmarks/mm_bench/__init__.py +0 -0
- evalscope/benchmarks/mm_bench/mm_bench_adapter.py +99 -0
- evalscope/benchmarks/mm_star/__init__.py +0 -0
- evalscope/benchmarks/mm_star/mm_star_adapter.py +73 -0
- evalscope/benchmarks/mmmu/__init__.py +0 -0
- evalscope/benchmarks/mmmu/mmmu_adapter.py +159 -0
- evalscope/benchmarks/mmmu_pro/__init__.py +0 -0
- evalscope/benchmarks/mmmu_pro/mmmu_pro_adapter.py +124 -0
- evalscope/benchmarks/multi_if/__init__.py +0 -0
- evalscope/benchmarks/multi_if/ifeval.py +3354 -0
- evalscope/benchmarks/multi_if/metrics.py +120 -0
- evalscope/benchmarks/multi_if/multi_if_adapter.py +161 -0
- evalscope/benchmarks/needle_haystack/needle_haystack_adapter.py +6 -5
- evalscope/benchmarks/olympiad_bench/__init__.py +0 -0
- evalscope/benchmarks/olympiad_bench/olympiad_bench_adapter.py +163 -0
- evalscope/benchmarks/olympiad_bench/utils.py +565 -0
- evalscope/benchmarks/omni_bench/__init__.py +0 -0
- evalscope/benchmarks/omni_bench/omni_bench_adapter.py +86 -0
- evalscope/benchmarks/real_world_qa/__init__.py +0 -0
- evalscope/benchmarks/real_world_qa/real_world_qa_adapter.py +64 -0
- evalscope/benchmarks/tau_bench/generation.py +1 -1
- evalscope/benchmarks/tau_bench/tau_bench_adapter.py +20 -19
- evalscope/benchmarks/text2image/__init__.py +0 -0
- evalscope/benchmarks/{aigc/t2i → text2image}/evalmuse_adapter.py +3 -1
- evalscope/benchmarks/{aigc/t2i → text2image}/genai_bench_adapter.py +2 -2
- evalscope/benchmarks/{aigc/t2i → text2image}/general_t2i_adapter.py +1 -1
- evalscope/benchmarks/{aigc/t2i → text2image}/hpdv2_adapter.py +7 -2
- evalscope/benchmarks/{aigc/t2i → text2image}/tifa_adapter.py +1 -0
- evalscope/benchmarks/truthful_qa/truthful_qa_adapter.py +1 -2
- evalscope/cli/start_app.py +7 -1
- evalscope/cli/start_perf.py +7 -1
- evalscope/config.py +96 -14
- evalscope/constants.py +11 -0
- evalscope/evaluator/evaluator.py +30 -10
- evalscope/metrics/llm_judge.py +19 -7
- evalscope/metrics/metric.py +27 -2
- evalscope/models/image_edit_model.py +125 -0
- evalscope/models/model_apis.py +22 -0
- evalscope/models/openai_compatible.py +3 -0
- evalscope/models/text2image_model.py +2 -2
- evalscope/models/utils/openai.py +8 -6
- evalscope/perf/arguments.py +2 -0
- evalscope/perf/benchmark.py +2 -0
- evalscope/perf/plugin/api/base.py +2 -2
- evalscope/perf/plugin/api/default_api.py +7 -7
- evalscope/perf/plugin/api/openai_api.py +83 -19
- evalscope/perf/plugin/datasets/flickr8k.py +2 -2
- evalscope/perf/plugin/datasets/kontext_bench.py +2 -2
- evalscope/perf/plugin/datasets/random_vl_dataset.py +2 -2
- evalscope/perf/utils/benchmark_util.py +7 -5
- evalscope/perf/utils/local_server.py +3 -0
- evalscope/report/__init__.py +0 -1
- evalscope/report/combinator.py +0 -25
- evalscope/report/generator.py +8 -87
- evalscope/report/report.py +8 -4
- evalscope/run.py +9 -5
- evalscope/third_party/toolbench_static/llm/swift_infer.py +0 -4
- evalscope/utils/chat_service.py +1 -1
- evalscope/utils/function_utils.py +41 -0
- evalscope/utils/import_utils.py +73 -1
- evalscope/utils/io_utils.py +56 -7
- evalscope/utils/json_schema.py +23 -2
- evalscope/utils/logger.py +19 -0
- evalscope/utils/model_utils.py +4 -3
- evalscope/utils/multi_choices.py +23 -6
- evalscope/version.py +2 -2
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/METADATA +17 -24
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/RECORD +145 -103
- tests/benchmark/test_eval.py +80 -37
- tests/benchmark/test_image_edit.py +65 -0
- tests/benchmark/test_sandbox.py +81 -0
- tests/benchmark/test_vlm.py +137 -0
- tests/cli/test_all.py +83 -43
- tests/cli/test_collection.py +8 -5
- tests/cli/test_reasoning.py +81 -0
- tests/common.py +73 -0
- tests/perf/test_perf.py +44 -14
- tests/rag/test_clip_benchmark.py +0 -3
- evalscope/api/mixin/dataset_mixin.py +0 -105
- evalscope/benchmarks/aigc/i2i/general_i2i_adapter.py +0 -44
- tests/aigc/__init__.py +0 -1
- /evalscope/benchmarks/{aigc → ai2d}/__init__.py +0 -0
- /evalscope/benchmarks/{aigc/i2i → amc}/__init__.py +0 -0
- /evalscope/benchmarks/{aigc/t2i → healthbench}/__init__.py +0 -0
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/LICENSE +0 -0
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/WHEEL +0 -0
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/entry_points.txt +0 -0
- {evalscope-1.0.0.dist-info → evalscope-1.0.2.dist-info}/top_level.txt +0 -0
- /tests/{aigc → benchmark}/test_t2i.py +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import re
|
|
3
|
+
from typing import Any, Dict, List
|
|
4
|
+
|
|
5
|
+
from evalscope.api.benchmark import BenchmarkMeta, VisionLanguageAdapter
|
|
6
|
+
from evalscope.api.dataset import Sample
|
|
7
|
+
from evalscope.api.evaluator import TaskState
|
|
8
|
+
from evalscope.api.messages import ChatMessageUser, Content, ContentImage, ContentText
|
|
9
|
+
from evalscope.api.registry import register_benchmark
|
|
10
|
+
from evalscope.constants import Tags
|
|
11
|
+
from evalscope.utils.io_utils import bytes_to_base64
|
|
12
|
+
from evalscope.utils.logger import get_logger
|
|
13
|
+
from evalscope.utils.multi_choices import MultipleChoiceTemplate, parse_answers, prompt
|
|
14
|
+
|
|
15
|
+
# flake8: noqa
|
|
16
|
+
|
|
17
|
+
logger = get_logger()
|
|
18
|
+
|
|
19
|
+
SUBSET_LIST = [
|
|
20
|
+
'Accounting',
|
|
21
|
+
'Agriculture',
|
|
22
|
+
'Architecture_and_Engineering',
|
|
23
|
+
'Art',
|
|
24
|
+
'Art_Theory',
|
|
25
|
+
'Basic_Medical_Science',
|
|
26
|
+
'Biology',
|
|
27
|
+
'Chemistry',
|
|
28
|
+
'Clinical_Medicine',
|
|
29
|
+
'Computer_Science',
|
|
30
|
+
'Design',
|
|
31
|
+
'Diagnostics_and_Laboratory_Medicine',
|
|
32
|
+
'Economics',
|
|
33
|
+
'Electronics',
|
|
34
|
+
'Energy_and_Power',
|
|
35
|
+
'Finance',
|
|
36
|
+
'Geography',
|
|
37
|
+
'History',
|
|
38
|
+
'Literature',
|
|
39
|
+
'Manage',
|
|
40
|
+
'Marketing',
|
|
41
|
+
'Materials',
|
|
42
|
+
'Math',
|
|
43
|
+
'Mechanical_Engineering',
|
|
44
|
+
'Music',
|
|
45
|
+
'Pharmacy',
|
|
46
|
+
'Physics',
|
|
47
|
+
'Psychology',
|
|
48
|
+
'Public_Health',
|
|
49
|
+
'Sociology',
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
MULT_CHOICE_PROMPT = MultipleChoiceTemplate.SINGLE_ANSWER_COT
|
|
53
|
+
|
|
54
|
+
OPEN_PROMPT = """
|
|
55
|
+
Solve the following problem step by step. The last line of your response should be of the form "ANSWER: $ANSWER" (without quotes) where $ANSWER is the answer to the problem.
|
|
56
|
+
|
|
57
|
+
{question}
|
|
58
|
+
|
|
59
|
+
Remember to put your answer on its own line at the end in the form "ANSWER: $ANSWER" (without quotes) where $ANSWER is the answer to the problem, and you do not need to use a \\boxed command.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
MULTI_CHOICE_TYPE = 'multiple-choice'
|
|
63
|
+
OPEN_TYPE = 'open'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@register_benchmark(
|
|
67
|
+
BenchmarkMeta(
|
|
68
|
+
name='mmmu',
|
|
69
|
+
pretty_name='MMMU',
|
|
70
|
+
tags=[Tags.MULTI_MODAL, Tags.KNOWLEDGE, Tags.QA],
|
|
71
|
+
description=
|
|
72
|
+
'MMMU (A Massive Multi-discipline Multimodal Understanding and Reasoning Benchmark for Expert AGI) benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning. MMMU includes 11.5K meticulously collected multimodal questions from college exams, quizzes, and textbooks, covering six core disciplines: Art & Design, Business, Science, Health & Medicine, Humanities & Social Science, and Tech & Engineering. These questions span 30 subjects and 183 subfields, comprising 30 highly heterogeneous image types, such as charts, diagrams, maps, tables, music sheets, and chemical structures.', # noqa: E501
|
|
73
|
+
dataset_id='AI-ModelScope/MMMU',
|
|
74
|
+
subset_list=SUBSET_LIST,
|
|
75
|
+
metric_list=['acc'],
|
|
76
|
+
eval_split='validation',
|
|
77
|
+
prompt_template=OPEN_PROMPT,
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
class MMMUAdapter(VisionLanguageAdapter):
|
|
81
|
+
MAX_IMAGES: int = 7
|
|
82
|
+
|
|
83
|
+
def __init__(self, *args, **kwargs):
|
|
84
|
+
super().__init__(*args, **kwargs)
|
|
85
|
+
|
|
86
|
+
def record_to_sample(self, record: Dict[str, Any]) -> Sample:
|
|
87
|
+
question_type = record['question_type']
|
|
88
|
+
content_list, answers_list = MMMUAdapter.create_content_and_answers_list(record)
|
|
89
|
+
|
|
90
|
+
metadata = {
|
|
91
|
+
'id': record['id'],
|
|
92
|
+
'question_type': record['question_type'],
|
|
93
|
+
'subfield': record['subfield'],
|
|
94
|
+
'explanation': record['explanation'],
|
|
95
|
+
'img_type': record['img_type'],
|
|
96
|
+
'topic_difficulty': record['topic_difficulty'],
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if question_type == MULTI_CHOICE_TYPE:
|
|
100
|
+
return Sample(
|
|
101
|
+
input=[ChatMessageUser(content=content_list)],
|
|
102
|
+
choices=answers_list,
|
|
103
|
+
target=record['answer'],
|
|
104
|
+
metadata=metadata,
|
|
105
|
+
)
|
|
106
|
+
elif question_type == OPEN_TYPE:
|
|
107
|
+
return Sample(
|
|
108
|
+
input=[ChatMessageUser(content=content_list)],
|
|
109
|
+
target=record['answer'],
|
|
110
|
+
metadata=metadata,
|
|
111
|
+
)
|
|
112
|
+
else:
|
|
113
|
+
raise ValueError(f'Unsupported question type: {question_type}')
|
|
114
|
+
|
|
115
|
+
def extract_answer(self, prediction: str, task_state: TaskState) -> str:
|
|
116
|
+
question_type = task_state.metadata['question_type']
|
|
117
|
+
if question_type == MULTI_CHOICE_TYPE:
|
|
118
|
+
answers = parse_answers(task_state)
|
|
119
|
+
return ''.join(sorted(list(answers)))
|
|
120
|
+
elif question_type == OPEN_TYPE:
|
|
121
|
+
pattern = r'ANSWER:\s*(.*)'
|
|
122
|
+
match = re.search(pattern, prediction)
|
|
123
|
+
if match:
|
|
124
|
+
return match.group(1).strip()
|
|
125
|
+
return ''
|
|
126
|
+
else:
|
|
127
|
+
raise ValueError(f'Unsupported question type: {question_type}')
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def create_content_and_answers_list(record: Dict[str, Any]) -> tuple[List[Content], List[str]]:
|
|
131
|
+
"""
|
|
132
|
+
Create a list of content elements and a list of answers from a record.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
record (dict): The record containing question, images, and options.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
tuple: A tuple containing:
|
|
140
|
+
- content_list (list): A list of content elements (text and images).
|
|
141
|
+
- answers_list (list): A list of possible answers (for multiple-choice questions).
|
|
142
|
+
"""
|
|
143
|
+
question_type = record['question_type']
|
|
144
|
+
|
|
145
|
+
if question_type == MULTI_CHOICE_TYPE:
|
|
146
|
+
answers_list: List[str] = ast.literal_eval(record['options'])
|
|
147
|
+
input_text = prompt(question=record['question'], choices=answers_list, template=MULT_CHOICE_PROMPT)
|
|
148
|
+
content_list: List[Content] = [ContentText(text=input_text)]
|
|
149
|
+
else:
|
|
150
|
+
answers_list: List[str] = []
|
|
151
|
+
content_list: List[Content] = [ContentText(text=OPEN_PROMPT.format(question=record['question']))]
|
|
152
|
+
|
|
153
|
+
for i in range(MMMUAdapter.MAX_IMAGES):
|
|
154
|
+
image = record[f'image_{i+1}']
|
|
155
|
+
if image:
|
|
156
|
+
image_base64 = bytes_to_base64(image['bytes'], format='png', add_header=True)
|
|
157
|
+
content_list.append(ContentImage(image=image_base64))
|
|
158
|
+
|
|
159
|
+
return content_list, answers_list
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
from typing import Any, Dict, List
|
|
3
|
+
|
|
4
|
+
from evalscope.api.benchmark import BenchmarkMeta, MultiChoiceAdapter, VisionLanguageAdapter
|
|
5
|
+
from evalscope.api.dataset import Sample
|
|
6
|
+
from evalscope.api.messages import ChatMessageUser, Content, ContentImage, ContentText
|
|
7
|
+
from evalscope.api.registry import register_benchmark
|
|
8
|
+
from evalscope.constants import Tags
|
|
9
|
+
from evalscope.utils.io_utils import bytes_to_base64
|
|
10
|
+
from evalscope.utils.logger import get_logger
|
|
11
|
+
from evalscope.utils.multi_choices import MultipleChoiceTemplate, answer_character, prompt
|
|
12
|
+
|
|
13
|
+
logger = get_logger()
|
|
14
|
+
|
|
15
|
+
SUBSET_LIST = [
|
|
16
|
+
'Accounting',
|
|
17
|
+
'Agriculture',
|
|
18
|
+
'Architecture_and_Engineering',
|
|
19
|
+
'Art',
|
|
20
|
+
'Art_Theory',
|
|
21
|
+
'Basic_Medical_Science',
|
|
22
|
+
'Biology',
|
|
23
|
+
'Chemistry',
|
|
24
|
+
'Clinical_Medicine',
|
|
25
|
+
'Computer_Science',
|
|
26
|
+
'Design',
|
|
27
|
+
'Diagnostics_and_Laboratory_Medicine',
|
|
28
|
+
'Economics',
|
|
29
|
+
'Electronics',
|
|
30
|
+
'Energy_and_Power',
|
|
31
|
+
'Finance',
|
|
32
|
+
'Geography',
|
|
33
|
+
'History',
|
|
34
|
+
'Literature',
|
|
35
|
+
'Manage',
|
|
36
|
+
'Marketing',
|
|
37
|
+
'Materials',
|
|
38
|
+
'Math',
|
|
39
|
+
'Mechanical_Engineering',
|
|
40
|
+
'Music',
|
|
41
|
+
'Pharmacy',
|
|
42
|
+
'Physics',
|
|
43
|
+
'Psychology',
|
|
44
|
+
'Public_Health',
|
|
45
|
+
'Sociology',
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
MULT_CHOICE_PROMPT = MultipleChoiceTemplate.SINGLE_ANSWER_COT
|
|
49
|
+
|
|
50
|
+
VISION_PROMPT = r"""
|
|
51
|
+
Answer the following multiple choice question in image. The last line of your response should be of the following format: 'ANSWER: $LETTER' (without quotes) where LETTER is one of {letters}. Think step by step before answering.
|
|
52
|
+
|
|
53
|
+
""".strip() # noqa: E501
|
|
54
|
+
|
|
55
|
+
DATASET_FORMATS = ['standard (4 options)', 'standard (10 options)', 'vision']
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@register_benchmark(
|
|
59
|
+
BenchmarkMeta(
|
|
60
|
+
name='mmmu_pro',
|
|
61
|
+
pretty_name='MMMU-PRO',
|
|
62
|
+
tags=[Tags.MULTI_MODAL, Tags.KNOWLEDGE, Tags.MULTIPLE_CHOICE],
|
|
63
|
+
description=
|
|
64
|
+
'MMMU-Pro is an enhanced multimodal benchmark designed to rigorously assess the true understanding capabilities of advanced AI models across multiple modalities. It builds upon the original MMMU benchmark by introducing several key improvements that make it more challenging and realistic, ensuring that models are evaluated on their genuine ability to integrate and comprehend both visual and textual information.', # noqa: E501
|
|
65
|
+
dataset_id='AI-ModelScope/MMMU_Pro',
|
|
66
|
+
subset_list=SUBSET_LIST,
|
|
67
|
+
metric_list=['acc'],
|
|
68
|
+
eval_split='test',
|
|
69
|
+
prompt_template=MULT_CHOICE_PROMPT,
|
|
70
|
+
extra_params={
|
|
71
|
+
'dataset_format': f"# choose from {DATASET_FORMATS}, default 'standard (4 options)'",
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
class MMMUPROAdapter(VisionLanguageAdapter, MultiChoiceAdapter):
|
|
76
|
+
MAX_IMAGES: int = 7
|
|
77
|
+
|
|
78
|
+
def __init__(self, *args, **kwargs):
|
|
79
|
+
super().__init__(*args, **kwargs)
|
|
80
|
+
|
|
81
|
+
self.reformat_subset = True
|
|
82
|
+
self.dataset_format = self.extra_params.get('dataset_format', 'standard (4 options)')
|
|
83
|
+
if self.dataset_format not in DATASET_FORMATS:
|
|
84
|
+
logger.warning(f"Invalid dataset_format '{self.dataset_format}', fallback to 'standard (4 options)'")
|
|
85
|
+
self.dataset_format = 'standard (4 options)'
|
|
86
|
+
self.default_subset = self.dataset_format
|
|
87
|
+
|
|
88
|
+
def record_to_sample(self, record: Dict[str, Any]) -> Sample:
|
|
89
|
+
|
|
90
|
+
metadata = {
|
|
91
|
+
'id': record['id'],
|
|
92
|
+
'explanation': record.get('explanation'),
|
|
93
|
+
'img_type': record.get('img_type'),
|
|
94
|
+
'topic_difficulty': record.get('topic_difficulty'),
|
|
95
|
+
'subject': record.get('subject')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
answers_list: List[str] = ast.literal_eval(record['options'])
|
|
99
|
+
|
|
100
|
+
if self.dataset_format == 'vision':
|
|
101
|
+
letters = ','.join(answer_character(i) for i in range(len(answers_list)))
|
|
102
|
+
input_text = VISION_PROMPT.format(letters=letters)
|
|
103
|
+
content_list: List[Content] = [ContentText(text=input_text)]
|
|
104
|
+
|
|
105
|
+
image = record.get('image')
|
|
106
|
+
if image:
|
|
107
|
+
content_list.append(ContentImage(image=bytes_to_base64(image['bytes'], format='png', add_header=True)))
|
|
108
|
+
else:
|
|
109
|
+
input_text = prompt(question=record['question'], choices=answers_list, template=MULT_CHOICE_PROMPT)
|
|
110
|
+
content_list: List[Content] = [ContentText(text=input_text)]
|
|
111
|
+
|
|
112
|
+
for i in range(MMMUPROAdapter.MAX_IMAGES):
|
|
113
|
+
image = record.get(f'image_{i+1}')
|
|
114
|
+
if image:
|
|
115
|
+
image_base64 = bytes_to_base64(image['bytes'], format='png', add_header=True)
|
|
116
|
+
content_list.append(ContentImage(image=image_base64))
|
|
117
|
+
|
|
118
|
+
return Sample(
|
|
119
|
+
input=[ChatMessageUser(content=content_list)],
|
|
120
|
+
choices=answers_list,
|
|
121
|
+
target=record['answer'],
|
|
122
|
+
subset_key=record['subject'],
|
|
123
|
+
metadata=metadata,
|
|
124
|
+
)
|
|
File without changes
|