File size: 5,719 Bytes
90d6c2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# ChartBench-E (Rebuilt, Insight-Oriented)

This implementation rebuilds ChartBench-E and extends it into a more diagnostic benchmark for VLM chart reading.

## What it provides

- 20 data patterns grouped into 6 behavior families.
- Multiple chart morphologies: `line`, `bar_v`, `bar_h`, `stacked`.
- Annotation modes: `labeled`, `partial`, `unlabeled`.
- Multi-factor difficulty beyond point count:
  - visual perturbations (noise, blur, JPEG artifacts, partial occlusion)
  - semantic traps (truncated axis, log-scale reading, legend confusion)
  - event-level stressors (outlier spikes, near-tie values, regime shifts)
- Diagnostic metadata tags for capability slicing:
  - `event_tags`
  - `perceptual_tags`
  - `semantic_risk_tags`
- Reproducible generation with random seed.
- Evaluation metrics:
  - SPR (Success Parsing Rate)
  - OA (Overall Accuracy)
  - NRA (Numerical Reading Accuracy)
  - ARE (Average Relative Error)

## Install

```bash
cd chartbench_e
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

## Build benchmark-focused dataset

```bash
PYTHONPATH=. python scripts/build_chartbench_e.py \
  --out output/chartbench_e_benchmark_plus \
  --total-samples 20000 \
  --seed 42 \
  --task-mode benchmark \
  --challenge-level standard
```

Challenge levels:

- `standard`: light perturbation, mostly clean charts.
- `advanced`: balanced stress setting.
- `extreme`: heavy perturbation and denser hard cases.

## Make fixed evaluation subset

```bash
PYTHONPATH=. python scripts/make_eval_subset.py \
  --index output/chartbench_e_benchmark_plus/metadata/index.jsonl \
  --out output/chartbench_e_benchmark_plus/metadata/eval_subset.jsonl \
  --per-task 400
```

Risk-focused subset example:

```bash
PYTHONPATH=. python scripts/make_eval_subset.py \
  --index output/chartbench_e_benchmark_plus/metadata/index.jsonl \
  --out output/chartbench_e_benchmark_plus/metadata/eval_compositional.jsonl \
  --per-task 200 \
  --require-risk-tag compositional_reasoning
```

## Evaluate predictions

Prediction format (`jsonl`):

```json
{"sample_id": "cb_0000001", "values": [[...], [...]]}
```

Run:

```bash
PYTHONPATH=. python scripts/evaluate_predictions.py \
  --truth output/chartbench_e_benchmark_plus/metadata/eval_subset.jsonl \
  --pred your_predictions.jsonl \
  --out output/report.json \
  --tolerance 0.05
```

## Multi-model benchmark (new)

### Supported model registry

See `scripts/model_registry.json`.

Default enabled models:
- `gpt-5.2`
- `gpt-5.2-high`
- `gpt-5`
- `gpt-5-mini-high`
- `qwen3-vl-30b-a3b-thinking`
- `qwen2.5-vl-72b`
- `glm-4.6v`

Explicitly excluded in this round:
- `deepseek-vl2`
- `paddleocr-vl-1.5`

### Required env vars

OpenAI provider:
- `OPENAI_API_KEY`
- `OPENAI_BASE_URL` (optional)

SiliconFlow provider:
- `SILICONFLOW_API_KEY`
- `SILICONFLOW_BASE_URL` (optional, default `https://api.siliconflow.cn/v1`)

Fallback rule for SiliconFlow models:
- if `SILICONFLOW_*` is missing, script falls back to `OPENAI_*`

### Prompt behavior

- The benchmark runner defaults to `--prompt-mode type_specific`.
- In `type_specific` mode, prompts are loaded from `prompts/chart_types/<chart_type>.txt`.
- Each prompt instantiation now includes a shape-aware JSON example through `{json_example}`, in addition to the strict JSON output contract.
- `prompts/chart_reading_prompt.txt` remains available for `--prompt-mode unified`.

### Run benchmark

Single model + 3 repeats + evaluation:

```bash
PYTHONPATH=. python scripts/run_vlm_benchmark.py \
  --truth-index output/chartbench_e_benchmark_plus/metadata/eval_subset.jsonl \
  --dataset-root output/chartbench_e_benchmark_plus \
  --models gpt-5.2 \
  --repeats 3 \
  --max-workers 2 \
  --max-retries 2 \
  --timeout-seconds 120 \
  --run-eval \
  --tolerance 0.05
```

All enabled models:

```bash
PYTHONPATH=. python scripts/run_vlm_benchmark.py \
  --truth-index output/chartbench_e_benchmark_plus/metadata/eval_subset.jsonl \
  --dataset-root output/chartbench_e_benchmark_plus \
  --models all \
  --repeats 3 \
  --max-workers 4 \
  --max-retries 2 \
  --timeout-seconds 120 \
  --run-eval
```

Offline smoke test (no API call, sanity-only):

```bash
PYTHONPATH=. python scripts/run_vlm_benchmark.py \
  --truth-index output/chartbench_e_benchmark_plus/metadata/eval_subset.jsonl \
  --dataset-root output/chartbench_e_benchmark_plus \
  --models gpt-5.2 \
  --repeats 3 \
  --max-samples 20 \
  --run-eval \
  --mock-from-truth
```

### Prompt A/B pilot

This pilot samples a 54-chart subset (18 chart types x 3 difficulty tiers x 1 sample), runs baseline vs. updated chart-type prompts, and writes a comparison report:

```bash
PYTHONPATH=. python scripts/run_prompt_ab_pilot.py \
  --mock-from-truth
```

For real model runs, set provider credentials first and rerun without `--mock-from-truth`.

### Output structure

`output/bench_runs/{run_id}/`
- `run_config.json`
- `truth_subset.jsonl`
- `run_summary.json`
- `leaderboard.csv`
- `models/{model_key}/repeat_0x/pred.jsonl`
- `models/{model_key}/repeat_0x/report.json`
- `models/{model_key}/repeat_0x/failures.jsonl`
- `models/{model_key}/repeat_0x/raw_responses.jsonl`
- `models/{model_key}/repeat_0x/slice_report.json`
- `models/{model_key}/model_stability.json`
- `models/{model_key}/sample_stability.jsonl`
- `models/{model_key}/slice_summary.json`

Slicing coverage:
- `difficulty_tier` (L1-L4)
- `theme_domain`
- `axis_scale`
- `y_axis_truncated`

## Output structure (dataset)

- `images/*.png`: generated chart images.
- `metadata/index.jsonl`: full metadata with ground truth and challenge tags.
- `metadata/summary.json`: split and distribution summary.
- `metadata/eval_subset.jsonl`: fixed benchmark subset.