Datasets:
Upload benchmark/README.md
Browse files- benchmark/README.md +144 -0
benchmark/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# APM Benchmark Scripts
|
| 2 |
+
|
| 3 |
+
This folder documents the command-line scripts used to run the Assistive Prompt Mediation (APM) benchmark from the published prompt CSVs through metric aggregation.
|
| 4 |
+
|
| 5 |
+
The scripts live in `scripts/`:
|
| 6 |
+
|
| 7 |
+
- `prepare_inference_inputs.py` converts the dataset CSVs into deterministic JSONL examples.
|
| 8 |
+
- `evaluate_outputs.py` computes row-level protocol, script, and burden metrics from model outputs.
|
| 9 |
+
- `compile_results.py` merges those metrics with judge annotations.
|
| 10 |
+
- `analyze_results.py` writes benchmark summary CSVs and optional plots.
|
| 11 |
+
|
| 12 |
+
## Setup
|
| 13 |
+
|
| 14 |
+
```bash
|
| 15 |
+
python -m pip install -r requirements-benchmark.txt
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
The row-level metric and compilation scripts only use the Python standard library. `pandas` is needed for aggregate analysis; `matplotlib` is only needed when `--plots` is used.
|
| 19 |
+
|
| 20 |
+
## 1. Prepare Inference Inputs
|
| 21 |
+
|
| 22 |
+
Run from the dataset repository root:
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
python scripts/prepare_inference_inputs.py \
|
| 26 |
+
--dataset-dir . \
|
| 27 |
+
--output-dir benchmark_inputs \
|
| 28 |
+
--overwrite
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
This writes files such as `benchmark_inputs/N1/en.jsonl`. Each row has the following shape:
|
| 32 |
+
|
| 33 |
+
```json
|
| 34 |
+
{
|
| 35 |
+
"example_id": "stable_sha1_id",
|
| 36 |
+
"language": "en",
|
| 37 |
+
"noise": "N1",
|
| 38 |
+
"category": "Communication and Task delegation",
|
| 39 |
+
"alpha": 0.2,
|
| 40 |
+
"clean_text": "Write a short message asking my manager for one day of sick leave.",
|
| 41 |
+
"noisy_prompt": "Wriet a shrot emssage askign my managre fro noe dya of sikc elave.",
|
| 42 |
+
"instruction": "Rewrite the noisy user prompt into a clear prompt..."
|
| 43 |
+
}
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
The full CSV set expands to 40,928 inference examples across languages, noise types, and alpha severities.
|
| 47 |
+
|
| 48 |
+
Save model generations in this format before evaluation:
|
| 49 |
+
|
| 50 |
+
```json
|
| 51 |
+
{
|
| 52 |
+
"example_id": "stable_sha1_id",
|
| 53 |
+
"language": "en",
|
| 54 |
+
"noise": "N1",
|
| 55 |
+
"alpha": 0.2,
|
| 56 |
+
"noisy_prompt": "Wriet a shrot emssage askign my managre fro noe dya of sikc elave.",
|
| 57 |
+
"model_response": "Write a short message asking my manager for one day of sick leave."
|
| 58 |
+
}
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
The evaluator also accepts common response field names such as `response`, `assistant_response`, `assist_prompt`, `assisted_prompt`, `mediated_prompt`, or `output`.
|
| 62 |
+
|
| 63 |
+
## 2. Evaluate Model Outputs
|
| 64 |
+
|
| 65 |
+
Expected layout:
|
| 66 |
+
|
| 67 |
+
```text
|
| 68 |
+
outputs/
|
| 69 |
+
model-name/
|
| 70 |
+
N1/
|
| 71 |
+
results.jsonl
|
| 72 |
+
N2/
|
| 73 |
+
results.jsonl
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Run:
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
python scripts/evaluate_outputs.py \
|
| 80 |
+
--input-root outputs \
|
| 81 |
+
--output-root metrics
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
This writes `metrics/<model>/<noise>/metrics.json`.
|
| 85 |
+
|
| 86 |
+
Each metric row includes:
|
| 87 |
+
|
| 88 |
+
- `asked_question`, `added_explanation`, `protocol_compliant`
|
| 89 |
+
- `script_match`, `script_ratio` for Chinese-script diagnostics
|
| 90 |
+
- `B_raw`, `B_assist`, and `BRS = B_raw - B_assist`
|
| 91 |
+
|
| 92 |
+
## 3. Compile With Judge Annotations
|
| 93 |
+
|
| 94 |
+
If judge annotations are stored as `outputs_judged/<model>/<noise>/results.jsonl`, run:
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
python scripts/compile_results.py \
|
| 98 |
+
--metrics-root metrics \
|
| 99 |
+
--judged-root outputs_judged \
|
| 100 |
+
--output-root compiled
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Judge annotations may be nested under a `judge` key:
|
| 104 |
+
|
| 105 |
+
```json
|
| 106 |
+
{
|
| 107 |
+
"example_id": "stable_sha1_id",
|
| 108 |
+
"judge": {
|
| 109 |
+
"intent_preservation": 5,
|
| 110 |
+
"hallucinated_additions": false,
|
| 111 |
+
"hallucination_severity": 0,
|
| 112 |
+
"asked_for_clarification": false,
|
| 113 |
+
"added_extra_text": false,
|
| 114 |
+
"language_match": true,
|
| 115 |
+
"overall_verdict": "pass",
|
| 116 |
+
"comment": "Intent is preserved."
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
The compiler prefixes nested judge fields with `judge_` and writes `compiled/<model>/<noise>/compiled.json`.
|
| 122 |
+
|
| 123 |
+
## 4. Aggregate Benchmark Results
|
| 124 |
+
|
| 125 |
+
```bash
|
| 126 |
+
python scripts/analyze_results.py \
|
| 127 |
+
--compiled-root compiled \
|
| 128 |
+
--output-dir benchmark_summaries
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Add `--plots` to also write PNG visualizations when matplotlib is available in your environment.
|
| 132 |
+
|
| 133 |
+
Summary outputs include:
|
| 134 |
+
|
| 135 |
+
- `apm_sensitivity_curves.csv`
|
| 136 |
+
- `core_metrics.csv`
|
| 137 |
+
- `hallucination_metrics.csv`
|
| 138 |
+
- `intent_burden_tradeoff.csv`
|
| 139 |
+
- `false_robustness_summary.csv`
|
| 140 |
+
- `language_noise_disparities.csv`
|
| 141 |
+
- `table_language_avg.csv`
|
| 142 |
+
- `table_model_avg.csv`
|
| 143 |
+
|
| 144 |
+
Use `--write-combined` if you also want a flattened `compiled_results.csv`.
|