Ishan3141's picture
Upload benchmark/README.md
5bc019a verified
|
Raw
History Blame Contribute Delete
3.96 kB
# APM Benchmark Scripts
This folder documents the command-line scripts used to run the Assistive Prompt Mediation (APM) benchmark from the published prompt CSVs through metric aggregation.
The scripts live in `scripts/`:
- `prepare_inference_inputs.py` converts the dataset CSVs into deterministic JSONL examples.
- `evaluate_outputs.py` computes row-level protocol, script, and burden metrics from model outputs.
- `compile_results.py` merges those metrics with judge annotations.
- `analyze_results.py` writes benchmark summary CSVs and optional plots.
## Setup
```bash
python -m pip install -r requirements-benchmark.txt
```
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.
## 1. Prepare Inference Inputs
Run from the dataset repository root:
```bash
python scripts/prepare_inference_inputs.py \
--dataset-dir . \
--output-dir benchmark_inputs \
--overwrite
```
This writes files such as `benchmark_inputs/N1/en.jsonl`. Each row has the following shape:
```json
{
"example_id": "stable_sha1_id",
"language": "en",
"noise": "N1",
"category": "Communication and Task delegation",
"alpha": 0.2,
"clean_text": "Write a short message asking my manager for one day of sick leave.",
"noisy_prompt": "Wriet a shrot emssage askign my managre fro noe dya of sikc elave.",
"instruction": "Rewrite the noisy user prompt into a clear prompt..."
}
```
The full CSV set expands to 40,928 inference examples across languages, noise types, and alpha severities.
Save model generations in this format before evaluation:
```json
{
"example_id": "stable_sha1_id",
"language": "en",
"noise": "N1",
"alpha": 0.2,
"noisy_prompt": "Wriet a shrot emssage askign my managre fro noe dya of sikc elave.",
"model_response": "Write a short message asking my manager for one day of sick leave."
}
```
The evaluator also accepts common response field names such as `response`, `assistant_response`, `assist_prompt`, `assisted_prompt`, `mediated_prompt`, or `output`.
## 2. Evaluate Model Outputs
Expected layout:
```text
outputs/
model-name/
N1/
results.jsonl
N2/
results.jsonl
```
Run:
```bash
python scripts/evaluate_outputs.py \
--input-root outputs \
--output-root metrics
```
This writes `metrics/<model>/<noise>/metrics.json`.
Each metric row includes:
- `asked_question`, `added_explanation`, `protocol_compliant`
- `script_match`, `script_ratio` for Chinese-script diagnostics
- `B_raw`, `B_assist`, and `BRS = B_raw - B_assist`
## 3. Compile With Judge Annotations
If judge annotations are stored as `outputs_judged/<model>/<noise>/results.jsonl`, run:
```bash
python scripts/compile_results.py \
--metrics-root metrics \
--judged-root outputs_judged \
--output-root compiled
```
Judge annotations may be nested under a `judge` key:
```json
{
"example_id": "stable_sha1_id",
"judge": {
"intent_preservation": 5,
"hallucinated_additions": false,
"hallucination_severity": 0,
"asked_for_clarification": false,
"added_extra_text": false,
"language_match": true,
"overall_verdict": "pass",
"comment": "Intent is preserved."
}
}
```
The compiler prefixes nested judge fields with `judge_` and writes `compiled/<model>/<noise>/compiled.json`.
## 4. Aggregate Benchmark Results
```bash
python scripts/analyze_results.py \
--compiled-root compiled \
--output-dir benchmark_summaries
```
Add `--plots` to also write PNG visualizations when matplotlib is available in your environment.
Summary outputs include:
- `apm_sensitivity_curves.csv`
- `core_metrics.csv`
- `hallucination_metrics.csv`
- `intent_burden_tradeoff.csv`
- `false_robustness_summary.csv`
- `language_noise_disparities.csv`
- `table_language_avg.csv`
- `table_model_avg.csv`
Use `--write-combined` if you also want a flattened `compiled_results.csv`.