evalscope 0.12.0__py3-none-any.whl → 0.12.1__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/arguments.py +1 -1
- evalscope/benchmarks/aime/aime24_adapter.py +3 -3
- evalscope/benchmarks/aime/aime25_adapter.py +3 -3
- evalscope/benchmarks/arc/arc_adapter.py +14 -17
- evalscope/benchmarks/bbh/bbh_adapter.py +6 -6
- evalscope/benchmarks/benchmark.py +9 -9
- evalscope/benchmarks/ceval/ceval_adapter.py +10 -15
- evalscope/benchmarks/cmmlu/cmmlu_adapter.py +11 -16
- evalscope/benchmarks/competition_math/competition_math_adapter.py +3 -3
- evalscope/benchmarks/data_adapter.py +31 -21
- evalscope/benchmarks/data_collection/data_collection_adapter.py +0 -1
- evalscope/benchmarks/general_mcq/general_mcq_adapter.py +9 -12
- evalscope/benchmarks/general_qa/general_qa_adapter.py +25 -11
- evalscope/benchmarks/gpqa/gpqa_adapter.py +12 -7
- evalscope/benchmarks/gsm8k/gsm8k_adapter.py +2 -3
- evalscope/benchmarks/hellaswag/hellaswag_adapter.py +8 -12
- evalscope/benchmarks/humaneval/humaneval_adapter.py +2 -2
- evalscope/benchmarks/ifeval/ifeval_adapter.py +2 -3
- evalscope/benchmarks/iquiz/iquiz_adapter.py +9 -5
- evalscope/benchmarks/math_500/math_500_adapter.py +2 -6
- evalscope/benchmarks/mmlu/mmlu_adapter.py +11 -16
- evalscope/benchmarks/mmlu_pro/mmlu_pro_adapter.py +9 -5
- evalscope/benchmarks/musr/musr_adapter.py +8 -5
- evalscope/benchmarks/process_bench/process_bench_adapter.py +8 -5
- evalscope/benchmarks/race/race_adapter.py +12 -16
- evalscope/benchmarks/simple_qa/__init__.py +0 -0
- evalscope/benchmarks/simple_qa/simple_qa_adapter.py +20 -0
- evalscope/benchmarks/super_gpqa/__init__.py +0 -0
- evalscope/benchmarks/super_gpqa/five_shot_prompt.txt +89 -0
- evalscope/benchmarks/super_gpqa/super_gpqa_adapter.py +191 -0
- evalscope/benchmarks/super_gpqa/utils.py +90 -0
- evalscope/benchmarks/super_gpqa/zero_shot_prompt.txt +3 -0
- evalscope/benchmarks/trivia_qa/trivia_qa_adapter.py +3 -4
- evalscope/benchmarks/truthful_qa/truthful_qa_adapter.py +6 -13
- evalscope/benchmarks/utils.py +43 -0
- evalscope/collections/evaluator.py +11 -2
- evalscope/config.py +10 -2
- evalscope/constants.py +7 -0
- evalscope/metrics/named_metrics.py +1 -0
- evalscope/models/__init__.py +2 -1
- evalscope/models/base_adapter.py +25 -5
- evalscope/models/chat_adapter.py +3 -0
- evalscope/models/choice_adapter.py +4 -0
- evalscope/models/custom_adapter.py +2 -0
- evalscope/models/register.py +28 -0
- evalscope/models/server_adapter.py +35 -8
- evalscope/perf/arguments.py +13 -7
- evalscope/perf/http_client.py +6 -4
- evalscope/perf/utils/analysis_result.py +1 -1
- evalscope/report/app.py +3 -0
- evalscope/report/combinator.py +2 -2
- evalscope/run.py +5 -4
- evalscope/third_party/thinkbench/eval.py +220 -55
- evalscope/third_party/thinkbench/infer.py +37 -7
- evalscope/third_party/thinkbench/tools/llm.py +1 -0
- evalscope/third_party/toolbench_static/llm/swift_infer.py +50 -20
- evalscope/utils/chat_service.py +1 -0
- evalscope/utils/filters.py +59 -0
- evalscope/utils/logger.py +3 -3
- evalscope/version.py +2 -2
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/METADATA +7 -3
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/RECORD +68 -58
- tests/cli/test_collection.py +1 -1
- tests/cli/test_run.py +135 -28
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/LICENSE +0 -0
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/WHEEL +0 -0
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/entry_points.txt +0 -0
- {evalscope-0.12.0.dist-info → evalscope-0.12.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Answer the following multiple choice question. There is only one correct answer. The last line of your response should be in the format 'Answer: $LETTER' (without quotes), where LETTER is one of A, B, C, D, E, F, G, H, I, or J.
|
|
2
|
+
|
|
3
|
+
Question:
|
|
4
|
+
A refracting telescope consists of two converging lenses separated by 100 cm. The eye-piece lens has a focal length of 20 cm. The angular magnification of the telescope is
|
|
5
|
+
A) 10
|
|
6
|
+
B) 40
|
|
7
|
+
C) 6
|
|
8
|
+
D) 25
|
|
9
|
+
E) 15
|
|
10
|
+
F) 50
|
|
11
|
+
G) 30
|
|
12
|
+
H) 4
|
|
13
|
+
I) 5
|
|
14
|
+
J) 20
|
|
15
|
+
|
|
16
|
+
Answer: Let's think step by step. In a refracting telescope, if both lenses are converging, the focus of both lenses must be between the two lenses, and thus the focal lengths of the two lenses must add up to their separation. Since the focal length of one lens is 20 cm, the focal length of the other must be 80 cm. The magnification is the ratio of these two focal lengths, or 4.
|
|
17
|
+
Answer: H.
|
|
18
|
+
|
|
19
|
+
Question:
|
|
20
|
+
Say the pupil of your eye has a diameter of 5 mm and you have a telescope with an aperture of 50 cm. How much more light can the telescope gather than your eye?
|
|
21
|
+
A) 1000 times more
|
|
22
|
+
B) 50 times more
|
|
23
|
+
C) 5000 times more
|
|
24
|
+
D) 500 times more
|
|
25
|
+
E) 10000 times more
|
|
26
|
+
F) 20000 times more
|
|
27
|
+
G) 2000 times more
|
|
28
|
+
H) 100 times more
|
|
29
|
+
I) 10 times more
|
|
30
|
+
J) N/A
|
|
31
|
+
|
|
32
|
+
Answer: Let's think step by step. The amount of light a telescope can gather compared to the human eye is proportional to the area of its apertures. The area of a circle is given by the formula $A = \pi \left(\frac{{D}}{{2}}\right)^2$, where $D$ is the diameter. Therefore, the relative light-gathering power is calculated as:
|
|
33
|
+
\[
|
|
34
|
+
\frac{{\left(\frac{{50 \text{{ cm}}}}{{2}}\right)^2}}{{\left(\frac{{5 \text{{ mm}}}}{{2}}\right)^2}} = \frac{{\left(\frac{{50 \text{{ cm}}}}{{0.1 \text{{ cm}}}}\right)^2}}{{\left(\frac{{5 \text{{ mm}}}}{{0.1 \text{{ cm}}}}\right)^2}} = \frac{{500^2}}{{5^2}} = 10000.
|
|
35
|
+
\]
|
|
36
|
+
Answer: E.
|
|
37
|
+
|
|
38
|
+
Question:
|
|
39
|
+
Where do most short-period comets come from and how do we know?
|
|
40
|
+
A) The Kuiper belt; short period comets tend to be in the plane of the solar system like the Kuiper belt.
|
|
41
|
+
B) The asteroid belt; short period comets tend to come from random directions indicating a spherical distribution of comets called the asteroid belt.
|
|
42
|
+
C) The asteroid belt; short period comets tend to be in the plane of the solar system just like the asteroid belt.
|
|
43
|
+
D) The Oort cloud; short period comets have orbital periods similar to asteroids like Vesta and are found in the plane of the solar system just like the Oort cloud.
|
|
44
|
+
E) The Oort Cloud; short period comets tend to come from random directions indicating a spherical distribution of comets called the Oort Cloud.
|
|
45
|
+
F) The Oort cloud; short period comets tend to be in the plane of the solar system just like the Oort cloud.
|
|
46
|
+
G) The asteroid belt; short period comets have orbital periods similar to asteroids like Vesta and are found in the plane of the solar system just like the asteroid belt.
|
|
47
|
+
Answer: Let's think step by step. Most short-period comets originate from the Kuiper belt. This is deduced from the observation that these comets tend to follow orbits that lie in the plane of the solar system, similar to the distribution of objects in the Kuiper belt itself. Thus, the alignment of these cometary orbits with the ecliptic plane points to their Kuiper belt origin.
|
|
48
|
+
Answer: A.
|
|
49
|
+
|
|
50
|
+
Question:
|
|
51
|
+
Colors in a soap bubble result from light
|
|
52
|
+
A) dispersion
|
|
53
|
+
B) deflection
|
|
54
|
+
C) refraction
|
|
55
|
+
D) reflection
|
|
56
|
+
E) interference
|
|
57
|
+
F) converted to a different frequency
|
|
58
|
+
G) polarization
|
|
59
|
+
H) absorption
|
|
60
|
+
I) diffraction
|
|
61
|
+
J) transmission
|
|
62
|
+
|
|
63
|
+
Answer: Let's think step by step. The colorful patterns observed in a soap bubble are caused by the phenomenon of light interference. This occurs when light waves bounce between the two surfaces of the soap film, combining constructively or destructively based on their phase differences and the varying thickness of the film. These interactions result in vibrant color patterns due to variations in the intensity of different wavelengths of light.
|
|
64
|
+
Answer: E.
|
|
65
|
+
|
|
66
|
+
Question:
|
|
67
|
+
A microwave oven is connected to an outlet, 120 V, and draws a current of 2 amps. At what rate is energy being used by the microwave oven?
|
|
68
|
+
A) 240 W
|
|
69
|
+
B) 120 W
|
|
70
|
+
C) 10 W
|
|
71
|
+
D) 480 W
|
|
72
|
+
E) 360 W
|
|
73
|
+
F) 200 W
|
|
74
|
+
G) 30 W
|
|
75
|
+
H) 150 W
|
|
76
|
+
I) 60 W
|
|
77
|
+
J) 300 W
|
|
78
|
+
|
|
79
|
+
Answer: Let's think step by step. The rate of energy usage, known as power, in an electrical circuit is calculated by the product of voltage and current. For a microwave oven connected to a 120 V outlet and drawing a current of 2 amps, the power consumption can be calculated as follows:
|
|
80
|
+
\[
|
|
81
|
+
\text{{Power}} = \text{{Voltage}} \times \text{{Current}} = 120 \, \text{{V}} \times 2 \, \text{{A}} = 240 \, \text{{W}}.
|
|
82
|
+
\]
|
|
83
|
+
Therefore, the microwave oven uses energy at a rate of 240 watts.
|
|
84
|
+
Answer: A.
|
|
85
|
+
|
|
86
|
+
Question:
|
|
87
|
+
{query}
|
|
88
|
+
|
|
89
|
+
Answer: Let's think step by step.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import random
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from evalscope.benchmarks import Benchmark, DataAdapter
|
|
6
|
+
from evalscope.constants import EvalType, OutputType
|
|
7
|
+
from evalscope.metrics import exact_match
|
|
8
|
+
from evalscope.utils import logger
|
|
9
|
+
|
|
10
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
11
|
+
|
|
12
|
+
SUBSET_LIST = [
|
|
13
|
+
'Electronic Science and Technology', 'Philosophy', 'Traditional Chinese Medicine', 'Applied Economics',
|
|
14
|
+
'Mathematics', 'Physics', 'Clinical Medicine', 'Computer Science and Technology',
|
|
15
|
+
'Information and Communication Engineering', 'Control Science and Engineering', 'Theoretical Economics', 'Law',
|
|
16
|
+
'History', 'Basic Medicine', 'Education', 'Materials Science and Engineering', 'Electrical Engineering',
|
|
17
|
+
'Systems Science', 'Power Engineering and Engineering Thermophysics', 'Military Science', 'Biology',
|
|
18
|
+
'Business Administration', 'Language and Literature', 'Public Health and Preventive Medicine', 'Political Science',
|
|
19
|
+
'Chemistry', 'Hydraulic Engineering', 'Chemical Engineering and Technology', 'Pharmacy', 'Geography', 'Art Studies',
|
|
20
|
+
'Architecture', 'Forestry Engineering', 'Public Administration', 'Oceanography', 'Journalism and Communication',
|
|
21
|
+
'Nuclear Science and Technology', 'Weapon Science and Technology', 'Naval Architecture and Ocean Engineering',
|
|
22
|
+
'Environmental Science and Engineering', 'Transportation Engineering', 'Geology', 'Physical Oceanography',
|
|
23
|
+
'Musicology', 'Stomatology', 'Aquaculture', 'Mechanical Engineering',
|
|
24
|
+
'Aeronautical and Astronautical Science and Technology', 'Civil Engineering', 'Mechanics',
|
|
25
|
+
'Petroleum and Natural Gas Engineering', 'Sociology', 'Food Science and Engineering', 'Agricultural Engineering',
|
|
26
|
+
'Surveying and Mapping Science and Technology', 'Metallurgical Engineering',
|
|
27
|
+
'Library, Information and Archival Management', 'Mining Engineering', 'Astronomy',
|
|
28
|
+
'Geological Resources and Geological Engineering', 'Atmospheric Science', 'Optical Engineering', 'Animal Husbandry',
|
|
29
|
+
'Geophysics', 'Crop Science', 'Management Science and Engineering', 'Psychology', 'Forestry',
|
|
30
|
+
'Textile Science and Engineering', 'Veterinary Medicine', 'Instrument Science and Technology', 'Physical Education'
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
SUBSET_MAPPING = {
|
|
34
|
+
'Electronic Science and Technology': ['Engineering'],
|
|
35
|
+
'Philosophy': ['Philosophy'],
|
|
36
|
+
'Traditional Chinese Medicine': ['Medicine'],
|
|
37
|
+
'Applied Economics': ['Economics'],
|
|
38
|
+
'Mathematics': ['Science'],
|
|
39
|
+
'Physics': ['Science'],
|
|
40
|
+
'Clinical Medicine': ['Medicine'],
|
|
41
|
+
'Computer Science and Technology': ['Engineering'],
|
|
42
|
+
'Information and Communication Engineering': ['Engineering'],
|
|
43
|
+
'Control Science and Engineering': ['Engineering'],
|
|
44
|
+
'Theoretical Economics': ['Economics'],
|
|
45
|
+
'Law': ['Law'],
|
|
46
|
+
'History': ['History'],
|
|
47
|
+
'Basic Medicine': ['Medicine'],
|
|
48
|
+
'Education': ['Education'],
|
|
49
|
+
'Materials Science and Engineering': ['Engineering'],
|
|
50
|
+
'Electrical Engineering': ['Engineering'],
|
|
51
|
+
'Systems Science': ['Science'],
|
|
52
|
+
'Power Engineering and Engineering Thermophysics': ['Engineering'],
|
|
53
|
+
'Military Science': ['Military Science'],
|
|
54
|
+
'Biology': ['Science'],
|
|
55
|
+
'Business Administration': ['Management'],
|
|
56
|
+
'Language and Literature': ['Literature and Arts'],
|
|
57
|
+
'Public Health and Preventive Medicine': ['Medicine'],
|
|
58
|
+
'Political Science': ['Law'],
|
|
59
|
+
'Chemistry': ['Science'],
|
|
60
|
+
'Hydraulic Engineering': ['Engineering'],
|
|
61
|
+
'Chemical Engineering and Technology': ['Engineering'],
|
|
62
|
+
'Pharmacy': ['Medicine'],
|
|
63
|
+
'Geography': ['Science'],
|
|
64
|
+
'Art Studies': ['Literature and Arts'],
|
|
65
|
+
'Architecture': ['Engineering'],
|
|
66
|
+
'Forestry Engineering': ['Engineering'],
|
|
67
|
+
'Public Administration': ['Management'],
|
|
68
|
+
'Oceanography': ['Science'],
|
|
69
|
+
'Journalism and Communication': ['Literature and Arts'],
|
|
70
|
+
'Nuclear Science and Technology': ['Engineering'],
|
|
71
|
+
'Weapon Science and Technology': ['Engineering'],
|
|
72
|
+
'Naval Architecture and Ocean Engineering': ['Engineering'],
|
|
73
|
+
'Environmental Science and Engineering': ['Engineering'],
|
|
74
|
+
'Transportation Engineering': ['Engineering'],
|
|
75
|
+
'Geology': ['Science'],
|
|
76
|
+
'Physical Oceanography': ['Science'],
|
|
77
|
+
'Musicology': ['Literature and Arts'],
|
|
78
|
+
'Stomatology': ['Medicine'],
|
|
79
|
+
'Aquaculture': ['Agronomy'],
|
|
80
|
+
'Mechanical Engineering': ['Engineering'],
|
|
81
|
+
'Aeronautical and Astronautical Science and Technology': ['Engineering'],
|
|
82
|
+
'Civil Engineering': ['Engineering'],
|
|
83
|
+
'Mechanics': ['Engineering'],
|
|
84
|
+
'Petroleum and Natural Gas Engineering': ['Engineering'],
|
|
85
|
+
'Sociology': ['Sociology'],
|
|
86
|
+
'Food Science and Engineering': ['Engineering'],
|
|
87
|
+
'Agricultural Engineering': ['Engineering'],
|
|
88
|
+
'Surveying and Mapping Science and Technology': ['Engineering'],
|
|
89
|
+
'Metallurgical Engineering': ['Engineering'],
|
|
90
|
+
'Library, Information and Archival Management': ['Management'],
|
|
91
|
+
'Mining Engineering': ['Engineering'],
|
|
92
|
+
'Astronomy': ['Science'],
|
|
93
|
+
'Geological Resources and Geological Engineering': ['Engineering'],
|
|
94
|
+
'Atmospheric Science': ['Science'],
|
|
95
|
+
'Optical Engineering': ['Engineering'],
|
|
96
|
+
'Animal Husbandry': ['Agronomy'],
|
|
97
|
+
'Geophysics': ['Science'],
|
|
98
|
+
'Crop Science': ['Agronomy'],
|
|
99
|
+
'Management Science and Engineering': ['Management'],
|
|
100
|
+
'Psychology': ['Education'],
|
|
101
|
+
'Forestry': ['Agronomy'],
|
|
102
|
+
'Textile Science and Engineering': ['Engineering'],
|
|
103
|
+
'Veterinary Medicine': ['Agronomy'],
|
|
104
|
+
'Instrument Science and Technology': ['Engineering'],
|
|
105
|
+
'Physical Education': ['Education']
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@Benchmark.register(
|
|
110
|
+
name='super_gpqa',
|
|
111
|
+
pretty_name='SuperGPQA',
|
|
112
|
+
dataset_id='m-a-p/SuperGPQA',
|
|
113
|
+
model_adapter=OutputType.GENERATION,
|
|
114
|
+
output_types=[OutputType.MULTIPLE_CHOICE, OutputType.GENERATION],
|
|
115
|
+
subset_list=SUBSET_LIST,
|
|
116
|
+
metric_list=['AverageAccuracy'],
|
|
117
|
+
few_shot_num=0,
|
|
118
|
+
train_split=None,
|
|
119
|
+
eval_split='train', # only have train split
|
|
120
|
+
)
|
|
121
|
+
class SuperGPQAAdapter(DataAdapter):
|
|
122
|
+
|
|
123
|
+
def __init__(self, **kwargs):
|
|
124
|
+
few_shot_num = kwargs.get('few_shot_num', 0)
|
|
125
|
+
if few_shot_num > 0 and few_shot_num != 5:
|
|
126
|
+
logger.warning(
|
|
127
|
+
f'Only support few_shot_num 0 or 5 for SuperGPQA, but got {few_shot_num}. Use 5-shot by default.')
|
|
128
|
+
kwargs['few_shot_num'] = 5
|
|
129
|
+
super().__init__(**kwargs)
|
|
130
|
+
|
|
131
|
+
self.choices = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
|
|
132
|
+
self.category_map = SUBSET_MAPPING
|
|
133
|
+
self.few_shot_prompt = open(os.path.join(current_dir, 'five_shot_prompt.txt'), encoding='utf-8').read()
|
|
134
|
+
self.zero_shot_prompt = open(os.path.join(current_dir, 'zero_shot_prompt.txt'), encoding='utf-8').read()
|
|
135
|
+
|
|
136
|
+
def load(self, **kwargs):
|
|
137
|
+
kwargs['subset_list'] = ['default']
|
|
138
|
+
data_dict = super().load(**kwargs)
|
|
139
|
+
return self.reformat_subset(data_dict, subset_key='field', format='{}')
|
|
140
|
+
|
|
141
|
+
def gen_prompt(self, input_d: dict, subset_name: str, few_shot_list: list, **kwargs) -> dict:
|
|
142
|
+
if not self.prompt_template:
|
|
143
|
+
if few_shot_list:
|
|
144
|
+
prompt = self.few_shot_prompt.format(query=input_d['question'])
|
|
145
|
+
else:
|
|
146
|
+
prompt = self.zero_shot_prompt.format(query=input_d['question'])
|
|
147
|
+
else:
|
|
148
|
+
prompt = self.prompt_template.format(query=input_d['question'])
|
|
149
|
+
return self.gen_prompt_data(prompt)
|
|
150
|
+
|
|
151
|
+
def get_gold_answer(self, input_d: dict) -> str:
|
|
152
|
+
# Get the gold choice
|
|
153
|
+
return input_d.get('answer_letter')
|
|
154
|
+
|
|
155
|
+
def parse_pred_result(self, result: str, raw_input_d: dict = None, eval_type: str = EvalType.CHECKPOINT) -> str:
|
|
156
|
+
"""
|
|
157
|
+
Parse the model output to get the answer. Could be the best choice index.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
result: Predicted answer from the model. Usually a string for chat.
|
|
161
|
+
raw_input_d: The raw input. Depending on the dataset.
|
|
162
|
+
eval_type: 'checkpoint' or 'service' or 'custom'
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
The parsed answer. Depending on the dataset. Usually a string for chat.
|
|
166
|
+
"""
|
|
167
|
+
if self.model_adapter == OutputType.MULTIPLE_CHOICE:
|
|
168
|
+
return result
|
|
169
|
+
else:
|
|
170
|
+
from evalscope.benchmarks.super_gpqa.utils import extract_option_content, extract_option_labels
|
|
171
|
+
sample = raw_input_d
|
|
172
|
+
if self.few_shot_num == 0:
|
|
173
|
+
predict = extract_option_labels(result, 'ABCDEFGHIJ')
|
|
174
|
+
if predict is None:
|
|
175
|
+
predict = extract_option_content(result, sample['options'])
|
|
176
|
+
predict = chr(sample['options'].index(predict) + 65) if predict else None
|
|
177
|
+
else:
|
|
178
|
+
response = result.split('Question:')[0]
|
|
179
|
+
predict = extract_option_labels(response, 'ABCDEFGHIJ')
|
|
180
|
+
if predict is None:
|
|
181
|
+
predict = extract_option_content(response, sample['options'])
|
|
182
|
+
predict = chr(sample['options'].index(predict) + 65) if predict else None
|
|
183
|
+
if predict is None:
|
|
184
|
+
predict = extract_option_labels(result, 'ABCDEFGHIJ')
|
|
185
|
+
if predict is None:
|
|
186
|
+
predict = extract_option_content(result, sample['options'])
|
|
187
|
+
predict = chr(sample['options'].index(predict) + 65) if predict else None
|
|
188
|
+
return predict
|
|
189
|
+
|
|
190
|
+
def match(self, gold: str, pred: str) -> float:
|
|
191
|
+
return exact_match(gold=gold, pred=pred)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# flake8: noqa
|
|
2
|
+
import re
|
|
3
|
+
import timeout_decorator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@timeout_decorator.timeout(5) # 5 seconds timeout
|
|
7
|
+
def safe_regex_search(pattern, text, flags=0):
|
|
8
|
+
try:
|
|
9
|
+
return re.search(pattern, text, flags)
|
|
10
|
+
except timeout_decorator.TimeoutError:
|
|
11
|
+
print(f'Regex match timeout: pattern={pattern}, text={text[:100]}...')
|
|
12
|
+
return None
|
|
13
|
+
except Exception as e:
|
|
14
|
+
print(f'Regex match error: {str(e)}')
|
|
15
|
+
return None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def extract_option_labels(text, options='ABCDEFGHIJ'):
|
|
19
|
+
if not isinstance(text, str) or not isinstance(options, str):
|
|
20
|
+
return 'error'
|
|
21
|
+
|
|
22
|
+
text = text.rstrip()
|
|
23
|
+
last_line = text.split('\n')[-1]
|
|
24
|
+
|
|
25
|
+
option_str = ''.join([chr(65 + i) for i in range(len(options))]) if options else 'ABCDEFGHIJ'
|
|
26
|
+
|
|
27
|
+
patterns = [
|
|
28
|
+
# e.g. "The final answer to this question is: A."
|
|
29
|
+
# "The best option is $\boxed{B}:"
|
|
30
|
+
# "The correct answer is (C)."
|
|
31
|
+
f'[Tt]he\s+(?:\w+\s+)?(?:answer|option)(?:\w+\s+)?\s+is?:?\s*(?:[\*\$\\{{(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*([{option_str}])(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
32
|
+
|
|
33
|
+
# e.g. "ANSWER: A"
|
|
34
|
+
# "Answer: $\boxed{B}."
|
|
35
|
+
# "ANSWER: (C):"
|
|
36
|
+
f'(?i:Answer)[\*\s]*:\s*(?:[\*\$\\{{(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*([{option_str}])(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
37
|
+
|
|
38
|
+
# e.g. "A"
|
|
39
|
+
# "$\boxed{B}$"
|
|
40
|
+
# "(C)."
|
|
41
|
+
# "[D]:"
|
|
42
|
+
f'^[^\w\r\n]*(?:[\*\$\\{{(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*([{option_str}])(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
for pattern in patterns:
|
|
46
|
+
match = safe_regex_search(pattern, last_line, re.IGNORECASE)
|
|
47
|
+
if match:
|
|
48
|
+
return match.group(1)
|
|
49
|
+
|
|
50
|
+
for pattern in patterns:
|
|
51
|
+
match = safe_regex_search(pattern, text, re.IGNORECASE)
|
|
52
|
+
if match:
|
|
53
|
+
return match.group(1)
|
|
54
|
+
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def extract_option_content(text, options_content=None):
|
|
59
|
+
if not isinstance(text, str) or not isinstance(options_content, list):
|
|
60
|
+
return 'error'
|
|
61
|
+
|
|
62
|
+
escaped_options_content = [re.escape(option_content) for option_content in options_content]
|
|
63
|
+
escaped_options_content_str = '|'.join(escaped_options_content)
|
|
64
|
+
|
|
65
|
+
text = text.rstrip()
|
|
66
|
+
last_line = text.split('\n')[-1]
|
|
67
|
+
|
|
68
|
+
patterns = [
|
|
69
|
+
f'[Tt]he\s+(?:\w+\s+)?(?:answer|option)(?:\w+\s+)?\s+is:?\s*(?:[\*\$\\{{\(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*({escaped_options_content_str})(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
70
|
+
f'(?i:Answer)\s*(?:[\*\$\\{{\(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*({escaped_options_content_str})(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
71
|
+
f'^[^\w\r\n]*(?:[\*\$\\{{\(\[\\\\(]*?(?:(?:\\\\boxed|\\\\mathbf|\\\\mathrm|\\\\text){{)?)*\s*({escaped_options_content_str})(?:\\\\?\}}?\$?\)?\]?\}}?)*(?:[\s:\.\*)]|$)',
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
for pattern in patterns:
|
|
75
|
+
match = safe_regex_search(pattern, last_line)
|
|
76
|
+
if match:
|
|
77
|
+
if match.group(1) in escaped_options_content:
|
|
78
|
+
return options_content[escaped_options_content.index(match.group(1))]
|
|
79
|
+
else:
|
|
80
|
+
return match.group(1)
|
|
81
|
+
|
|
82
|
+
for pattern in patterns:
|
|
83
|
+
match = safe_regex_search(pattern, text)
|
|
84
|
+
if match:
|
|
85
|
+
if match.group(1) in escaped_options_content:
|
|
86
|
+
return options_content[escaped_options_content.index(match.group(1))]
|
|
87
|
+
else:
|
|
88
|
+
return match.group(1)
|
|
89
|
+
|
|
90
|
+
return None
|
|
@@ -5,8 +5,7 @@ import os
|
|
|
5
5
|
|
|
6
6
|
from evalscope.benchmarks import Benchmark
|
|
7
7
|
from evalscope.benchmarks.data_adapter import DataAdapter
|
|
8
|
-
from evalscope.constants import EvalType
|
|
9
|
-
from evalscope.models import ChatGenerationModelAdapter
|
|
8
|
+
from evalscope.constants import EvalType, OutputType
|
|
10
9
|
from evalscope.utils import get_logger
|
|
11
10
|
|
|
12
11
|
# flake8: noqa
|
|
@@ -16,8 +15,8 @@ logger = get_logger()
|
|
|
16
15
|
|
|
17
16
|
@Benchmark.register(
|
|
18
17
|
name='trivia_qa',
|
|
18
|
+
pretty_name='TriviaQA',
|
|
19
19
|
dataset_id='modelscope/trivia_qa',
|
|
20
|
-
model_adapter=ChatGenerationModelAdapter,
|
|
21
20
|
subset_list=['default'],
|
|
22
21
|
metric_list=['AverageAccuracy'],
|
|
23
22
|
few_shot_num=5,
|
|
@@ -100,7 +99,7 @@ class TriviaQaAdapter(DataAdapter):
|
|
|
100
99
|
context += self._generate_prompt(input_d=input_d, include_answer=False)
|
|
101
100
|
full_prompt = context
|
|
102
101
|
|
|
103
|
-
return
|
|
102
|
+
return self.gen_prompt_data(full_prompt)
|
|
104
103
|
|
|
105
104
|
def get_gold_answer(self, input_d: dict) -> list:
|
|
106
105
|
# Get the gold choice
|
|
@@ -8,8 +8,7 @@ from typing import List
|
|
|
8
8
|
|
|
9
9
|
from evalscope.benchmarks import Benchmark
|
|
10
10
|
from evalscope.benchmarks.data_adapter import DataAdapter
|
|
11
|
-
from evalscope.constants import EvalType
|
|
12
|
-
from evalscope.models import ContinuationLogitsModelAdapter
|
|
11
|
+
from evalscope.constants import EvalType, OutputType
|
|
13
12
|
from evalscope.utils import get_logger
|
|
14
13
|
|
|
15
14
|
# flake8: noqa
|
|
@@ -21,8 +20,10 @@ logger = get_logger()
|
|
|
21
20
|
|
|
22
21
|
@Benchmark.register(
|
|
23
22
|
name='truthful_qa',
|
|
23
|
+
pretty_name='TruthfulQA',
|
|
24
24
|
dataset_id='modelscope/truthful_qa',
|
|
25
|
-
model_adapter=
|
|
25
|
+
model_adapter=OutputType.CONTINUOUS,
|
|
26
|
+
output_types=[OutputType.CONTINUOUS, OutputType.GENERATION],
|
|
26
27
|
subset_list=['multiple_choice'],
|
|
27
28
|
metric_list=['AverageAccuracy'],
|
|
28
29
|
few_shot_num=0,
|
|
@@ -195,8 +196,7 @@ class TruthfulQaAdapter(DataAdapter):
|
|
|
195
196
|
else:
|
|
196
197
|
raise ValueError(f'** Unknown subset_name: {subset_name}')
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
return prompt_d
|
|
199
|
+
return self.gen_prompt_data(ctx_continuation_pair_list)
|
|
200
200
|
|
|
201
201
|
def get_gold_answer(self, input_d: dict) -> dict:
|
|
202
202
|
# Get the gold choice
|
|
@@ -215,14 +215,7 @@ class TruthfulQaAdapter(DataAdapter):
|
|
|
215
215
|
Returns:
|
|
216
216
|
The predicted answer.
|
|
217
217
|
"""
|
|
218
|
-
|
|
219
|
-
return result
|
|
220
|
-
elif eval_type == EvalType.SERVICE: # TODO: to be supported !
|
|
221
|
-
return result
|
|
222
|
-
elif eval_type == EvalType.CUSTOM: # TODO: to be supported !
|
|
223
|
-
return result
|
|
224
|
-
else:
|
|
225
|
-
raise ValueError(f'Invalid eval_type: {eval_type}')
|
|
218
|
+
return result
|
|
226
219
|
|
|
227
220
|
def match(self, gold: dict, pred: list) -> dict:
|
|
228
221
|
"""
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from typing import Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from evalscope.constants import EvalType
|
|
6
|
+
from evalscope.utils.filters import Filter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class PromptData:
|
|
11
|
+
data: List[str]
|
|
12
|
+
index: Optional[int] = 0
|
|
13
|
+
system_prompt: Optional[str] = None
|
|
14
|
+
multi_choices: Optional[List[str]] = None
|
|
15
|
+
|
|
16
|
+
def to_dict(self) -> Dict:
|
|
17
|
+
if self.multi_choices is None:
|
|
18
|
+
return {
|
|
19
|
+
'data': self.data,
|
|
20
|
+
'index': self.index,
|
|
21
|
+
'system_prompt': self.system_prompt,
|
|
22
|
+
}
|
|
23
|
+
else:
|
|
24
|
+
return {
|
|
25
|
+
'data': self.data,
|
|
26
|
+
'index': self.index,
|
|
27
|
+
'system_prompt': self.system_prompt,
|
|
28
|
+
'multi_choices': self.multi_choices,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def preprocess_decorator(func):
|
|
33
|
+
|
|
34
|
+
@wraps(func)
|
|
35
|
+
def wrapper(self, result: str, raw_input_d: dict = None, eval_type: str = EvalType.CHECKPOINT):
|
|
36
|
+
filters = self.config_kwargs.get('filters', None)
|
|
37
|
+
if filters:
|
|
38
|
+
# Apply filters to the resultply filters to the result
|
|
39
|
+
for filter_name, filter_value in filters.items():
|
|
40
|
+
result = Filter.apply(filter_name, result, filter_value)
|
|
41
|
+
return func(self, result, raw_input_d, eval_type)
|
|
42
|
+
|
|
43
|
+
return wrapper
|
|
@@ -97,8 +97,8 @@ class EvaluatorCollection:
|
|
|
97
97
|
evaluators = {}
|
|
98
98
|
for dataset_name in self.dataset_name_map.keys():
|
|
99
99
|
benchmark = Benchmark.get(dataset_name)
|
|
100
|
+
model_adapter = initialize_model_adapter(self.task_cfg, benchmark, self.model)
|
|
100
101
|
data_adapter = benchmark.get_data_adapter()
|
|
101
|
-
model_adapter = initialize_model_adapter(self.task_cfg, benchmark.model_adapter, self.model)
|
|
102
102
|
evaluators[dataset_name] = SimpleEvaluator(dataset_name, data_adapter, model_adapter, self.task_cfg,
|
|
103
103
|
self.outputs)
|
|
104
104
|
return evaluators
|
|
@@ -238,7 +238,16 @@ class EvaluatorCollection:
|
|
|
238
238
|
if self.task_cfg.use_cache and os.path.exists(review_file_path):
|
|
239
239
|
logger.warning(
|
|
240
240
|
f'Ignore use_cache={self.task_cfg.use_cache}, updating the review file: {review_file_path} ...')
|
|
241
|
-
os.
|
|
241
|
+
if os.path.isdir(review_file_path):
|
|
242
|
+
for filename in os.listdir(review_file_path):
|
|
243
|
+
file_path = os.path.join(review_file_path, filename)
|
|
244
|
+
try:
|
|
245
|
+
if os.path.isfile(file_path):
|
|
246
|
+
os.remove(file_path)
|
|
247
|
+
except Exception as e:
|
|
248
|
+
logger.error(f'Error deleting file {file_path}: {e}')
|
|
249
|
+
else:
|
|
250
|
+
os.remove(review_file_path)
|
|
242
251
|
|
|
243
252
|
reviews = defaultdict(dict)
|
|
244
253
|
for sample in tqdm(self.dataset, desc='Getting reviews'):
|
evalscope/config.py
CHANGED
|
@@ -4,10 +4,12 @@ import copy
|
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
6
|
from argparse import Namespace
|
|
7
|
+
from collections import OrderedDict
|
|
7
8
|
from dataclasses import dataclass, field
|
|
8
9
|
from typing import Dict, List, Optional, Union
|
|
9
10
|
|
|
10
|
-
from evalscope.constants import DEFAULT_DATASET_CACHE_DIR, DEFAULT_WORK_DIR, EvalBackend, EvalStage, EvalType, HubType
|
|
11
|
+
from evalscope.constants import (DEFAULT_DATASET_CACHE_DIR, DEFAULT_WORK_DIR, EvalBackend, EvalStage, EvalType, HubType,
|
|
12
|
+
OutputType)
|
|
11
13
|
from evalscope.models.custom import CustomModel
|
|
12
14
|
from evalscope.utils import gen_hash
|
|
13
15
|
from evalscope.utils.io_utils import dict_to_yaml, json_to_dict, yaml_to_dict
|
|
@@ -54,7 +56,7 @@ class TaskConfig:
|
|
|
54
56
|
eval_config: Union[str, Dict, None] = None
|
|
55
57
|
stage: str = EvalStage.ALL
|
|
56
58
|
limit: Optional[int] = None
|
|
57
|
-
eval_batch_size: int =
|
|
59
|
+
eval_batch_size: Optional[int] = None
|
|
58
60
|
|
|
59
61
|
# Cache and working directory arguments
|
|
60
62
|
mem_cache: bool = False # Deprecated, will be removed in v1.0.0.
|
|
@@ -77,6 +79,12 @@ class TaskConfig:
|
|
|
77
79
|
self.model_id = type(self.model).__name__
|
|
78
80
|
else:
|
|
79
81
|
self.model_id = os.path.basename(self.model).rstrip(os.sep)
|
|
82
|
+
# fix path error, see http://github.com/modelscope/evalscope/issues/377
|
|
83
|
+
self.model_id = self.model_id.replace(':', '-')
|
|
84
|
+
|
|
85
|
+
# Set default eval_batch_size based on eval_type
|
|
86
|
+
if self.eval_batch_size is None:
|
|
87
|
+
self.eval_batch_size = 8 if self.eval_type == EvalType.SERVICE else 1
|
|
80
88
|
|
|
81
89
|
def to_dict(self):
|
|
82
90
|
return self.__dict__
|
evalscope/constants.py
CHANGED
|
@@ -139,6 +139,13 @@ class EvalType:
|
|
|
139
139
|
SERVICE = 'service' # model service
|
|
140
140
|
|
|
141
141
|
|
|
142
|
+
class OutputType:
|
|
143
|
+
LOGITS = 'logits' # for multiple choice tasks
|
|
144
|
+
GENERATION = 'generation' # for text generation tasks and general tasks
|
|
145
|
+
MULTIPLE_CHOICE = 'multiple_choice_logits' # for multiple choice tasks
|
|
146
|
+
CONTINUOUS = 'continuous_logits' # for continuous tasks
|
|
147
|
+
|
|
148
|
+
|
|
142
149
|
class EvalBackend:
|
|
143
150
|
NATIVE = 'Native'
|
|
144
151
|
OPEN_COMPASS = 'OpenCompass'
|
|
@@ -35,6 +35,7 @@ metric_registry = MetricRegistry()
|
|
|
35
35
|
metric_registry.register(Metric(name='AverageAccuracy', object=mean))
|
|
36
36
|
metric_registry.register(Metric(name='WeightedAverageAccuracy', object=weighted_mean))
|
|
37
37
|
metric_registry.register(Metric(name='AverageBLEU', object=mean))
|
|
38
|
+
metric_registry.register(Metric(name='AverageRouge', object=mean))
|
|
38
39
|
metric_registry.register(Metric(name='WeightedAverageBLEU', object=weighted_mean))
|
|
39
40
|
metric_registry.register(Metric(name='AveragePass@1', object=mean))
|
|
40
41
|
for k in range(1, 17):
|
evalscope/models/__init__.py
CHANGED
|
@@ -7,10 +7,11 @@ from evalscope.models.custom import CustomModel
|
|
|
7
7
|
from evalscope.models.custom_adapter import CustomModelAdapter
|
|
8
8
|
from evalscope.models.local_model import LocalModel, get_local_model
|
|
9
9
|
from evalscope.models.model import BaseModel, ChatBaseModel, OpenAIModel
|
|
10
|
+
from evalscope.models.register import get_model_adapter
|
|
10
11
|
from evalscope.models.server_adapter import ServerModelAdapter
|
|
11
12
|
|
|
12
13
|
__all__ = [
|
|
13
14
|
'CustomModel', 'BaseModel', 'ChatBaseModel', 'OpenAIModel', 'BaseModelAdapter', 'ChatGenerationModelAdapter',
|
|
14
15
|
'MultiChoiceModelAdapter', 'ContinuationLogitsModelAdapter', 'CustomModelAdapter', 'ServerModelAdapter',
|
|
15
|
-
'LocalModel', 'get_local_model', 'initialize_model_adapter'
|
|
16
|
+
'LocalModel', 'get_local_model', 'initialize_model_adapter', 'get_model_adapter'
|
|
16
17
|
]
|
evalscope/models/base_adapter.py
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import torch
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
|
-
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
3
|
+
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
|
4
4
|
|
|
5
|
-
from evalscope.constants import EvalType
|
|
5
|
+
from evalscope.constants import EvalType, OutputType
|
|
6
6
|
from evalscope.models.custom import CustomModel
|
|
7
7
|
from evalscope.models.local_model import LocalModel
|
|
8
|
+
from evalscope.models.register import get_model_adapter, register_model_adapter
|
|
9
|
+
from evalscope.utils.logger import get_logger
|
|
10
|
+
|
|
11
|
+
logger = get_logger()
|
|
8
12
|
|
|
9
13
|
if TYPE_CHECKING:
|
|
14
|
+
from evalscope.benchmarks import BenchmarkMeta
|
|
10
15
|
from evalscope.config import TaskConfig
|
|
11
16
|
|
|
12
17
|
|
|
18
|
+
@register_model_adapter('base')
|
|
13
19
|
class BaseModelAdapter(ABC):
|
|
14
20
|
|
|
15
21
|
def __init__(self, model: Optional[Union[LocalModel, CustomModel]], **kwargs):
|
|
@@ -33,7 +39,7 @@ class BaseModelAdapter(ABC):
|
|
|
33
39
|
raise NotImplementedError
|
|
34
40
|
|
|
35
41
|
|
|
36
|
-
def initialize_model_adapter(task_cfg: 'TaskConfig',
|
|
42
|
+
def initialize_model_adapter(task_cfg: 'TaskConfig', benchmark: 'BenchmarkMeta', base_model: 'LocalModel'):
|
|
37
43
|
"""Initialize the model adapter based on the task configuration."""
|
|
38
44
|
if task_cfg.dry_run:
|
|
39
45
|
from evalscope.models.model import DummyChatModel
|
|
@@ -43,8 +49,14 @@ def initialize_model_adapter(task_cfg: 'TaskConfig', model_adapter_cls: 'BaseMod
|
|
|
43
49
|
raise ValueError(f'Expected evalscope.models.custom.CustomModel, but got {type(task_cfg.model)}.')
|
|
44
50
|
from evalscope.models import CustomModelAdapter
|
|
45
51
|
return CustomModelAdapter(custom_model=task_cfg.model)
|
|
46
|
-
elif task_cfg.eval_type == EvalType.SERVICE:
|
|
52
|
+
elif task_cfg.eval_type == EvalType.SERVICE or task_cfg.api_url is not None:
|
|
47
53
|
from evalscope.models import ServerModelAdapter
|
|
54
|
+
|
|
55
|
+
if benchmark.model_adapter in [OutputType.CONTINUOUS, OutputType.MULTIPLE_CHOICE]:
|
|
56
|
+
logger.warning('Output type is set to logits. This is not supported for service evaluation. '
|
|
57
|
+
'Setting output type to generation by default.')
|
|
58
|
+
benchmark.model_adapter = OutputType.GENERATION
|
|
59
|
+
|
|
48
60
|
return ServerModelAdapter(
|
|
49
61
|
api_url=task_cfg.api_url,
|
|
50
62
|
model_id=task_cfg.model,
|
|
@@ -54,5 +66,13 @@ def initialize_model_adapter(task_cfg: 'TaskConfig', model_adapter_cls: 'BaseMod
|
|
|
54
66
|
stream=task_cfg.stream,
|
|
55
67
|
)
|
|
56
68
|
else:
|
|
57
|
-
|
|
69
|
+
# for local model, we need to determine the model adapter class based on the output type
|
|
70
|
+
model_adapter_cls = benchmark.model_adapter
|
|
71
|
+
if model_adapter_cls not in benchmark.output_types:
|
|
72
|
+
logger.warning(f'Output type {model_adapter_cls} is not supported for benchmark {benchmark.name}. '
|
|
73
|
+
f'Using {benchmark.output_types[0]} instead.')
|
|
74
|
+
model_adapter_cls = benchmark.output_types[0]
|
|
75
|
+
|
|
76
|
+
model_adapter = get_model_adapter(model_adapter_cls)
|
|
77
|
+
return model_adapter(
|
|
58
78
|
model=base_model, generation_config=task_cfg.generation_config, chat_template=task_cfg.chat_template)
|