|
| 1 | +from ais_bench.benchmark.datasets import HLEDataset, HLEJGDataset |
| 2 | +from ais_bench.benchmark.datasets.hle import HLEJudgeEvaluator |
| 3 | +from ais_bench.benchmark.models import VLLMCustomAPIChat |
| 4 | +from ais_bench.benchmark.openicl.icl_inferencer import GenInferencer |
| 5 | +from ais_bench.benchmark.openicl.icl_prompt_template import (MMPromptTemplate, |
| 6 | + PromptTemplate) |
| 7 | +from ais_bench.benchmark.openicl.icl_retriever import ZeroRetriever |
| 8 | +from ais_bench.benchmark.utils.postprocess.model_postprocessors import \ |
| 9 | + extract_non_reasoning_content |
| 10 | + |
| 11 | +# Model inference prompt template - aligned with official HLE format |
| 12 | +HLE_INFER_PROMPT = "Your response should be in the following format:\nExplanation: {your explanation for your answer choice}\nAnswer: {your chosen answer}\nConfidence: {your confidence score between 0% and 100% for your answer}" |
| 13 | + |
| 14 | + |
| 15 | +hle_reader_cfg = dict(input_columns=["question", "image"], output_column="answer") |
| 16 | + |
| 17 | + |
| 18 | +hle_infer_cfg = dict( |
| 19 | + prompt_template=dict( |
| 20 | + type=MMPromptTemplate, |
| 21 | + template=dict( |
| 22 | + begin=[ |
| 23 | + dict( |
| 24 | + role="SYSTEM", |
| 25 | + prompt=HLE_INFER_PROMPT, |
| 26 | + ) |
| 27 | + ], |
| 28 | + round=[ |
| 29 | + dict( |
| 30 | + role="HUMAN", |
| 31 | + prompt_mm={ |
| 32 | + "text": {"type": "text", "text": "{question}"}, |
| 33 | + "image": {"type": "image_url", "image_url": {"url": "{image}"}}, |
| 34 | + }, |
| 35 | + ) |
| 36 | + ], |
| 37 | + ), |
| 38 | + ), |
| 39 | + retriever=dict(type=ZeroRetriever), |
| 40 | + inferencer=dict(type=GenInferencer), |
| 41 | +) |
| 42 | + |
| 43 | + |
| 44 | +# Judge model prompt template. Instructs the judge to extract answer and evaluate correctness - aligned with official HLE format |
| 45 | +JUDGE_PROMPT = """ |
| 46 | + Judge whether the following [response] to [question] is correct or not based on the precise and unambiguous [correct_answer] below. |
| 47 | +
|
| 48 | + [question]: {question} |
| 49 | +
|
| 50 | + [response]: {model_answer} |
| 51 | +
|
| 52 | + Your judgement must be in the format and criteria specified below: |
| 53 | +
|
| 54 | + extracted_final_answer: The final exact answer extracted from the [response]. Put the extracted answer as 'None' if there is no exact, final answer to extract from the response. |
| 55 | +
|
| 56 | + [correct_answer]: {answer} |
| 57 | +
|
| 58 | + reasoning: Explain why the extracted_final_answer is correct or incorrect based on [correct_answer], focusing only on if there are meaningful differences between [correct_answer] and the extracted_final_answer. Do not comment on any background to the problem, do not attempt to solve the problem, do not argue for any answer different than [correct_answer], focus only on whether the answers match. |
| 59 | +
|
| 60 | + correct: Answer 'yes' if extracted_final_answer matches the [correct_answer] given above, or is within a small margin of error for numerical problems. Answer 'no' otherwise, i.e. if there if there is any inconsistency, ambiguity, non-equivalency, or if the extracted answer is incorrect. |
| 61 | +
|
| 62 | + confidence: The extracted confidence score between 0|\%| and 100|\%| from [response]. Put 100 if there is no confidence score available. |
| 63 | +""".strip() |
| 64 | + |
| 65 | + |
| 66 | +# JSON schema for structured judge model output |
| 67 | +RESPONSE_FORMAT_SCHEMA = { |
| 68 | + "type": "json_schema", |
| 69 | + "json_schema": { |
| 70 | + "schema": { |
| 71 | + "properties": { |
| 72 | + "extracted_final_answer": { |
| 73 | + "title": "Extracted Final Answer", |
| 74 | + "type": "string", |
| 75 | + }, |
| 76 | + "reasoning": {"title": "Reasoning", "type": "string"}, |
| 77 | + "correct": { |
| 78 | + "title": "Correct", |
| 79 | + "enum": ["yes", "no"], |
| 80 | + "type": "string", |
| 81 | + }, |
| 82 | + "confidence": {"title": "Confidence", "type": "integer"}, |
| 83 | + "strict": {"const": True, "type": "boolean"}, |
| 84 | + }, |
| 85 | + "required": [ |
| 86 | + "extracted_final_answer", |
| 87 | + "reasoning", |
| 88 | + "correct", |
| 89 | + "confidence", |
| 90 | + "strict", |
| 91 | + ], |
| 92 | + "type": "object", |
| 93 | + "additionalProperties": False, |
| 94 | + }, |
| 95 | + "name": "ExtractedAnswer", |
| 96 | + "strict": True, |
| 97 | + }, |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | +hle_judge_infer_cfg = dict( |
| 102 | + judge_reader_cfg=dict( |
| 103 | + input_columns=["question", "answer", "model_answer"], |
| 104 | + output_column="model_pred_uuid", |
| 105 | + ), |
| 106 | + judge_model=dict( |
| 107 | + attr="service", |
| 108 | + type=VLLMCustomAPIChat, |
| 109 | + abbr="judge", |
| 110 | + path="", |
| 111 | + model="", |
| 112 | + stream=False, |
| 113 | + request_rate=0, |
| 114 | + use_timestamp=False, |
| 115 | + retry=2, |
| 116 | + api_key="", |
| 117 | + host_ip="localhost", |
| 118 | + host_port=8080, |
| 119 | + url="", |
| 120 | + max_out_len=8192, |
| 121 | + batch_size=100, |
| 122 | + trust_remote_code=False, |
| 123 | + generation_kwargs=dict( |
| 124 | + temperature=0.01, |
| 125 | + seed=0, |
| 126 | + response_format=RESPONSE_FORMAT_SCHEMA, |
| 127 | + chat_template_kwargs=dict( |
| 128 | + enable_thinking=False, |
| 129 | + ), |
| 130 | + ), |
| 131 | + ), |
| 132 | + judge_dataset_type=HLEJGDataset, |
| 133 | + prompt_template=dict( |
| 134 | + type=PromptTemplate, |
| 135 | + template=dict( |
| 136 | + round=[ |
| 137 | + dict(role="HUMAN", prompt=JUDGE_PROMPT), |
| 138 | + ], |
| 139 | + ), |
| 140 | + ), |
| 141 | + retriever=dict(type=ZeroRetriever), |
| 142 | + inferencer=dict(type=GenInferencer), |
| 143 | +) |
| 144 | + |
| 145 | + |
| 146 | +hle_eval_cfg = dict( |
| 147 | + evaluator=dict(type=HLEJudgeEvaluator), |
| 148 | +) |
| 149 | + |
| 150 | + |
| 151 | +hle_datasets = [ |
| 152 | + dict( |
| 153 | + abbr="hle", |
| 154 | + type=HLEDataset, |
| 155 | + path="ais_bench/datasets/hle/data/test-00000-of-00001.parquet", |
| 156 | + reader_cfg=hle_reader_cfg, |
| 157 | + infer_cfg=hle_infer_cfg, |
| 158 | + judge_infer_cfg=hle_judge_infer_cfg, |
| 159 | + eval_cfg=hle_eval_cfg, |
| 160 | + ) |
| 161 | +] |
0 commit comments